因此,我正在尝试将策略转变为创建警报的研究。所以我认为最好的方法是从简单的事情开始。下面我试图编写一个脚本,当较快的 ema 越过较慢的 ema 时发出警报。我把这部分记下来了。我正在挣扎的是在退出警报期间。我知道我定义的止盈价和止损价很好,因为当我绘制这两条线时,我得到了我想要的线。所以我认为我的错误是在定义buy_exit1 和buy_exit2 时。任何帮助,将不胜感激。谢谢!
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © manuchtrafaldor
//@version=4
study("2 ema crossover",overlay=true)
buy = crossover(ema(close,9),ema(close,20))
sell = crossunder(ema(close,9),ema(close,20))
tp = 280
sl = 200
buy_tp_price = 0.0
buy_sl_price = 0.0
buy_tp_price := buy? close+tp*syminfo.mintick : na
buy_sl_price := buy? close-sl*syminfo.mintick : na
buy_exit1 = high>buy_tp_price
buy_exit2 = low<buy_sl_price
alertcondition(buy,"Buy 101")
alertcondition(sell,"Sell 101")
plot(ema(close,9),color=color.green)
plot(ema(close,20),color=color.red)
plotshape(buy,style=shape.triangleup,location=location.belowbar,text='buy',color=color.blue)
plotshape(sell,style=shape.triangledown,location=location.abovebar,text='sell',color=color.red)
plot(buy_tp_price)
plot(buy_sl_price)
plotshape(buy_exit2,style=shape.triangledown,location=location.abovebar,text='exit loss',color=color.purple)
plotshape(buy_exit1,style=shape.triangledown,location=location.abovebar,text='exit profit',color=color.purple)