Pine 脚本:strategy.exit 错误,带有追踪止损和止损

问题描述 投票:0回答:1

我正在为 TradingView 开发 Pine 脚本策略,并且我的strategy.exit 函数遇到错误。错误信息是:

这是我的代码的相关部分:

// Execute trades based on the buy conditions for long and short positions
if startLongTrade
    strategy.entry("Buy Long", strategy.long)
    strategy.exit("Take Profit Long", from_entry="Buy Long", limit=strategy.position_avg_price * (1 + takeProfitPercent), stop=strategy.position_avg_price * (1 - stopLossPercent))
    strategy.exit("Trailing Stop Long", from_entry="Buy Long", trail_offset=strategy.position_avg_price * trailingStopPercent)

问题已上线

strategy.exit("Trailing Stop Long", from_entry="Buy Long", trail_offset=strategy.position_avg_price * trailingStopPercent)

我的目的是同时实施止盈和追踪止损。如何正确设置我的

strategy.exit
调用来解决此错误并实现所需的功能?

pine-script
1个回答
0
投票
  1. 请勿从一个入场点进行两次退出,如果您不打算部分平仓,则只有代码中第一个退出才有效,请将您的退出合并为一个。
  2. 如果您想在图表上箭头下的标题中看到不同的注释,因为不同的退出原因,请使用适当的 comment_* 参数,例如
    comment_trailing
    用于尾随退出的标题,或
    comment_loss
    用于标题基于止损的退出
  3. 在示例的最后一行中,您有一个不完整的函数调用;您需要定义至少一个
    loss
    profit
    limit
    stop
    或一对尾随。
    trail_offset
    设置追踪订单的退出水平,但要使其发挥作用,您需要通过
    trail_points
    trail_price
    参数
  4. 确定激活水平
© www.soinside.com 2019 - 2024. All rights reserved.