请老师帮忙看下,代码问题出在哪里哦

老师好 一个早盘突破系统,我的想法是高低线生成后,满足代码的突破条件后,第一时间给到信号,每天交易一次哈。但目前有2个小问题。 第1个,应该有开仓信号的地方,却没有开仓信号,如下图: 第2个,没能第一时间给出开仓信号。 代码如下,请帮忙修改一下,谢谢 Params Numeric t1(30);// 突破区间时间设置 Numeric offset(3);// 偏移参数 Numeric t2(1455); //离场时间 Vars Series<Numeric>tem_h; Series<Numeric>tem_l; Series<Numeric>my_h; Series<Numeric>my_l; Series<Numeric>bprice; Series<Numeric>sprice; Global Numeric s1(0); Events OnBar(ArrayRef<Integer> indexs) { tem_h = Highest(h[1],t1); tem_l = Lowest(l[1],t1); Commentary("BarsSinceToday=" + Text(BarsSinceToday)); If(BarsSinceToday == t1) { my_h=tem_h; my_l=tem_l; s1=1; bprice=my_h+offset*minmove; sprice=my_l-offset*minmove; } //突破入场 If(BarsSinceToday>t1) { If(High >= bprice And MarketPosition <=0 And s1>0) { Buy(1,Max(O,bprice));//开盘价和突破价的最大值 s1=0; } If(Low <= sprice And MarketPosition >=0 and s1>1) { SellShort(1,Min(O,sprice));//开盘价和突破价的最小值 s1=0; } } //止损离场或定时离场 if(MarketPosition>0) { if(L<my_l And BarsSinceEntry>0) { Sell(0,Min(O,my_l)); s1=0; } else If(Time==t2/10000) { Sell(0,Open); s1=0; } } Else If(MarketPosition<0) { if(H>my_h And BarsSinceEntry>0) { BuyToCover(0,Max(O,my_h)); s1=0; } else If(Time==t2/10000) { BuyToCover(0,Open); s1=0; } } PlotNumeric("my_h",my_h); PlotNumeric("my_l",my_l); }

请问s1(0,2)代表什么意思?

回复:

其他问题,没细看,大致修改后代码如下。 Params Numeric t1(30); // 突破区间时间设置 Numeric offset(3); // 偏移参数 Numeric t2(1455); //离场时间 Vars Series<Numeric> tem_h; Series<Numeric> tem_l; Series<Numeric> my_h; Series<Numeric> my_l; Series<Numeric> bprice; Series<Numeric> sprice; //Global Numeric s1(0); Series<Numeric> s1(0,2); Events OnBar(ArrayRef<Integer> indexs) { tem_h = Highest(h[1],t1); tem_l = Lowest(l[1],t1); Commentary("BarsSinceToday=" + Text(BarsSinceToday)); If(BarsSinceToday == t1) { my_h=tem_h; my_l=tem_l; s1=1; bprice=my_h+offset*minmove; sprice=my_l-offset*minmove; } //突破入场 If(BarsSinceToday>t1) { If(High >= bprice And MarketPosition <=0 And s1>0) { Buy(1,Max(O,bprice));//开盘价和突破价的最大值 //s1=0; } //If(Low <= sprice And MarketPosition >=0 and s1>1) If(Low <= sprice And MarketPosition >=0 and s1>0) { SellShort(1,Min(O,sprice));//开盘价和突破价的最小值 //s1=0; } } //止损离场或定时离场 if(MarketPosition>0) { if(L<my_l And BarsSinceEntry>0) { Sell(0,Min(O,my_l)); s1=0; } else If(Time==t2/10000) { Sell(0,Open); s1=0; } } Else If(MarketPosition<0) { if(H>my_h And BarsSinceEntry>0) { BuyToCover(0,Max(O,my_h)); s1=0; } else If(Time==t2/10000) { BuyToCover(0,Open); s1=0; } } PlotNumeric("my_h",my_h); PlotNumeric("my_l",my_l); }

1、s1不要定义为全局变量,定义为序列变量即可; 2、开仓后,不需要将s1赋值为0,平仓时赋值即可; 3、空头不开仓,可能是因为这写错了