Close all open trades after X bars

Post Reply
GG158
Posts: 12
Joined: Sun Mar 12, 2023 8:24 pm

Close all open trades after X bars

Post by GG158 »

Hi,

I am trying to figure out how to close my open trade after 3-4 bars after the trade is open, regardless of floating profit/loss.

I have tried the below and it's not working.

Would someone be able to provide some help?

Screenshot_2.png
Screenshot_2.png (21.53 KiB) Viewed 215 times
NakedMarkets
Posts: 251
Joined: Tue Feb 22, 2022 11:06 am

Re: Close all open trades after X bars

Post by NakedMarkets »

Hi,

Could you be more specific please ?
For example, do you want to close you open trade always after a specific amount of elapsed bars or it depends on your timeframe ?
In the first case, it's not yet possible but we can add additional rules for that.
In the second case, you can obtain the open time of a trade and eventually compare it with the current backtest time.
In your screenshot, we can see that you compare the monthly days of the bar in position 1 and position 4, it will always happen since the bar in position 1 will be always more recent than the one in position 4, except at the beginning of a new month
GG158
Posts: 12
Joined: Sun Mar 12, 2023 8:24 pm

Re: Close all open trades after X bars

Post by GG158 »

I am trying to achieve the below:

On the daily timeframe:
If:

Candle(1)close>candle(1)open
&&
Candle(2)=close<candle(2)open

Then:
Buy (mkt) 0.1 (as an example)


And:
On the 1 hour timeframe:

Close trade during 4th daily candle at 11am (AEST)


See the below:

MCL1!_2024-02-26_14-33-17_LONG_ENTRY.png
MCL1!_2024-02-26_14-33-17_LONG_ENTRY.png (195.34 KiB) Viewed 204 times
NakedMarkets
Posts: 251
Joined: Tue Feb 22, 2022 11:06 am

Re: Close all open trades after X bars

Post by NakedMarkets »

Thanks for providing the details, this is easier to understand for us with this example.
So, as we understand, you want to close your open order always after the 4th candle has closed.
At the moment, this is not possible but we can add a rule for that.

Let's say we call it "order duration", this rule could be compared with a new "timespan" rule : expressed by a number of bars or a real timespan (just like current order expiration for pending order).
The condition would be in the exit rule :
IF "order duration" >= "timespan (4 bars)" THEN
-> Close the current trade

Would it okay for you like that ?
GG158
Posts: 12
Joined: Sun Mar 12, 2023 8:24 pm

Re: Close all open trades after X bars

Post by GG158 »

Yes, I would like to try using an order duration (timespan) rule.

Thanks!
Post Reply