Why no drawing for my indicator sometime??

 

I simply code an indicator as below. When it is embeded into MT4, sometimes the drawing line can be reflected in the screen sometimes is empty. It really makes me confused.

Any wrong with my coding? Or 3 arrays slow down the caculating speed?

Can someone kindly give me a hand?

Thanks a lot...

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_color1 DodgerBlue

extern int GRSIPeriod =20;
double GRSI1[];
double GRSI2[];
double GRSI[];


int init()
{
string short_name;
IndicatorBuffers(3);
SetIndexBuffer(1,GRSI1);
SetIndexBuffer(2,GRSI2);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,GRSI);
short_name="GRSI("+GRSIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexDrawBegin(0,GRSIPeriod);
return(0);
}

int deinit()
{
return(0);
}


int start()
{
int limit;

int counted_bars=IndicatorCounted();
if ( counted_bars < 0 ) return(0);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
{
GRSI1[i]=MathMax((Close[i]-Close[i+1]),0);
GRSI2[i]=MathAbs((Close[i]-Close[i+1]));
GRSI[i]=iMAOnArray(GRSI1,0,5,0,MODE_SMMA,i)/iMAOnArray(GRSI2,0,5,0,MODE_SMMA,i)*100;
}
return(0);
}

 

Could someone help me on the question? I am really confused.

Sometimes, the line can be drawn but sometimes cannot. I just tried to load the code into another broker's MT4 plateform but the problem remain the same.

I begin to prefer to assume something wrong with my programming but not sure. Please point out if you notice.

I appreciate for your help!!

 

  1. limit=Bars-counted_bars;
    for(int i=0; i<limit; i++)
    {
       GRSI1[i]=MathMax((Close[i]-Close[i+1]),0);
       GRSI2[i]=MathAbs((Close[i]-Close[i+1]));
       GRSI[i]=iMAOnArray(GRSI1,0,5,0,MODE_SMMA,i)/iMAOnArray(GRSI2,0,5,0,MODE_SMMA,i)*100;
    }
    You can't use iMAonArray(GRSI1,...,i) until you initialize GRSI1[i].. GRSI1[i+4].
    limit=Bars-1-counted_bars;
    for(int i=limit; i>=0; i--)
Reason: