I am modifying a strategy to only exit the trade after a set number of candles.
I put in an input for timeframe
(in inputs section of script) and set the exit rule at the bottom (barssince
) - it is working a lot of the time, but some trades are still closing sooner. Can't figure out what is causing this.
What else needs to be done so that it exclusively exits the trade only on the number of bars specified?
Here is the script: https://pastebin.com/8HQyJxa0 (updated)
It seems like when longer expiry times are set, that an UP trade is prematurely closing a DOWN, and vice versa. I really need both trades to be able to run concurrently, closing only after the number of bars specified by timeframe
UPDATE: Apparently using strategy.position_size <= 0
to specify no shares or borrowed could avoid it closing my currently open positions - but not sure how this could fit into the current script.