信号闪烁

Global Numeric high_profit(1800); Global Numeric close_position(0); Global Numeric short_build(0); Global Numeric long_build(0);If(MarketPosition == -1 && (short_build - Close[1])*lots >= high_profit) { high_profit = (short_build - Close[1])*lots; close_position = high_profit * 0.5; } Else If(MarketPosition == 1 && (Close[1] - long_build)*lots >= high_profit) { high_profit = (Close[1] - long_build)*lots; close_position = high_profit * 0.5; }If(MarketPosition == -1) { If((short_build - Close[1])*lots < close_position && close_position > 0 && (short_build - Close[1]) > 0 ) { If((short_build - Close[1])*lots <1800) { BuyToCover(shortposition , Close); shortposition = 0; close_position = 0; high_profit = profit; If(sign_ni == 1) { need_plus = 1; } Else If(Open_bar > 6000 && sign_ni == 0) { sign_ni = 1; } } Else If((short_build - Close[1])*lots >= 1800) { close_position = high_profit * 0.3; } } } Else If(MarketPosition == 1) { If((Close[1] - long_build)*lots < close_position && close_position > 0 && (Close[1] - long_build) > 0) { If((Close[1] - long_build)*lots < 1800) { Sell(longposition , Close); longposition = 0; close_position = 0; high_profit = profit; If(sign_ni == 1) { need_plus = 1; } } Else If((Close[1] - long_build)*lots >= 1800) { close_position = high_profit * 0.3; } } }请问该段代码为什么会出现信号闪烁,我看了避免信号闪烁的视频,把可能会出现信号闪烁的问题给规避掉了,但还是出现了信号闪烁的问题。

1.你这个代码不能直接运行2.像你里面long_build这些变量定义为global的原因是?3.要学会使用commentry ,print等输出调试

回复:这只是代码的一部分,long_build和short_build 分别是多单建仓价和空单建仓价,在建仓的时候将建仓价赋给这两个变量

回复:这个代码的问题就是达到止盈条件之后,会平仓,但是在图表上不会显示,如果重新打开图表,他又准确的显示了

回复:说明全局变量使用不当有全局的情况,条件一变,则下一个tick全局就不满足了常见情况

回复:全局变量是每个tick都会重置变量的值吗

回复:使用全局变量是因为多个函数用到了该变量

回复:通过print等输出方法调试也就是检查每次条件进入和出去后的值

回复:但是逻辑又是对的,这种是不是不能用图标信号来做,直接使用A函数?