Pine script 在Tradingview研究中通过警报获取利润和止损

Pine script 在Tradingview研究中通过警报获取利润和止损,pine-script,algorithmic-trading,trading,Pine Script,Algorithmic Trading,Trading,因此,我试图将一项战略转变为一项研究,以创建警报。所以我想最好的办法是从简单的事情开始。下面,我试图编写一个脚本,当更快的ema越过较慢的ema时发出警报。我把这部分记下来了。我正在挣扎的是在退出警报期间。我知道我定义的获利回吐价格和止损价格都很好,因为当我画这两个价格时,我得到了我想要的线。所以我认为我的错误是当我定义buy_exit1和buy_exit2时。任何帮助都将不胜感激。谢谢 // This source code is subject to the terms of the Mo

因此,我试图将一项战略转变为一项研究,以创建警报。所以我想最好的办法是从简单的事情开始。下面,我试图编写一个脚本,当更快的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)
//此源代码受Mozilla公共许可证2.0的条款约束,位于https://mozilla.org/MPL/2.0/
//©manuchtrafaldor
//@版本=4
研究(“2 ema交叉”,叠加=真实)
买入=交叉(均线(收盘,9),均线(收盘,20))
卖出=交叉下跌(均线(收盘,9),均线(收盘,20))
tp=280
sl=200
购买价格=0.0
购买价格=0.0
购买价格:=购买?关闭+tp*syminfo.mintick:na
购买价格:=购买?关闭sl*syminfo.mintick:na
买入卖出1=高>买入价格
买入/卖出2=低