我想知道我的多头/空头止盈/止损/追踪逻辑是否合适,因为空头应该是相反的方式,我不太确定它是如何工作的。例如。我可以轻松地测试 TP/SL,使用 Shift + Click
(百分比测量值)TP/SL 是否正确,但尾随我不能。
i_trailingPricePercent = input(4, title = "Trailing Price", minval = 0.01, step = 0.5)
i_trailingOffsetPercent = input(2, title = "Trailing Offset", minval = 0.01, step = 0.5)
i_takeProfitPercent = input(45, title = "Take Profit", minval = 0.01, step = 0.5)
i_stopLossPercent = input(15, title = "Stop Loss", minval = 0.01, step = 0.5)
entryLong = strategy.position_size == 0 and close > ema
entryShort = strategy.position_size == 0 and close < ema
trailingPoints = (close * (i_trailingPricePercent / 100)) / syminfo.mintick
trailingOffset = (close * (i_trailingOffsetPercent / 100)) / syminfo.mintick
takeProfit = (close * (i_takeProfitPercent / 100)) / syminfo.mintick
stopLoss = (close * (i_stopLossPercent / 100)) / syminfo.mintick
strategy.entry("Long", strategy.long, when = entryLong)
strategy.entry("Short", strategy.short, when = entryShort)
strategy.exit("Long Trailing", "Long", trail_price = trailingPoints, trail_offset = trailingOffset)
strategy.exit("Short Trailing", "Short", trail_price = trailingPoints, trail_offset = trailingOffset)
strategy.exit("Long TP/SL", "Long", loss = stopLoss, profit = takeProfit)
strategy.exit("Short TP/SL", "Short", loss = stopLoss, profit = takeProfit)