Pinescript 多策略.exit 为一入口

发布于 2025-01-16 07:54:23 字数 381 浏览 3 评论 0原文

我尝试为一个条目创建两个不同的strategy.exit函数(其中一个用于限制,另一个用于停止)。因为我想从这两个退出函数中获取不同的注释。

相关代码片段:

strategy.entry("Longi" , direction = strategy.long, limit = close + 5)
strategy.exit("LongKapa" , from_entry = "Longi" , limit = xxx)
strategy.exit("LongKapa" , from_entry = "Longi" , stop = xxx)

但是策略测试人员忽略了第二个。那么,在 if 块中不使用strategy.order 的情况下如何获得两个不同的注释呢?

I try to create two different strategy.exit function for one entry(one of them is for limit, other one is for stop). Because I want to take different comments from these two exit function.

Related code snippet:

strategy.entry("Longi" , direction = strategy.long, limit = close + 5)
strategy.exit("LongKapa" , from_entry = "Longi" , limit = xxx)
strategy.exit("LongKapa" , from_entry = "Longi" , stop = xxx)

But strategy tester neglect second one. So how can I get two different comments without using strategy.order in if block ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤云独去闲 2025-01-23 07:54:23

您应该为其提供唯一的 ID,否则您将修改而不是创建新的。

strategy.entry("Longi" , direction = strategy.long, limit = close + 5, qty=2)
strategy.exit("LongKapa-1" , from_entry = "Longi" , limit = xxx, qty=1)
strategy.exit("LongKapa-2" , from_entry = "Longi" , stop = xxx, qty=1)

https://www.tradingview.com/pine-script -reference/v5/#fun_strategy{dot}退出

You should give it unique id's otherwise you will modify and not create a new one.

strategy.entry("Longi" , direction = strategy.long, limit = close + 5, qty=2)
strategy.exit("LongKapa-1" , from_entry = "Longi" , limit = xxx, qty=1)
strategy.exit("LongKapa-2" , from_entry = "Longi" , stop = xxx, qty=1)

https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}exit

醉城メ夜风 2025-01-23 07:54:23

使用逻辑。适用于布尔表达式。

longCondition = ta.crossunder(ta.sma(close, 20), ta.sma(close, 50))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)


exitCondition = ta.crossunder(ta.sma(close, 10), ta.sma(close, 20)) or ta.crossunder(ta.sma(close, 10), ta.sma(close, 50))
if (exitCondition)
    strategy.exit("exit", "My Long Entry Id", profit = 10, loss = 5)

Use logical or. Applicable to boolean expressions.

longCondition = ta.crossunder(ta.sma(close, 20), ta.sma(close, 50))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)


exitCondition = ta.crossunder(ta.sma(close, 10), ta.sma(close, 20)) or ta.crossunder(ta.sma(close, 10), ta.sma(close, 50))
if (exitCondition)
    strategy.exit("exit", "My Long Entry Id", profit = 10, loss = 5)
寄意 2025-01-23 07:54:23

strategy.exit 为此目的提供了专用的注释参数:comment、comment_profit、comment_loss、comment_trailing,这些参数根据触发退出的条件使用。检查帮助以获取详细信息,但在您的示例中您将使用:

strategy.exit("LongKapa" , from_entry = "Longi" ,
  limit = xxx, stop = xxx,
  comment_profit = 'Limit triggered',
  comment_loss = 'Stop triggered'
  )

strategy.exit has dedicated comment arguments for that purpose: comment, comment_profit, comment_loss, comment_trailing, which are used based on the condition, which triggered the exit. Check help for details, but in your example you'd use:

strategy.exit("LongKapa" , from_entry = "Longi" ,
  limit = xxx, stop = xxx,
  comment_profit = 'Limit triggered',
  comment_loss = 'Stop triggered'
  )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文