即使到达TP/SL

发布于 2025-02-13 02:00:26 字数 725 浏览 1 评论 0原文

我不明白为什么当我设置 sl/tp 时, pine脚本正在退出我在下一个bar上的位置。

这是我简单的示例代码:

if entryConditionsAreMet
    strategy.entry("short", strategy.short)

// let's assume 5% TP and 2% SL
takeProfitShort = strategy.position_avg_price * (1 - (5 / 100))
stopLossShort = strategy.position_avg_price * (1 + (2 / 100))

strategy.exit("exitShort", "short", limit=takeProfitShort, stop=stopLossShort)

它可以正确打开并关闭位置,但是TP/SL 总是出现在下一个bar 上。

查看下面了解的图片(绿线是TP,橙色是SL):

i 'd期望该位置关闭在同一栏上,而不是在下一个条上!

如您所见,该位置不是在达到TP时关闭的位置,而是在下一个开放栏上关闭。

为什么会发生这种情况?如何避免它?

I cannot understand why Pine Script is exiting my position on next bar when I set SL/TP.

This is my simple example code:

if entryConditionsAreMet
    strategy.entry("short", strategy.short)

// let's assume 5% TP and 2% SL
takeProfitShort = strategy.position_avg_price * (1 - (5 / 100))
stopLossShort = strategy.position_avg_price * (1 + (2 / 100))

strategy.exit("exitShort", "short", limit=takeProfitShort, stop=stopLossShort)

It opens and closes positions correctly, however the TP/SL always occur on the next bar.

Look at the picture below to understand (the green line is the TP and the orange one is the SL):

I'd expect the position closes on the same bar, not in the next one!

As you can see, the position closes not when the TP is reached but on the next opening bar.

Why does this happen? How to avoid it?

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

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

发布评论

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

评论(2

生活了然无味 2025-02-20 02:00:26

尝试以下操作:

if entryConditionsAreMet
    strategy.entry("short", strategy.short)

// let's assume 5% TP and 2% SL
takeProfitShort = strategy.position_avg_price * (1 - (5.0 / 100))
stopLossShort = strategy.position_avg_price * (1 + (2.0 / 100))

strategy.exit("exitShort", "short", limit=takeProfitShort, stop=stopLossShort)

Try this:

if entryConditionsAreMet
    strategy.entry("short", strategy.short)

// let's assume 5% TP and 2% SL
takeProfitShort = strategy.position_avg_price * (1 - (5.0 / 100))
stopLossShort = strategy.position_avg_price * (1 + (2.0 / 100))

strategy.exit("exitShort", "short", limit=takeProfitShort, stop=stopLossShort)
早茶月光 2025-02-20 02:00:26

这是当前在Pinescript中不可能的(据我所知

if exitConditionsAreMet
    strategy.close_all(comment, alert_message, immediately) //Set immediately to true

) strategy.close_all() 允许在同一栏上关闭条目,通过将立即设置为true来打开它们。

这两个strategy.exit()stragity.entry()将忽略限制(获利),并在入口栏上停止(Stoploss),并且将在以下条的开放式。

This is not currently possible in pinescript (as far as I am aware) but you can trigger an exit on the close of the entry bar:

if exitConditionsAreMet
    strategy.close_all(comment, alert_message, immediately) //Set immediately to true

Using strategy.close_all() allows for closing entries on the same bar they are opened by setting the immediately parameter to true.

Both strategy.exit() and strategy.entry() will ignore the limit (take profit) and stop (stoploss) on the entry bar, and will be active criteria on the open of the following bar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文