我写的这个套利策略,其他地方都还好,就是这个减仓部分出了问题,百思不得其解,想向各位老师请教
Events
OnInit()
{
layers[0]=SubscribeBar(“pp888.DCE”, "30m", 20211101.0930);
layers[1]=SubscribeBar(“MA888.CZCE”, "30m", 20211101.0930);
}
OnBar(ArrayRef<Integer> indexs)
{
//买多部分
//开仓1
If(k1==0 and jiacha<bz-db1)
{data0.buy(lots1,data0.open);
data1.SellShort(lots1,data1.open);Commentary("开仓1");
lotsj=lots1;k1=1;Return;
}
//加仓2
If(k1==1 and jiacha<bz-2*db1)
{data0.buy(2*lots1,data0.open);
data1.SellShort(2*lots1,data1.open);Commentary("加仓2");
lotsj=lots1*2;k1=2;Return;
}
//加仓3
If(k1==2 and jiacha<bz-3*db1)
{data0.buy(3*lots1,data0.open);
data1.SellShort(3*lots1,data1.open);Commentary("加仓3");
lotsj=lots1*3;k1=3;Return;
}
//分批减仓
If(k1>0 and jiacha>lowestjc)
{
data0.Sell(lotsj,data0.open);
data1.BuyToCover(lotsj,data1.open);
Commentary(" 减仓");
k1=k1-1;lotsj=lotsj-1;Return;
}
}
问题如下图
把图放大
已经搞掂了,非常感谢两位老师,@kyover , @cai446449
那要怎么样对两个图层的变量分别进行定义和使用呢?
这个我知道啊,可是我增加了一个变量也不行啊,2个变量分别用在2个图层的开仓和平仓代码上,也没解决问题
增加多一个变量也不行哦,跪求各位老师帮忙
那我改如何处理呢?增加多一个变量?
可是为什么前面加仓的时候又能保持一致呢?