'Tradingview Pine script `strategy.exit` and `strategy.close` don't respect `from_entry` value
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.
Solution 1:[1]
in the entry , you should have the price you target for your TP en SL
something like limit=close+10000*syminfo.mintick and stop=close-10000*syminfo.mintick
in case of a long position
and in the exit, you should directly put the ticks
stop=9000 (it's like 900 pips, it's huge)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | deeBo |
