Timeframe Command Issues

I am trying to use the TimeFrame command in the following contexts. Note that I am using 5-minute Intraday data:

This code below using TimeFrameGetPrice() definately works in my program:

DailyOpen = TimeFrameGetPrice( "O", inDaily, -0 );
PrevDailyClose = TimeFrameGetPrice( "C", inDaily, -1 );
PrevDailyHigh = TimeFrameGetPrice( "H", inDaily, -1 );
PrevDailyLow = TimeFrameGetPrice( "L", inDaily, -1 );

But when I try to compute the 20, 50, and 200 day moving averages, then the code below does not generate any results or values:

TimeFrameSet( inDaily ); // switch to daily frame
SMA200 = MA( C, 200 );
SMA50 = MA( C, 50 );
SMA20 = MA( C, 20 );
TimeFrameRestore(); // restore time frame to original

I even tried the code below to no avail:

for ( i = 0, SMA = 0; i < 200; i++ ) {
	SMA = SMA + TimeFrameGetPrice( "C", inDaily, -i ) / ( i + 1 );

Any help would be appreciated. Thanks!

@pmfiorini, how did you confirm that your code did not generate any values? Also, did you remember to use TimeFrameExpand() after you call to TimeFrameRestore(), i.e. something like this:

SMA200 = TimeFrameExpand(SMA200, inDaily, expandLast);

I tried to confirm that the code generated values by using "DEBUG". Is there another way I am not aware of?

I tried the code you recommended - The values when I run DEBUGVIEW are {empty}

By default, the built-in debugger limits you to 200 bars of data in your base timeframe, as explained here: https://www.amibroker.com/guide/h_debugger.html

You should try outputting your values using an Exploration, and of course verify that you really do have enough data in your database to calculate a 200-day MA.


You are correct - Stupid mistake on my part - Yes, you are correct. I did not have 200 bars worth of data - Thanks for your time...I tried it with the 20 MA and it works fine - I remember I only have 104 bars of data...