How do I apply data from the previous indicator?

 

Hi good people,

I am trying to use to MAs with one using data from the other.

However, I am unable to skip over this hurdle on my expert advisor.

Here is the code I have for this so far. Any pointers to get this working will be highly appreciated.

Thanks in advance.

//Define properties for Smooth MA
int SmoothAverageArrayDefinition = iMA (_Symbol,_Period,5,0,MODE_SMMA,PRICE_CLOSE);
      
//Define properties for Linear MA - Use previous indicator data
int LinearAverageArrayDefinition = iMA (SmoothAverageArrayDefinition,0,5,0,MODE_LWMA);
      
//Define MA1, one line, current candle, 2 candles, store result
CopyBuffer(SmoothAverageArrayDefinition,0,0,2,SmoothAverageArray);
      
//Define MA2, one line, current candle, 2 candles, store result
CopyBuffer(LinearAverageArrayDefinition,0,0,2,LinearAverageArray);
 
You just put the handle of the first Indicator instead of the price inside th second.
 
George Ndwiga #:

I am a newbie to this. I am not quite clear on what you mean by this. Could you kindly demonstrate what needs to change?

First of all fix your posted code. 
You have the handle
SmoothAverageDefinition which is defined as
iMA(symbol,timeframe,period,shift,method,price).

If you do it otherwise compiler throws errors about unknown function overloads or something.

Then set the second one up in the same way and then replace the price by SmoothAverageDefinition. Now you can use CopyBuffer on the second one and have the results of both calculations on top of each other.
 

Okay. Let me try apply this then get back to you.

Tobias Johannes Zimmer #:
First of all fix your posted code. 
You have the handle
SmoothAverageDefinition which is defined as
iMA(symbol,timeframe,period,shift,method,price).

If you do it otherwise compiler throws errors about unknown function overloads or something.

Then set the second one up in the same way and then replace the price by SmoothAverageDefinition. Now you can use CopyBuffer on the second one and have the results of both calculations on top of each other.
 

It has worked just as I wanted.

Thank you very much for your insights.

Tobias Johannes Zimmer #:
First of all fix your posted code. 
You have the handle
SmoothAverageDefinition which is defined as
iMA(symbol,timeframe,period,shift,method,price).

If you do it otherwise compiler throws errors about unknown function overloads or something.

Then set the second one up in the same way and then replace the price by SmoothAverageDefinition. Now you can use CopyBuffer on the second one and have the results of both calculations on top of each other.
Reason: