2

The following code works for me when I try to set the stop loss and take profit level:

strategy.exit("TP/SL 1", "Long Entry 1",  stop = long_stop_level,  limit = long_profit_level)

But the issue for this code is that it will not tell me it is a stop loss exit or take profit exit.. so I tried to split it off to the following manner:

strategy.exit("SL 1", "Long Entry 1",  stop = long_stop_level)
strategy.exit("TP 1", "Long Entry 1",  limit = long_profit_level)

But I notice that only the stop loss is working but not the take profit, is there anyway I could fix that?

jguy
  • 161
  • 1
  • 11
  • Short answer, no. What do you need it split for? – Bjorgum Apr 07 '22 at 16:27
  • So that I can know what cause the strategy to exit, in the original code, it will only display "TP/SL 1" but does not tell me it hits the target profit or stop loss at all – jguy Apr 08 '22 at 09:17
  • 1
    I think the TV will can take care about such case. – Andrey D Apr 08 '22 at 10:42
  • @jguy FYI, TradingView added new comment parameters for the `strategy.exit()` function. https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}exit – Starr Lucky May 27 '22 at 13:32

1 Answers1

1

use this. and it will display on chart SL and TP. Note that i'm using v5

strategy.exit("exit Long", from_entry="Long",loss= sl,profit = tp,comment_profit="Buy TP", comment_loss="Buy SL")
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257