 
等级: 超级版主
- 注册:
- 2021-5-24
- 曾用名:
|
本帖最后由 资深技术05 于 2025-10-10 13:38 编辑
TA0001 是我本地的套利合约。你要确定你本地自建套利合约 是否是这个名称。
其次这种写法是不支持回测的。 因为回测中对套利合约下单,回测系统是将它拟作一个单一的品种的,此时通过tbuyholdingex 函数无法读取单腿的持仓的。直接回测只会有开仓,没有平仓。
需要回测你使用下面的代码 然后后台预警中直接设置监控套利合约。
回测版本,回测前务必刷新套利合约的数据:
[PEL] 复制代码 input:m(3,0.1,100,1),k(1,0.1,10,1),max_hd(1,1,10000,1);
mid: ma(close,m);//布林中轨
upper:= mid + k*std(close,m);//布林上轨
lower:= mid - k*std(close,m);//布林下轨
if tbuyholdingex('','',1)=0 and (c<mid)and( tisremainex(0,'','')=0) then
begin
tbuy(1,1,lmt,close-1);
end
if tbuyholdingex('','',1)>0 and (mid<c)then tsell(1,0,lmt,close+1);
实际运行则单独使用下面的代码版本:
[PEL] 复制代码 input:m(3,0.1,100,1),k(1,0.1,10,1),max_hd(1,1,10000,1);
mid: ma(close,m);//布林中轨
upper:= mid + k*std(close,m);//布林上轨
lower:= mid - k*std(close,m);//布林下轨
code1:=arbitragecode('ta0001',1);
code2:=arbitragecode('ta0001',2);
//第一腿的多空持仓
d1_d:tbuyholdingex('',code1,1);
d1_k:tsellholdingex('',code1,1);
//第二腿的多空持仓
d2_d:tbuyholdingex('',code2,1);
d2_k:tsellholdingex('',code2,1);
tao_d:d1_d>0 and d2_k>0;//判断是否套利多
tao_k:d1_k>0 and d2_d>0;
if tao_d=0 and (c<mid)and( tisremainex(0,'','')=0) then
begin
tbuy(1,1,lmt,close-1);
end
if tao_d>0 and (mid<c)then tsell(1,0,lmt,close+1);
|
|