Hi,
Wanted to get the periodicity in AFL, basically I need to calculate the CAR in exploration or backtesting and use different divisor according to the periodicty used.
Currently I have a code where I calculate the difference in days beetween the first bar and next bar. Is a really dirty solution and I wondered if anyone has a better one to share. TRyied to make it work at the very first sympbol, but does't work.
Any help would be appreciated.
fbr = Status( "FirstBarInRange" );
lbr = Status( "LastBarInRange" );
//if ( Status( "stocknum" ) == 0 )
NumOfDays= LastValue(ValueWhen(fbr==1,Ref(DaysSince1900(),1),1)-ValueWhen(fbr==1,DaysSince1900(),1));
If(NumOfDays<5) TF=0; If(NumOfDays>=6 AND NumOfDays <15) TF=1; If(NumOfDays>15) TF=2;
VarSet("ND",NumOfDays);
VarSet("TF",TF);
NumOfDays= VarGet("ND");
TimeFrame=StrExtract("Daily,Weekly,Monthly",VarGet("TF"));
if(TimeFrame=="Daily") CarDiv=252; if(TimeFrame=="Weekly") CarDiv=52;
if(TimeFrame=="Monthly") CarDiv=12;