looping and indexes

#1
looping and indexes for a new indicator

good morning everyone


now I'm tryng to do some new statistics for my algoritms, namely those suggested by Chande in one of his books: in particular, the statistic projection of the DrawDowns, in a way different from the use of the Montecarlo simulation and more similar to inferential statistic
You can got the Idea here:
https://books.google.it/books?id=Qf...ROD68Q6AEIHzAA#v=onepage&q=chande CCZ&f=false

a lot of words but in essence a very simple computation : the basic need is
  • the number of Drawdowns
  • the max DrawDown for every period of DrawDown
  • the lenght of every period of Drawdowns


I have tried my hand with the following AFL, but it doesn't work ... it seem the variable under the [j] index, the eqx[j] , doesn't take any value

hoping the suggestion will be useful to anybody, may I ask an help for the code?
any is interested in complete with me the code for this function ?
Thanks in advance for your kindness
regards


( PS
the code here is only for example: the buy/sell rule is obviously very simple, the trouble is within the loop
Thanks again)




GfxTextOut("CCZ 001 ",10,20);
init=50000;
SetOption( "InitialEquity", init );
SetChartOptions(0,chartShowArrows|chartShowDates);
SetTradeDelays(1,1,1,1);
BuyPrice=SellPrice=CoverPrice=ShortPrice=O;
SetPositionSize( 1, spsShares ) ;

Buy= Cross ( MACD(), Signal() ) AND C>MA(C,200);
Sell= Cross (Signal(), MACD() ) OR C< MA(C,50) OR RSI(5)<90 ;

Short=Cover=0;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);


Etrade=0;
rend=0;
j=0;
k=0;
pike=0; // livello massimo locale della equity, serve per il DD
DD=0; // drawdonw
MDD =0; // maxDD
eq= Equity()- init ;
eqx=0;
eq1=Ref(Equity(),-1) ;

Lap = IIf ( Month() == Ref (Month(), -1) , 0, 1); //Lap = iif ( Day() < ref (Day(), -1) , 0 , 1 ) ;


start= BarCount -3650;
Lap = IIf ( Month() == Ref (Month(), -1) , 0, 1);


for (i = start ; i < BarCount; i++)
{

if ( lap == 1)
{
j= j +1 ;
eqx[j]= eq;
rend[j]= eqx[j] - eqx[j-1];
if ( pike [j-1]> eqx[j] )
{
pike[j]= eqx[j];
DD[j] =0;
}
else
{
DD[j]= eqx[j] -pike[j] ;
MDD = IIf (MDD < DD[j] , DD[j] , MDD );

}

}


}



Plot ( C, "Close", colorBlack, styleCandle);
Plot ( MA(C,200) , "ma200", colorAqua);
Plot ( MA(C,50) , "ma50", colorBlue);
Plot ( Lap, "lap" , colorAqua, styleLeftAxisScale);
Plot ( j, "j" , colorOrange, styleOwnScale);

Plot ( eq, "eq" , colorOrange, styleOwnScale);
Plot ( eqx, "eqx" , colorRed, styleLeftAxisScale);
Plot ( pike, "pike" , colorGreen, styleLeftAxisScale);
Plot ( DD, "DD" , colorGreen, styleLeftAxisScale);
Plot ( MDD, "MDD" , colorGreen, styleLeftAxisScale);


PlotShapes ( IIf (Buy, shapeSmallUpTriangle, 0) , IIf (Buy,colorGreen, colorBlue )) ;
PlotShapes ( IIf (Sell, shapeSmallDownTriangle, 0) , IIf (Sell,colorRed, colorBlue )) ;
PlotShapes ( IIf (Short, shapeHollowSmallDownTriangle, 0) , IIf (Short,colorRed, colorBlue )) ;
PlotShapes ( IIf (Cover, shapeHollowSmallUpTriangle, 0) , IIf (Cover,colorGreen, colorBlue )) ;
 
Last edited:

Similar threads