微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

下图中所指的那些绿线和红线实际上是我的算法之前给我的一个信号的止损和获利。我实际上希望这条线在我的 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,linewidth = 2)
plot(Sell ? na : short_stop_level,linewidth = 2) 
plot(Sell ? na : take_profit_short,linewidth = 2)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。