Please instruct me, when the stop loss value of the design draw line is greater than the deviation value, the three yuan calculation draw line should be changed but it does not work, I don't know where the problem comes from?

Author: hope, Created: 2022-10-29 13:54:10, Updated: 2022-11-03 18:18:07

Please instruct me, when the stop loss value of the design draw line is greater than the deviation value, the three yuan calculation draw line should be changed but it does not work, I don't know where the problem comes from?

indicator("根据历史区间最高价、最低价、+偏移率,计算止损价、止盈价", overlay=true)

var IshistoryLength = input.int(15, title = "Ishistory Length", minval=1, maxval=100, step=1)    
var StopLossOffset = input.float(0.005, title = "Stop Loss Offset", minval=0.001, step=0.001)    
var ProfitLossRatio = input.float(2, title = "Profit Loss Ratio", minval=0.1, step=0.1)          
var float highest = na                                                                           
var float lowest = na                                                                            
var float StopLossLong = na                                                                      
var float StopLossShort = na                                                                     
var float StopProfitLong = na                                                                    
var float StopProfitShort = na                                                                   

highest := ta.highest(high[1], IshistoryLength)                                                  

lowest  := ta.lowest(low[1], IshistoryLength)                                                    

//存在问题:波动越小时,止损值越小;波动越大时,止损值越大;
//优化方案:计算一下止损比例,如果止损小于0.5%,就把止损偏移量加进去;如果止损大于0.5%,则不加偏移量;控制总体止损值不大于1%;
StopLossLong := math.round(((open - lowest) / open) <= StopLossOffset ? (1 - StopLossOffset) * lowest : lowest, precision = 6)        
plot(StopLossLong, title = "开多止损价:", color = color.purple)                               

StopProfitLong := math.round((1 + (StopLossOffset * ProfitLossRatio)) * highest, precision = 6)  
plot(StopProfitLong, title = "开多止盈价:", color = color.orange)                              

StopLossShort := math.round(((open - highest) / open) <= StopLossOffset ? (1 + StopLossOffset) * highest : highest, precision = 6)    
plot(StopLossShort, title = "开空止损价:", color = color.red)                                 

StopProfitShort := math.round((1 - (StopLossOffset * ProfitLossRatio)) * lowest, precision = 6)  
plot(StopProfitShort, title = "开空止盈价:", color = color.navy)                                

More

hopeGood, thank you very much.

The Little DreamStopLossShort := math.round ((((highest - open) / open) <= StopLossOffset? (1 + StopLossOffset) * highest : highest, precision = 6) // stop loss blank list, re-assign, calculate the stop loss price; The algorithms for doing nothing and doing more, be careful! are different.