Get MA Value of specific date and specific time frame

Hi All,

the following afl will give us MA Value of previous bar.
but is it possible to get MA value of specific date and time frame as well ?
for example, how to get MA value for 13-Sep-2022 in H2 or other time frame like H1 or M30 time frame ?

i need to compare today MA value and today close price
versus specific date and time frame of those values.

CP = Close;
printf ( " \n");
printf ("CLOSE_TODAY = " +CP);
printf ( " \n");

MAV_TODAY = MA( Close, 500);
printf ( " \n");
printf ("MA Value TODAY = %g\n", MAV_TODAY);
printf ( " \n");


ClosePreviousBar1 = ref( CLOSE, -1 );
MAV_PREVIOUS_BAR = MA( ClosePreviousBar1, 500);

printf ("CLOSE PREVIOUS BAR = " +ClosePreviousBar1);
printf ( " \n");
printf ("MA Value PREVIOUS BAR = %g\n", MAV_PREVIOUS_BAR);

Please use search function.
There are "thousands" of threads already
No need to repeat everything.
There is almost nothing that has not been covered already.

Hint: Lookup function.

Also see

i have read that several times and apply most of the command for my others afl, get familiar with them as well.
most are dealing with previous bar, previous day bar, previous week bar.
but not about particular date.
i know how to get close price for particular date, but haven't found how to derive ma value for specific date with particular time frame.

i've tried that one ( lookup function) before i create this thread.
and also have tried a lot of code
playing with "bar replay" shown it can be done
just haven't found the code yet

InputDate = "2022-09-09";
MYPRICE = Lookup( Close, _DT( InputDate ),-1 );
printf( "MYPRICE = " +MYPRICE);
printf ( " \n");

mymav = MA( MYPRICE, 500 );
printf( "MYMAV = " +mymav);

haven't get the expected result

The Lookup() function returns a single value (i.e. a SCALAR), which you are storing in MYPRICE. Then you're trying to calculate a moving average from a single value, which of course won't do what you want.

Try calculating the moving average first, and then using Lookup() to select one value out of the ARRAY that's returned from the MA() function.

I also recommend you do some additional reading so that you have a better grasp of AmiBroker's array processing capabilities, as this is absolutely essential to writing AFL.


And where is that mentioned in first post?
No where!

If you have tried it then why not following the manual which radtke repeats again?



no need to talk like that, if you cannot be nice, no need to put down people.
your attitude only bring negative atmosphere.
don't repeat negative habit of scolding people.

if you don't happy to answer, then don't do it
if you think it doesn't deserve your time, then just leave it
just leave it and let someone who happy to answer to do it
as simple as that

thank you, for taking your time replying

InputDate = "2022-09-08";
MYMA= MA(C,500);

FINALMA=Lookup( MYMA, _DT( InputDate ), -1 );

printf( " \n ");
printf( " MA TODAY = " +MYMA);

printf( " \n ");
printf( " MA 2022-09-08 = " +FINALMA);

Thank you so much Matt
i really appreciate your kindness

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