help with indicator

 

Can anyone see why the first alert is returning zero every time ? I wanted it to compare the buffers current and previous values and therefore the Alert should return a varying result of either 0, 1 or 2 depending if the direction is up down or mixed but it isnt working that way

int start()
  {
   if(Bars<=MA_Period) return(0);
   int limit,mdf=0,idf=0;
   int counted_bars=IndicatorCounted();
   double ma[4,2], sprd=MarketInfo(Symbol(),MODE_SPREAD)*Point;
   double mid,highval,lowval,current;   
//---- error check
   if(counted_bars<0) return(-1);
//---- recount last bar
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- main loop
   for(int i=0; i<limit; i++)
    {mah_buf[i]=iMA(NULL,0,MA_Period,0,MODE_LWMA,PRICE_HIGH,i)-sprd;
     mal_buf[i]=iMA(NULL,0,MA_Period,0,MODE_LWMA,PRICE_LOW,i)+sprd;
     highval=mah_buf[i];
     lowval=mal_buf[i];
     mid=(highval-lowval)/100*38.2;
     uf_buf[i]=highval-mid;
     lf_buf[i]=lowval+mid;
//----get current and previous values  
     for(int j=0; j<2; j++)
      {ma[0,j]=mah_buf[i];
       ma[1,j]=mal_buf[i];
       ma[2,j]=uf_buf[i];
       ma[3,j]=lf_buf[i];   //Everyting appears to work fine up to this point.
      }
//----compare current and previous values
     for(int k=0; k<4; k++)    
      {if(ma[k,0]>ma[k,1]) idf++;
       if(ma[k,0]<ma[k,1]) idf--;
      }
//----calculate direction
     if(idf==4) mdf=0; //direction is up.
     if(idf==-4) mdf=1; //direction is down.
     if(idf<=3 && idf>=-3) mdf=2; //direction is mixed.
     Alert("idf= ",idf);    //This alert returns zero every time i dont see why.
     Alert("mdf= ",mdf);    //This alert returns two every time because idf is always at zero
   }
  return(0);
}


 
     for(int j=0; j<2; j++)
      {ma[0,j]=mah_buf[i];
       ma[1,j]=mal_buf[i];
       ma[2,j]=uf_buf[i];
       ma[3,j]=lf_buf[i];   //Everyting appears to work fine up to this point.
      }

should be:

     for(int j=0; j<2; j++)
      {ma[0,j]=mah_buf[i+j];
       ma[1,j]=mal_buf[i+j];
       ma[2,j]=uf_buf[i+j];
       ma[3,j]=lf_buf[i+j];   //Everyting appears to work fine up to this point.
      }

ma[x,0] is always equal ma[x,1] so idf will be 0 all the time.


But i don't see the point why you use this additional 2 dimensional array...


//z

 

damn yes that isnt going to work that way is it, i was trying to put the values of the 4 lines current and previous values in an array to make it easy to compare them I probably should have just done it like this in the first place.

     if(mah_buf[i]>mah_buf[i+1]) idf++;
     if(mah_buf[i]<mah_buf[i+1]) idf--;
     if(mal_buf[i]>mah_buf[i+1]) idf++;
     if(mal_buf[i]<mal_buf[i+1]) idf--;
     if(uf_buf[i]>uf_buf[i+1])   idf++;
     if(uf_buf[i]<uf_buf[i+1])   idf--;
     if(lf_buf[i]>lf_buf[i+1])   idf++;
     if(lf_buf[i]<lf_buf[i+1])   idf--;
 

Yeah arrays are only useful if you have a large dataset.

btw, i just saw that you use the two dimensional array totally wrong should be like:

 ma[1][j]  =#someNumber 


//z

 
zzuegg:

Yeah arrays are only useful if you have a large dataset.

btw, i just saw that you use the two dimensional array totally wrong should be like:


//z


oh ok yeah i see what your saying ... i was trying to get the line values from the buffer and into the array as the buffer was filled, then i was going to draw a 3 colored histogram to show direction, up down or indeterminate .. i didnt think it through properly, im going to redo that part of it
 
zzuegg:

Yeah arrays are only useful if you have a large dataset.

btw, i just saw that you use the two dimensional array totally wrong should be like:

 ma[1][j]  =#someNumber 
Nothing wrong with that ma[1,j] or ma[1][j] are equivalent. There is a compiler bug where the ma[1,j] gives an error under some circumstances.