TimeFrameGetPrice

mastermind007

Well-Known Member
#1
Code:
	aavg = 5;
	if (Interval(0) == inDaily)
	{
		avO = MA(Open, aavg);
		avH = MA(High, aavg);
		avL = MA(Low, aavg);
		avC = MA(Close, aavg);
	} else
	{
		avO = MA(TimeFrameGetPrice("O", inDaily, 0 , expandLast), aavg);
		avH = MA(TimeFrameGetPrice("H", inDaily, 0 , expandLast), aavg);
		avL = MA(TimeFrameGetPrice("L", inDaily, 0 , expandLast), aavg);
		avC = MA(TimeFrameGetPrice("C", inDaily, 0 , expandLast), aavg);			
	}
Above AFL snippet produces different results based on Time frame in which data is being viewed, whereas the whole idea behind writing this was to eliminate precisely this. Can anyone figure out what I am not doing correctly?
 
#2
avO = MA( TimeFrameGetPrice("O", inDaily, 0 , expandLast), aavg);


The red part is evaluated first . . . lets say if using with 5 minutes chart . . .

then the avg will be for 5 values (of the red part) on 5 min chart . . .

i.e same day values used 5 times to get avg and not the values of last 5 days
 

mastermind007

Well-Known Member
#3
avO = MA( TimeFrameGetPrice("O", inDaily, 0 , expandLast), aavg);


The red part is evaluated first . . . lets say if using with 5 minutes chart . . .

then the avg will be for 5 values (of the red part) on 5 min chart . . .

i.e same day values used 5 times to get avg and not the values of last 5 days
Cannot comprehend what you mean... But yes.... I did plot the last 5 values of Ref(avC) and they all remain the same. Basically, what I want to achieve is MA over 5 daily values and then computations off it...
 

trash

Well-Known Member
#4
Code:
	aavg = 5;
	if (Interval(0) == inDaily)
	{
		avO = MA(Open, aavg);
		avH = MA(High, aavg);
		avL = MA(Low, aavg);
		avC = MA(Close, aavg);
	} else
	{
		avO = MA(TimeFrameGetPrice("O", inDaily, 0 , expandLast), aavg);
		avH = MA(TimeFrameGetPrice("H", inDaily, 0 , expandLast), aavg);
		avL = MA(TimeFrameGetPrice("L", inDaily, 0 , expandLast), aavg);
		avC = MA(TimeFrameGetPrice("C", inDaily, 0 , expandLast), aavg);			
	}
Above AFL snippet produces different results based on Time frame in which data is being viewed, whereas the whole idea behind writing this was to eliminate precisely this. Can anyone figure out what I am not doing correctly?
What you do is wrong. Use TimeFrameSet and expandfirst.

Code:
periods1440 = Param( "Periods", 5, 1, 200, 1 );

TimeFrameSet( inDaily );
MA1 = MA( C, periods1440 );
TimeFrameRestore();

Plot( TimeFrameExpand(MA1, inDaily, expandFirst), _DEFAULT_NAME(), colorOrange, ParamStyle("Style") );

// for daily TF check
if( Interval() == inDaily )
   Plot( MA( C, periods1440 ), _DEFAULT_NAME(), colorRed, ParamStyle("Style") );
 

mastermind007

Well-Known Member
#5
Code:
aavg  =  5;
if (Interval(0) == inDaily)
{
	dailyO = Open;
	dailyH = High;
	dailyL = Low ;
	dailyC = Close;

	avO = MA(dailyO, aavg);
	avH = MA(dailyH, aavg);
	avL = MA(dailyL, aavg);
	avC = MA(dailyC, aavg);
} else
{
	TimeFrameSet(inDaily);

	avOi = MA(Open , aavg);
	avHi = MA(High , aavg);
	avLi = MA(Low  , aavg);
	avCi = MA(Close, aavg);

	TimeFrameRestore();

	dailyO = TimeFrameExpand(Open, inDaily, expandLast);
	dailyH = TimeFrameExpand(High, inDaily, expandFirst);
	dailyL = TimeFrameExpand(Low,  inDaily, expandFirst);
	dailyC = TimeFrameExpand(Close,inDaily, expandLast);

	avO    = TimeFrameExpand(avOi  , inDaily,  expandFirst); 
	avH    = TimeFrameExpand(avHi  , inDaily,  expandFirst);
	avL    = TimeFrameExpand(avLi  , inDaily,  expandFirst);
	avC    = TimeFrameExpand(avCi  , inDaily,  expandFirst); 
}
This works as expected....
 

trash

Well-Known Member
#6
It is pretty simple to understand why it is so. Think about again why it provides different results with your Timeframeset method you were using and you will understand.