Add Trend Filter in Indicator MQL4

 

How can I get the price to compare with a MA in mql4?

I wanna make a condition if the price is upper the MA shows only buys arrow upper the MA, if the price is bellow the MA shows only sells bellow the MA.

 
Hire someone if you don't know how to program at all. People here won't do your job for free.
 
input int                   MAperiod      =21;//MA Period
input ENUM_MA_METHOD        MAmethod      =MODE_SMA;//MA Method
input ENUM_APPLIED_PRICE    MAapplied     =PRICE_CLOSE;//MA Applied Price
//In OnCalculate or a function

      int index=0; //Set to 1 if you want to only compare with closed bars
      double ma_value=TickNormalize(iMA(_Symbol,0,MAperiod,0,MAmethod,MAapplied,index));
      if(Close[index]>ma_value)
        {
         //Price is above MA
        }
      if(Close[index]<ma_value)
        {
         //Price is below MA
        }

.

double TickNormalize(double price)
{
   double ts=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
   double adjustedForTickSize=NormalizeDouble(MathRound(price/ts)*ts,_Digits);
   return(adjustedForTickSize);
}
 

Keith Watford

TickNormalize


What's that?
 
mt4ski:


What's that?

I have edited my post and added the function.

Reason: