Download MetaTrader 5
To add comments, please log in or register
Sell products right in MetaTrader. Millions of traders are waiting for this!
masoud0455_a
51
masoud0455_a 2016.07.15 12:27 

I want to know Ascending/Descending moving average in mql4.

give me an idea to code this. How can I do it?


whroeder1
13619
whroeder1 2016.07.15 13:57  
How do you define ascending? That's how you code it.
masoud0455_a
51
masoud0455_a 2016.07.15 14:08  

that's my problem.

I don't know how to define.can someone help me and give me an idea to define it?

whroeder1
13619
whroeder1 2016.07.15 20:15  
masoud0455_a: that's my problem.I don't know how to define.
Perhaps: Ascending | Define Ascending at Dictionary.com
masoud0455_a
51
masoud0455_a 2016.07.15 21:00  

:-)))

I got it and I coded it.

Just get 2 price of first and 15 candle back and subtract them and compare the result with my define distance.

#property copyright "Masoud"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property show_inputs

 extern int CandlesBack=15; //How many candles look back:
 extern int pipsdefine=5;//How many pips define at M5
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 { 
  
   double pips =Point; 
   if(Digits==3||Digits==5)
   pips*=10;
   //------
   
    int timef;             
    double distance=pipsdefine*pips;
    
    switch(Period())
    {   
      case 15: timef=15; distance*=2;  break; //10 pips M15
      case 30: timef=30; distance*=4;  break; //20 pips M30          
      case 60: timef=60; distance*=4; break;
      case 240: timef=240; distance*=5; break;
      case 1440:timef=1440; distance*=12; break;
      default:timef=5; break;         
    }
    
    double startSMA20 =iMA(Symbol(),timef,20,0,MODE_SMA,PRICE_CLOSE,1);
    double endSMA20 =iMA(Symbol(),timef,20,0,MODE_SMA,PRICE_CLOSE,CandlesBack);
     
    if(startSMA20-endSMA20 > distance) MessageBox("Ascending","Trend Info"); 
    else if(startSMA20-endSMA20 < -distance) MessageBox("Descending","Trend Info"); 
    else MessageBox("Sideway","Trend Info");
            
 }
/
To add comments, please log in or register