资源加载中... loading...

请大佬指导一下,当设计画线的止损值大于偏离值时,三元计算画线应该改变却没有生效,不知问题出在哪里?

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

请大佬指导一下,当设计画线的止损值大于偏离值时,三元计算画线应该改变却没有生效,不知问题出在哪里?

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

hope 好的,谢谢大佬。

发明者量化-小小梦 StopLossShort := math.round(((highest - open) / open) <= StopLossOffset ? (1 + StopLossOffset) * highest : highest, precision = 6) //止损空单,重新赋值,计算止损价格; 做空和做多的算法,你要注意啊!是不一样的。