问题
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)
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
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")
All have the same effect whereby "SL-E1" causes "E0" to exit.
回答1:
Try this:
// @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)
来源:https://stackoverflow.com/questions/64743470/tradingview-pine-script-strategy-exit-and-strategy-close-dont-respect-from