Pinescript:当我的止盈或止损被触及时,我如何使止盈和止损线突破并消失?

时间:2021-03-11 05:28:25

标签: pine-script indicator

下图中所指的那些绿线和红线实际上是我的算法之前给我的一个信号的止损和获利。我实际上希望这条线在我的 tp 或止损被触及或价格越过我的基线反向时不再显示。

这是我使用的代码:

use_tp = input(false, title = "Use Take Profit ?", type=input.bool)

// Store values

entry_atr = float(0.0) //set float
entry_price = float(0.0) //set float
entry_atr := Buy or Sell ? atr : entry_atr[1]
entry_price := Buy or Sell ? close : entry_price[1]

//Calculate the stop loss and take profit distance in price
xLoss = entry_atr * atrMulti_Loss 
xProfit = entry_atr*atrMulti_Profit

//find long entry stop loss and take profit
long_stop_level = float(0.0) //set float
long_profit_level = float(0.0) //set float long_stop_level := entry_price - xLoss long_profit_level := entry_price + xProfit

//find short entry stop loss and take profit
short_stop_level = float(0.0) // set float
short_profit_level = float(0.0) // set float
short_stop_level := entry_price + xLoss short_profit_level := entry_price - xProfit

take_profit_long = use_tp ? long_profit_level : na
take_profit_short = use_tp ? short_profit_level : na

//Plot stop loss and profit level on chart, hide levels when no trade
plot(Buy ? na : long_stop_level, color=color.red, style=plot.style_linebr, linewidth = 2) 
plot(Buy ? na : take_profit_long, color=color.lime, style=plot.style_linebr, linewidth = 2)
plot(Sell ? na : short_stop_level, color=color.red, style=plot.style_linebr, linewidth = 2) 
plot(Sell ? na : take_profit_short, color=color.lime, style=plot.style_linebr, linewidth = 2)

0 个答案:

没有答案