Code Library / Moving Average
MQL4 MA Slope Filter
Filter trades by MA slope angle threshold.
Language: MQL4 · Category: Moving Average · Tags: MA slope, filter, MQL4, trend strength, angle
Source code
double GetMASlope(int period,int shift,int look) {
double m0=iMA(Symbol(),0,period,0,MODE_EMA,PRICE_CLOSE,shift);
double m1=iMA(Symbol(),0,period,0,MODE_EMA,PRICE_CLOSE,shift+look);
return MathArctan((m0-m1)/(look*Point))*180/M_PI;
}
int GetTrend() {
double a=GetMASlope(50,0,5);
if(a>=15) return 1; if(a<=-15) return -1; return 0;
}How to use this snippet
This is a building block, not a finished trading system. Paste it into your own MQL4 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.