iMAOnArray produces zeros unless linked to a line buffer?

 

Some code to calc MACD:

int FastEMA = 12;
int SlowEMA = 26;
int SignalSMA = 9;


if(counted_bars > 0) counted_bars--;

limit = Bars - counted_bars;

for(i=0; i < limit; i++)
MACDBuffer[i] = iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i) - iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);

for(i=0; i < limit; i++)

MACDSignal[i] = iMAOnArray(MACDBuffer,Bars,SignalSMA,0,MODE_EMA,i);

-----------------------------------------------

MACDSignal[i] gets zeros, UNLESS I have these statements (but I don't particularly want to graph this data, just use in in computations):

SetIndexDrawBegin(1,SignalSMA);

SetIndexBuffer(0,MACDBuffer);
SetIndexBuffer(1,MACDSignal);
SetIndexStyle(0,DRAW_LINE);

SetIndexStyle(1,DRAW_LINE);


Why would linking MACDBuffer and MACDSignal to these Buffers make things calc differently?


Thank you

 

Index Buffers are 'special'

- they are automatically extended as more bars are formed

- they are accessed in 'reverse order' i.e. [0] is 'last' one, not 'first'

I suggest that you read up on them

 
oh, and to stop any of the up to 8 Index Buffers displaying, use SetIndexStyle(N, DRAW_NONE);
 
brewmanz:
oh, and to stop any of the up to 8 Index Buffers displaying, use SetIndexStyle(N, DRAW_NONE);

Thank you. But it puzzles me that my MACDSignal[i] array will not compute correctly UNLESS I have this: SetIndexBuffer(1,MACDSignal);

 
Reason: