Need help to debug indicator

 

Hi, I am making very simple indicator which just checks all MAs and draws 2 line for high and low values. But by some reasons, after initialization it draws wrong lines and only if I leave it runing for some time it starts to draw "correct lines".

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_color2 Red

int MAPeriod=100;

int ma_shift=0;

int ma_method=MODE_SMA;

int applied_price=PRICE_MEDIAN;

double Buf_0[],Buf_1[];

//--------------------------------------------------------------------

int init()

{

//--------------------------------------------------------------------

SetIndexBuffer(0,Buf_0);

SetIndexStyle (0,DRAW_LINE);

SetIndexLabel (0,"MA High Value");

//--------------------------------------------------------------------

SetIndexBuffer(1,Buf_1);

SetIndexStyle (1,DRAW_LINE);

SetIndexLabel (1,"MA Low Value");

//--------------------------------------------------------------------

return;

}

//--------------------------------------------------------------------

int start()

{

int y,i,

Counted_bars;

double mmax=0, mmin=9999999999;

double Aval[10];

//--------------------------------------------------------------------

Counted_bars=IndicatorCounted();

y=iBars(NULL,PERIOD_M5)-Counted_bars-1;

while(y>=0)

{

mmax=0;

mmin=9999999999;

Aval[0]=iMA(NULL,PERIOD_M5,100,ma_shift,ma_method,applied_price,y) ;

Aval[1]=iMA(NULL,PERIOD_M5,200,ma_shift,ma_method,applied_price,y) ;

Aval[2]=iMA(NULL,PERIOD_M15,100,ma_shift,ma_method,applied_price,y) ;

Aval[3]=iMA(NULL,PERIOD_M30,100,ma_shift,ma_method,applied_price,y) ;

Aval[4]=iMA(NULL,PERIOD_H1,100,ma_shift,ma_method,applied_price,y) ;

Aval[5]=iMA(NULL,PERIOD_H1,200,ma_shift,ma_method,applied_price,y) ;

Aval[6]=iMA(NULL,PERIOD_H4,100,ma_shift,ma_method,applied_price,y) ;

Aval[7]=iMA(NULL,PERIOD_H4,200,ma_shift,ma_method,applied_price,y) ;

Aval[8]=iMA(NULL,PERIOD_D1,100,ma_shift,ma_method,applied_price,y) ;

Aval[9]=iMA(NULL,PERIOD_D1,200,ma_shift,ma_method,applied_price,y) ;

for(i=0;i<ArrayRange(Aval,0);i++)

{

if(Aval>mmax) mmax=Aval;

if(Aval<mmin) mmin=Aval;

}

Buf_0[y]=mmax;

Buf_1[y]=mmin;

y--;

}

//--------------------------------------------------------------------

return(0);

}

//--------------------------------------------------------------------
Files:
ind.png  139 kb
 
winters:
Hi, I am making very simple indicator which just checks all MAs and draws 2 line for high and low values. But by some reasons, after initialization it draws wrong lines and only if I leave it runing for some time it starts to draw "correct lines".

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_color2 Red

int MAPeriod=100;

int ma_shift=0;

int ma_method=MODE_SMA;

int applied_price=PRICE_MEDIAN;

double Buf_0[],Buf_1[];

//--------------------------------------------------------------------

int init()

{

//--------------------------------------------------------------------

SetIndexBuffer(0,Buf_0);

SetIndexStyle (0,DRAW_LINE);

SetIndexLabel (0,"MA High Value");

//--------------------------------------------------------------------

SetIndexBuffer(1,Buf_1);

SetIndexStyle (1,DRAW_LINE);

SetIndexLabel (1,"MA Low Value");

//--------------------------------------------------------------------

return;

}

//--------------------------------------------------------------------

int start()

{

int y,i,

Counted_bars;

double mmax=0, mmin=9999999999;

double Aval[10];

//--------------------------------------------------------------------

Counted_bars=IndicatorCounted();

y=iBars(NULL,PERIOD_M5)-Counted_bars-1;

while(y>=0)

{

mmax=0;

mmin=9999999999;

Aval[0]=iMA(NULL,PERIOD_M5,100,ma_shift,ma_method,applied_price,y) ;

Aval[1]=iMA(NULL,PERIOD_M5,200,ma_shift,ma_method,applied_price,y) ;

Aval[2]=iMA(NULL,PERIOD_M15,100,ma_shift,ma_method,applied_price,y) ;

Aval[3]=iMA(NULL,PERIOD_M30,100,ma_shift,ma_method,applied_price,y) ;

Aval[4]=iMA(NULL,PERIOD_H1,100,ma_shift,ma_method,applied_price,y) ;

Aval[5]=iMA(NULL,PERIOD_H1,200,ma_shift,ma_method,applied_price,y) ;

Aval[6]=iMA(NULL,PERIOD_H4,100,ma_shift,ma_method,applied_price,y) ;

Aval[7]=iMA(NULL,PERIOD_H4,200,ma_shift,ma_method,applied_price,y) ;

Aval[8]=iMA(NULL,PERIOD_D1,100,ma_shift,ma_method,applied_price,y) ;

Aval[9]=iMA(NULL,PERIOD_D1,200,ma_shift,ma_method,applied_price,y) ;

for(i=0;i<ArrayRange(Aval,0);i++)

{

if(Aval>mmax) mmax=Aval;

if(Aval<mmin) mmin=Aval;

}

Buf_0[y]=mmax;

Buf_1[y]=mmin;

y--;

}

//--------------------------------------------------------------------

return(0);

}

//--------------------------------------------------------------------

That is a multi time frame indicator using 6 time frames - you have to check the number of changed bars for each and every target time frame r else it will always work like that

 

Thank you for your reply. Is it possible to find a minimum number of tool bars among of all timeframes and use it in the while loop ?

I have done it, but still get the same wrong output .... :-(

....................

int cBars[6];

int cmin=99999999999;

//--------------------------------------------------------------------

cBars[0] = iBars(NULL,PERIOD_M5);

cBars[1] = iBars(NULL,PERIOD_M15);

cBars[2] = iBars(NULL,PERIOD_M30);

cBars[3] = iBars(NULL,PERIOD_H1);

cBars[4] = iBars(NULL,PERIOD_H4);

cBars[5] = iBars(NULL,PERIOD_D1);

for(i=0;i<ArrayRange(cBars,0);i++)

{

if(cBars<cmin) cmin=cBars;

Print("cBars[",i,"]=",cBars);

}

Counted_bars=IndicatorCounted();

y=cmin-Counted_bars-1;

while(y>=0)

......

MArange GER30,M5: cmin=1941

 
winters:
Thank you for your reply. Is it possible to find a minimum number of tool bars among of all timeframes and use it in the while loop ?

I have done it, but still get the same wrong output .... :-(

....................

int cBars[6];

int cmin=99999999999;

//--------------------------------------------------------------------

cBars[0] = iBars(NULL,PERIOD_M5);

cBars[1] = iBars(NULL,PERIOD_M15);

cBars[2] = iBars(NULL,PERIOD_M30);

cBars[3] = iBars(NULL,PERIOD_H1);

cBars[4] = iBars(NULL,PERIOD_H4);

cBars[5] = iBars(NULL,PERIOD_D1);

for(i=0;i<ArrayRange(cBars,0);i++)

{

if(cBars<cmin) cmin=cBars;

Print("cBars[",i,"]=",cBars);

}

Counted_bars=IndicatorCounted();

y=cmin-Counted_bars-1;

while(y>=0)

......

MArange GER30,M5: cmin=1941

winters

It can be done Will post you one solution

 

Thank you!!!

 
winters:
Re: Need help to debug indicator

Thank you for your reply. Is it possible to find a minimum number of tool bars among of all timeframes and use it in the while loop ?

I have done it, but still get the same wrong output .... :-(

....................

int cBars[6];

int cmin=99999999999;

//--------------------------------------------------------------------

cBars[0] = iBars(NULL,PERIOD_M5);

cBars[1] = iBars(NULL,PERIOD_M15);

cBars[2] = iBars(NULL,PERIOD_M30);

cBars[3] = iBars(NULL,PERIOD_H1);

cBars[4] = iBars(NULL,PERIOD_H4);

cBars[5] = iBars(NULL,PERIOD_D1);

for(i=0;i<ArrayRange(cBars,0);i++)

{

if(cBars<cmin) cmin=cBars;

Print("cBars[",i,"]=",cBars);

}

Counted_bars=IndicatorCounted();

y=cmin-Counted_bars-1;

while(y>=0)

......

MArange GER30,M5: cmin=1941

winters

What is the wrong result you are getting?

That code will find the minimal number of bars of the scaned time frames

Reason: