Params
Numeric zs(30); //跟踪止损点数
Vars
Numeric rand; //随机数
Numeric zg(0); //最高价
Numeric zd(9999999); //最低价
Defs
Events
OnInit(){
}
OnBar(ArrayRef<Integer> indexs){
If(O>zg){ //在控制台每次都输出两个一样的价格,好像这个判断总是成立的
zg = O;
Print(Text(zg));
}
If(O<zd){
zd = O;
Print(Text(zd));
}
If(MarketPosition == 0){
Print("持仓=0");
rand = IntPart(Rand(1,3));//随机数1或2
If(rand == 1){
Buy(1,0);
Print("多开");
}
If(rand == 2){
SellShort(1,0);
Print("空开");
}
}Else{
Print("持仓不为0");
If(MarketPosition == 1 And zg - O > zs){
Sell(1,0);
SellShort(1,0);
Print("多反");
}
If(MarketPosition == -1 And O - zd > zs){
BuyToCover(1,0);
Buy(1,0);
Print("空反");
}
}
}
跟踪止损在开发手册里是有专门案例的 仔细学习一下
zg zd定义成序列变量