Rolling Rate Of Return Plot

#1
Hi there.,

I am trying to make a working AFL to plot Rate Of Return based on a timeframe basis, in order to return a plot something like the one on this page as "Arith ROR(Periods): http://www.priceactionlab.com/Blog/2012/11/the-times-of-high-returns-in-holding-aapl-are-over/

I would like to make the AFL "TimeFrame ROC" selectable, no matter of the timeframe window currently selected.

My current AFL looks like this, but results has not been what I want to do:

Code:
_SECTION_BEGIN("Rolling Arithmetic ROR");
PF	=	ParamField( "Price field" );
RP	=	ParamList("Rolling Cycle","Daily|Weekly|Monthly|Quarterly|Yearly",4);
P	=	Param("Rolling Periods", 1, 1, 360, 1 );

// VARIABLES
switch (RP)	{
		case "Daily"		:	R = TimeFrameGetPrice( "PF", inDaily, -P );		break;
		case "Weekly"		:	R = TimeFrameGetPrice( "PF", inWeekly, -P );		break;
		case "Monthly"		:	R = TimeFrameGetPrice( "PF", inMonthly, -P );		break;
		case "Quarterly"	:	R = TimeFrameGetPrice( "PF", inQuarterly, -P );	break;
		default			:	R = TimeFrameGetPrice( "PF", inYearly, -P );		break;
	}



Plot( ROC( R, P), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style")  );



_SECTION_END();
I don't quite know if this is the right way to go, or if I need to write a "nested function" to expand or compress given the selected TimeFrame window.

Thanks for your Help Guys and Cheers!
 

trash

Well-Known Member
#2
No, you can't do it the way you did it.

Here is one way of doing it.

Code:
_SECTION_BEGIN("Rolling Arithmetic ROR");
RP	=	ParamList("Rolling Cycle","Daily|Weekly|Monthly|Quarterly|Yearly",4);
P	=	Param("Rolling Periods", 1, 1, 360, 1 );

// VARIABLES
switch (RP)	
{
	case "Daily":		R = inDaily;	break;
	case "Weekly":		R = inWeekly;	break;
	case "Monthly":		R = inMonthly;	break;
	case "Quarterly":	R = inQuarterly;break;
	default:		R = inYearly;	break;
}

TimeFrameSet( R );
PF	= ParamField( "Price field" );
ROC_ = ROC( PF, p );
TimeFrameRestore();

Plot( TimeFrameExpand( ROC_, R, expandFirst ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style")  );
_SECTION_END();
 
#3
Thanks a lot trash, it was very useful and enlightening... But my main idea is to; Based on the Parameters filled (TimeFrame and Period to look back), return the specific DATE as an array to calculate (or adjust) the ROC Periods based on the active TimeFrame window selected. Anyway, thanks for your suggestion! :thumb:
 

trash

Well-Known Member
#4
Based on the Parameters filled (TimeFrame and Period to look back), return the specific DATE as an array to calculate (or adjust) the ROC Periods based on the active TimeFrame window selected.
I don't understand this part or your English. Explain with example.

OR do you mean this way?
Code:
.
.
.
TimeFrameSet( R ); 
PF = ParamField( "Price field" ); 
ROC_ = Ref( ROC( PF, P ), -P ); 
TimeFrameRestore();
.
.
.
or

Code:
.
.
.
Lookback = Param( "LookBack", 0, 1, 360, 1 );
TimeFrameSet( R ); 
PF = ParamField( "Price field" ); 
ROC_ = Ref( ROC( PF, P ), -Lookback ); 
TimeFrameRestore();
.
.
.
 
Last edited:
#5
Sorry, must be my rusty english! I want to get the DateTime() of each bar given the timeframe() , then use them as time variables to count the bars involved for the ROC calculation on the selected interval()...

So if im inDaily interval and select Yearly as RP with 5 Periods back, go fetch the DateTime() when that condition apply and then count number of day bars back to apply the ROC criteria in formula.
 

Similar threads