![](/img/trans.png)
[英]How to make buy signals dependent on TP / SL conditions? please help me
[英]How to make buy signals dependent on TP / SL conditions?
我对 Pine Script 还是很陌生,在这里非常感谢您的帮助。 下面是一个示例代码,它生成“买入”信号。 但是,我想让这些“买入”信号仅在满足“获利”或“止损”条件时才会发生。 任何想法?
//@version=5
indicator("My script", overlay=true)
EMA1 = ta.ema(close, 20)
EMA2 = ta.ema(close, 50)
Buy = ta.crossover(EMA1, EMA2)
TPline = ta.valuewhen(Buy, close * 1.05, 0)
SLline = ta.valuewhen(Buy, close * 0.95, 0)
TakeProfit = ta.crossover(high, TPline)
StopLoss = ta.crossunder(low, SLline)
plot(TPline, color=color.orange, linewidth=2)
plot(SLline, color=color.aqua, linewidth=2)
plotshape(Buy, title = "Buy", style=shape.labelup, color=color.olive, location = location.belowbar, text ="Buy", textcolor = color.white)
plotshape(TakeProfit, title = "TakeProfit", style=shape.labeldown, color=color.green, location = location.abovebar, text ="TP", textcolor = color.white)
plotshape(StopLoss, title = "StopLoss", style=shape.labelup, color=color.red, location = location.belowbar, text ="SL", textcolor = color.white)
这也是一个屏幕截图:屏幕截图,指向冗余买入信号的箭头
plotshape(TakeProfit or StopLoss ? Buy : na , title = "Buy", style=shape.labelup, color=color.olive, location = location.belowbar, text ="Buy", textcolor = color.white)
或者,与
// put the `Buy` variable after declaration of `TakeProfit` and `StopLoss` variables
Buy = ta.crossover(EMA1, EMA2) and TakeProfit and StopLoss
plotshape(Buy, title = "Buy", style=shape.labelup, color=color.olive, location = location.belowbar, text ="Buy", textcolor = color.white)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.