Is This A Bug In iMA?

 
#property indicator_separate_window

#property indicator_buffers 7
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Blue
#property indicator_color7 Blue
#property indicator_color8 Blue
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 1
#property indicator_width8 1

double g_fBuffer1[];
double g_fBuffer2[];
double g_fBuffer3[];
double g_fBuffer4[];
double g_fBuffer5[];
double g_fBuffer6[];
double g_fBuffer7[];


int init()
{
   IndicatorBuffers(7); //8);

   SetIndexStyle( 0, DRAW_LINE, 0 );
   SetIndexStyle( 1, DRAW_LINE, 0 );
   SetIndexStyle( 2, DRAW_LINE, 0 );
   SetIndexStyle( 3, DRAW_LINE, 0 );
   SetIndexStyle( 4, DRAW_LINE, 0 );
   SetIndexStyle( 5, DRAW_LINE, 0 );
   SetIndexStyle( 6, DRAW_LINE, 0 );

   SetIndexBuffer( 0, g_fBuffer1 );
   SetIndexBuffer( 1, g_fBuffer2 );
   SetIndexBuffer( 2, g_fBuffer3 );
   SetIndexBuffer( 3, g_fBuffer4 );
   SetIndexBuffer( 4, g_fBuffer5 );
   SetIndexBuffer( 5, g_fBuffer6 );
   SetIndexBuffer( 6, g_fBuffer7 );
   
   return(0);
}

int start()
{
   double iO,iH,iL,iC;

   int CountedBars=IndicatorCounted();
   if( CountedBars > 0 ) CountedBars--;
   
   for(int iPos=Bars-CountedBars-1; iPos>=0; iPos--)
   {
      iO = iMA( NULL, 0, 1, 0, 0, MODE_OPEN,  iPos );
      iH = iMA( NULL, 0, 1, 0, 0, MODE_HIGH,  iPos );
      iL = iMA( NULL, 0, 1, 0, 0, MODE_LOW,   iPos );
      iC = iMA( NULL, 0, 1, 0, 0, MODE_CLOSE, iPos );
   
      g_fBuffer1[iPos] = Open[iPos]  - iO; // Open  - Open  SHOULD  = 0 but does NOT //
      g_fBuffer2[iPos] = Close[iPos] - iC; // Close - Close SHOULD  = 0 but does NOT //
      g_fBuffer3[iPos] = Low[iPos]   - iL; // Low   - Low   SHOULD  = 0 but does NOT //

      g_fBuffer4[iPos] = High[iPos]  - iH; // High  - High  SHOULD  = 0 and DOES     //

      g_fBuffer5[iPos] = Open[iPos]  - iL; // Open  - Low   SHOULD != 0 but DOES     //
      g_fBuffer6[iPos] = Low[iPos]   - iC; // Low   - Close SHOULD != 0 but DOES     //
      g_fBuffer7[iPos] = Close[iPos] - iO; // Close - Open  SHOULD != 0 but DOES     //
   }
   
   return(0);
}
I have gone over this and over this and it still shows all the red lines (the ones that SHOULD be zero) all over the place and the blue lines (the ones that SHOULD be all over the place) at zero. Can anyone help?
 

Hi,LaYsX

Your code is wrong.Please check iMA function definition.

Right code is here.

iO = iMA( NULL, 0, 1, 0, 0, PRICE_OPEN, iPos );
iH = iMA( NULL, 0, 1, 0, 0, PRICE_HIGH, iPos );
iL = iMA( NULL, 0, 1, 0, 0, PRICE_LOW, iPos );
iC = iMA( NULL, 0, 1, 0, 0, PRICE_CLOSE, iPos );

(ref.

MODE_OPEN 0 Open price.
MODE_LOW 1 Low price.
MODE_HIGH 2 High price.
MODE_CLOSE 3 Close price.

PRICE_CLOSE 0 Close price.
PRICE_OPEN 1 Open price.
PRICE_HIGH 2 High price.
PRICE_LOW 3 Low price.

 
fai wrote >>

Hi,LaYsX

Your code is wrong.Please check iMA function definition.

Right code is here.

iO = iMA( NULL, 0, 1, 0, 0, PRICE_OPEN, iPos );
iH = iMA( NULL, 0, 1, 0, 0, PRICE_HIGH, iPos );
iL = iMA( NULL, 0, 1, 0, 0, PRICE_LOW, iPos );
iC = iMA( NULL, 0, 1, 0, 0, PRICE_CLOSE, iPos );

(ref.

MODE_OPEN 0 Open price.
MODE_LOW 1 Low price.
MODE_HIGH 2 High price.
MODE_CLOSE 3 Close price.

PRICE_CLOSE 0 Close price.
PRICE_OPEN 1 Open price.
PRICE_HIGH 2 High price.
PRICE_LOW 3 Low price.

Oh, thank you. I was working on someone elses code when I ran into this. Seems strange that they would have similar definitions (assuming they are arbitrary) and not number them the same. Thank you.