Sloping MA

 

I'm reasonably new to this, therefore it may be staring me in the face, but as of yet I've had no luck finding the information.  

 What I want to do is have Moving averages 8, 20, 50, 200 have crossover signals for the 8, 20 - but I only want the trade to take place IF the MA(200) and the MA(50) are sloping upward (if long) and downward if short.

 Love any suggestions on this one.

 

Thanks 

 

So assuming you have used the iMA call to get a handle to your Moving Averages. You might end up with something like:

double ma200[2];

double ma50[2];

CopyBuffer(iMa200Handle,0,0,2,ma200);

CopyBuffer(iMa50Handle,0,0,2,ma50);

//Get the slope of ma200

double slopeMa200 = ma200[0] - ma200[1];

double slopeMa50 = ma50[0] - ma50[1];

 Now that you have the slopes you should be able to continue.

Alternatively if you have used CiMA and the associated Create method like in the How to Create a Module of Trading Signals then you might have something like:

In your Class definition 

protected: 

CiMA m_MA200;

CiMA m_MA50;

protected:

double MA200(int index){return (m_MA200.Main(index));} 

double MA50(int index){return (m_MA50.Main(index));}  

Initialize like in the article mentioned above

Then in your logic checking for open or close you would use something like:

MA200(1) > MA200(2) //Increasing

MA50(1) < MA50(2) //Decreasing 

In the appropriate logical spots.

Hope that helps.