Does iMAOnArray cache?

 

I've been trying to figure this out for a while. I've boiled the code down to the following snippet. From what I can tell no matter what you change the value in the buffer to the "Average" stays the same.

#property indicator_chart_window

double Buffer[];

int init()
{    
   SetIndexBuffer( 0, Buffer);
   return(0);
}

int start()
{
   double BeforeReal, BeforeRef, AfterReal, AfterRef;
   
   // Ensure a minimum history //
   if( Bars <= 10 ) return(0);
       
   for( int iA = 0; iA < ArraySize( Buffer ); iA++ )
     Buffer[iA] = 10000 + iA*10;
   
   for( int iPos=10; iPos>=0; iPos--)
   {
      // Record values before change //
      BeforeReal = Buffer[iPos];
      BeforeRef  = iMAOnArray( Buffer, 0, 1, 0, MODE_LWMA, iPos );

      // Make a change //
      Buffer[iPos] = 31337.0;

      // Record values after change //
      AfterReal  = Buffer[iPos];
      AfterRef   = iMAOnArray( Buffer, 0, 1, 0, MODE_LWMA, iPos );

      Print( "(", BeforeReal, ", ", BeforeRef, ") -> (", AfterReal, ", ", AfterRef, ")" );
   }
   return(0);
}

This doesn't seem to be an "Array/Series" problem. The output of the snippet SHOULD look like:

(10000, 10000) -> (31337, 31337)

(10010, 10010) -> (31337, 31337)

...

Instead it looks like:

(10000, 10000) -> (31337, 10000)

(10010, 10010) -> (31337, 10010)

...

Can someone please explain this to me? Thanks.

 
Sometimes I have found that you have to have a "write" loop, then after that is all done, do "read" loop, to get the expected values from index buffers.
 

That is how I made my current program work but am wondering if that is the way it is intended and if so why it isn't documented.

-Ted

Reason: