本文介绍了Tradingview Pine 脚本`strategy.exit` 和`strategy.close` 不尊重`from_entry` 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的策略中有几个不同的条目,我想为它们指定单独的止损:

I have several different entries in my strategy, and I want to assign separate stop losses to them:

// @version=4
strategy("Test strategy")
strategy.entry("E0", strategy.long, limit=10000, when=close[1] > 10000)
strategy.entry("E1", strategy.long, limit=10000, when=close[1] > 10000)
strategy.exit("SL-E0", "E0", stop=9000)
strategy.exit("SL-E1", "E1", stop=9500)

据我了解文档(https://www.tradingview.com/pine-script-reference/#fun_strategy{dot}exit) strategy.exit 的第二个参数应该导致退出仅适用于匹配的条目,但是查看交易列表(在 2 小时内应用于 BTCUSD 时 - 供参考)我看到:

As far as I understand the documentation (https://www.tradingview.com/pine-script-reference/#fun_strategy{dot}exit) the 2nd parameter of strategy.exit should cause the exit to apply only to the matching entry, however looking at the trade list (when applied to BTCUSD on a 2h timeframe - for reference) I see this:

1   Entry Long  E0      2019-07-02 14:00    10000.0 
    Exit Long   SL-E1   2019-07-17 02:00    9500.0
2   Entry Long  E1      2019-07-02 14:00    10000.0
    Exit Long   SL-E0   2019-09-25 04:00    9000.0

因此应用了错误的止损.这是一个错误吗?我尝试了许多不同的退出调用配置,包括 loss 而不是 stop,以及将条件拉到外部:

So the wrong stop loss is being applied. Is this a bug? I have tried numerous different configurations of the exit call, including loss instead of stop, as well as pulling the condition external:

if low < 9000
    strategy.exit("SL-E0", "E0")

SL-E1"具有相同的效果.导致E0"退出.

All have the same effect whereby "SL-E1" causes "E0" to exit.

推荐答案

试试这个:

// @version=4
strategy("Test strategy", close_entries_rule="ANY")
strategy.entry("E0", strategy.long, limit=10000, when=close[1] > 10000)
strategy.entry("E1", strategy.long, limit=10000, when=close[1] > 10000)
strategy.exit("SL-E0", "E0", stop=9000)
strategy.exit("SL-E1", "E1", stop=9500)

这篇关于Tradingview Pine 脚本`strategy.exit` 和`strategy.close` 不尊重`from_entry` 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 22:11