可能是close的问题,实盘信号时有闪烁,平时还好,特别是在使用监控器自动同步时经常反复发指令成交。策略是过均线后的下一根K线开平仓,或者当根过均线超过1.5倍的ATR值时开平仓。如何修改代码稳定信号,感谢感谢!
Params Numeric lots(0);
Numeric Length1(60); //均线默认60
Numeric Length2(26);//ATR值默认26
Numeric NumATRs(1.5);//ATR倍数默认1.5倍
Vars
Numeric MA1;
Numeric ATRValue;//ATR值
Numericseries Upbar; Numericseries Downbar;
Begin
MA1 = Average(Close,Length1);
ATRValue = NumATRs*AvgTrueRange(Length2);//
If ( CrossOver ( Close,MA1))
Upbar = CurrentBar;
If ( CrossUnder( Close,MA1))
Downbar = CurrentBar;
If( Close > MA1 && ( CurrentBar - Upbar ) >= 1 ) Buy(lots,Close);
if(Close > MA1+ATRValue && (CurrentBar - Upbar) == 0) Buy(lots,Close);
If( Close < MA1 && ( CurrentBar - Downbar ) >= 1 ) SellShort(lots, Close);
if(Close < MA1-ATRValue && ( CurrentBar - Upbar ) == 0) SellShort(lots, Close);
End
用close判断交叉肯定会闪烁
一般是close[1] 和ma[1],表示上一个周期走完的情况
我把close和ma改为close[1]和ma[1],提示错误描述是“只有序列变量和参数或数组才能使用回溯值”,麻烦帮忙改写一下上面的语句,感谢感谢!
Numeric MA1;
改成
numericseries ma1;
旗舰版现在应该都是老用户在用的,老用户连这个修改都不会?
研究的不深不透😂,感谢感谢!