# Ascending/Descending moving average

To add comments, please log in or register
51

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

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

15350

How do you define ascending? That's how you code it.
51

that's my problem.

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

15350

 masoud0455_a: that's my problem.I don't know how to define. Perhaps: Ascending | Define Ascending at Dictionary.com
51

:-)))

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