TradingView Pinescript - how to TP/SL for all trades instead of auto-exit with new trades

Viewed 533

I want to develop a strategy where every single trade that I enter will hit either the point of Take Profit or Stop Loss. For example, I have a short entry with the exit settings as below:

strategy.exit("TP/SL", "Short Entry", stop=low + ATR, limit=close - ATR)

but if the next day there's a long entry, it will enter that long position and automatically close my previous short entry, making the exit settings useless. Is there any ways to prevent this? Thanks in advance.

1 Answers

after a lot of search finally found it...! just use strategy.opentrades== 0 when your long or short condition is true

long = (OSrsi and BullEng) and strategy.opentrades==0 short= (OBrsi and BearEng) and strategy.opentrades==0

use this condition to enter trades

Related