How to close open positions at the end of the week

For intraday trade square off at market close, I was using the below code...

Sell = TimeNum() >= SquareOffTime OR xxx OR xxx;

I am coding for my swing system where I will be taking trade during the week and needs to be squared off on Friday at 3:20 PM if the trade is open. I am struggling to get the equivalent code for this.

Also, is there any way to know the last trade day of the week. This is because, sometimes Friday may be a holiday, in that case, the last day of the week would be Thursday.

Any help here is highly appreciated. I use Amibroker version 6.30.5.

Can you explain a bit more of how it works?

My system is a weekly pivot system in a 30-m chart.

Thanks in advance,

The code below will give you the last bar of the week at any timeframe lower than weekly, regardless of the day of the week it falls on. You can then use that to liquidate any positions at the end of each week in the backtest.

LastBarOfWeek = TimeFrameExpand(1, inWeekly, expandPoint);
Sell = LastBarOfWeek;

Wonderful.

Many Thanks MacAllan. You saved many hours.

1 Like