Tolong beri petunjuk, ketika nilai stop loss dari garis desain lebih besar dari nilai deviasi, garis perhitungan 3 yuan seharusnya berubah tetapi tidak berlaku, tidak tahu di mana masalahnya?
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)
harapanBagus, terima kasih banyak.
Penemu Kuantitas - Mimpi KecilStopLossShort := math.round ((((highest - open) / open) <= StopLossOffset? (1 + StopLossOffset) * highest : highest, precision = 6) // stop loss blank list, re-assign, calculate stop loss price; Algorithm yang dibuat untuk melakukan hal yang kosong dan yang dibuat untuk melakukan hal yang lebih banyak, Anda harus berhati-hati!