Tolong beri arahan kepada saya, apabila nilai stop loss pada garis reka bentuk lebih besar daripada nilai penyimpangan, garis pengiraan trian yang sepatutnya diubah tidak berlaku, tidak tahu di mana masalah itu timbul?

Penulis:harapan, Dicipta: 2022-10-29 13:54:10, Dikemas kini: 2022-11-03 18:18:07

Tolong beri arahan kepada saya, apabila nilai stop loss pada garis reka bentuk lebih besar daripada nilai penyimpangan, garis pengiraan trian yang sepatutnya diubah tidak berlaku, tidak tahu di mana masalah itu timbul?

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)                                

Lebih lanjut

harapanBaiklah, terima kasih banyak.

Mimpi kecilStopLossShort := math.round ((((highest - open) / open) <= StopLossOffset? (1 + StopLossOffset) * highest : highest, precision = 6) // Hentikan kerugian kosong, peruntukan semula, mengira harga hentian kerugian; Algorithm buat kosong dan buat banyak, anda perlu berhati-hati!