限制为 strategy.exit 的问题

Issue with limit of strategy.exit

限制和停止无法正常工作。知道为什么吗? 图片显示示例(蓝线是获利和止损) enter image description here 这是脚本:

tp = strategy.position_avg_price * (1.15)
sl = strategy.position_avg_price * (0.90)
plot(tp)
plot(strategy.position_avg_price)
plot(sl)

if (t <= -15)
    strategy.entry("My Long Entry Id", strategy.long, when = window())
    strategy.exit ("My Long Exit Id", limit = tp, stop = sl, when = window())

看来首先你需要在 strategy.entrystrategy.exit 中写入相同的 ID。

尝试将您的 tpsl 转换为价格变动的:

TPfixed = input.float(1, "Take profit", minval=0.1, maxval=100,step=0.1)
SLfixed = input.float(0.5, "Stop loss", minval=0.1, maxval=100, step=0.1)
tp = (strategy.position_avg_price*(TPfixed/100))/syminfo.mintick
sl = (strategy.position_avg_price * (SLfixed/100)/syminfo.mintick
strategy.exit("Close","Long", loss=sl, profit=tp, when=strategy.position_size>0)

注意函数中需要使用参数lossprofit