calculation for an indicator does not work

 

The calculation for an indicator at the last statement highligted in red, below, (ie) OutPut3[i]=(xx[i]+yy[i])/2; //???????????????????????

does not work. My intent is to calculate the one day and three day moving averages (xx[i] and yy[i]) and then plot

the average of those two averages.

What am I doing wrong?

double offset=0.0050; //<--SET OFFSET TO DESIRED VALUE

double xx[]; //??????????????????????????????????????????

double yy[]; //??????????????????????????????????????????

#property indicator_chart_window

#property indicator_buffers 9 //limit=8. Internally no limit but can display only 8.

#property indicator_color3 Black

//---- BUFFERS

double OutPut3[];

//---- INPUT(S)

extern int Periods = 1;

//+------------------------------------------------------------------+

//+ INIT |

//+------------------------------------------------------------------+

int init()

{

//---- ERROR TRAPS

if( Periods <= 0 ) { Alert("Invalid Periods"); return(-1); }

//---- INDICATOR STYLE

SetIndexShift(3,1);

SetIndexBuffer(3, OutPut3);

SetIndexStyle( 3, DRAW_LINE, STYLE_DOT, 1, Red);

SetIndexDrawBegin(3, Periods );

//----

return(0);

}

//+------------------------------------------------------------------+

//+ DEINIT |

//+------------------------------------------------------------------+

int deinit() { return(0); }

//+------------------------------------------------------------------+

//+ START |

//+------------------------------------------------------------------+

int start()

{

//---- Find MaxRecords

int counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

if(counted_bars>0) { counted_bars--; }

int MaxRecords = Bars-counted_bars;

Periods=1;

for( int i = 0; i < MaxRecords ; i++ )

{

double sum1dayma = 0.0;

for( int k = 0; k < Periods; k++ )

{

sum1dayma += (High[i+k]+Low[i+k])/2;

}

//OutPut0[i] = sum1dayma/Periods;

xx[i] = sum1dayma/Periods; //???????????????????????????

}

Periods=3;

for( i = 0; i < MaxRecords ; i++ )

{

double sum3dayma = 0.0;

for( k = 0; k < Periods; k++ )

{

sum3dayma += (High[i+k]+Low[i+k])/2;

}

yy[i] = sum3dayma/Periods; //???????????????????????????

}

//----calculate & plot average of xx[i] & yy[i]

for( i = 0; i < MaxRecords ; i++ )

{

OutPut3[i]=(xx[i]+yy[i])/2; //???????????????????????

}

//----

return(0);

}

 

First should to set array size of xx , yy

and then use them !!

see ArrayResize(.....) function in help

int ArrayResize( object&array[], int new_size)