Monthly bar tests only going back 17 months

I can’t get a strategy using monthly bars to test farther back than 17 months. Wondering if any of you can spot something in my code preventing this.

I have a strategy where I try to confirm multiple timeframes are synchronized (all having a higher close than open for their respective time periods). The timeframes are daily, weekly, monthly.
I’m using TimeFrameSet and TimeFrameRestore to create the various period’s Open, High, Low, Close data points. The core of the strategy confirms the daily close is higher than the daily open; the weekly close is higher than the weekly open; and the monthly close is higher than the monthly open.

//////////////////////// MONTHLY 
TimeFrameSet(inMonthly); 
TMOpen = Open; 
TMHigh = High; 
TMLow = Low; 
TMClose = Close; 
TimeFrameRestore(); 
	 
LongSetup = TMClose > TMOpen; // Monthly Bar Bullish 
Buy = LongSetup;
Sell = 0;
Nbar ApplyStop used to exit.

It seems to be working but will only execute trades going back about 17 months (from August 2021).
I thought maybe it could be I’m not loading enough bars, but my Database Settings show I’m loading 10,000 days, and I have no problem running any of my other strategies back 20 years to present.

All ideas appreciated.

FYI, your code is improper coding because you are missing TimeFrameExpand() function.

//////////////////////// MONTHLY 
TimeFrameSet(inMonthly); 
TMOpen = Open; 
TMHigh = High; 
TMLow = Low; 
TMClose = Close;

LongSetup = TMClose > TMOpen; // Monthly Bar Bullish  
TimeFrameRestore(); 

LongSetup = TimeFrameExpand(LongSetup, inMonthly);	 

Buy = LongSetup;
Sell = 0;
//Nbar ApplyStop used to exit.

Important read (orange boxes too)
http://www.amibroker.com/guide/h_timeframe.html

My inference was TimeFrameExpand() was just for displaying the bars correctly on a chart in a non-native timeframe, but are you saying that using TimeFrameExpand() it's required just to complete a screen backtest or exploration?

No, you should always expand. It is no where written to expand for charts only.

If you do not expand then you are working with compressed data.

Simply follow the manual.

Orange box from upper link:

IMPORTANT: TimeFrameExpand IS REQUIRED for any formula that uses TimeFrame* functions. If you don't expand time compressed data you will have incorrect timestamps (see description below in "How it works").

3 Likes

Thanks for your help. I think I can get what I need just using TimeFrameGetPrice. Appreciate the direction you offered.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.