Download MetaTrader 5

Result of EMA

To add comments, please log in or register
amando
434
amando  

Hello,

 

i try to run my EA on a 1H chart, but i calculate an EMA on daily basis,

so i use this code to get the daily EMA

 

double EMA500 = iMA(_Symbol,PERIOD_D1,50,0,MODE_EMA,PRICE_CLOSE);
double EMA501 = iMA(_Symbol,PERIOD_D1,50,1,MODE_EMA,PRICE_CLOSE);

  The interresting thing,

 

EMA500 result is 10

EMA501 result is 11

 

does anyone have an idea whats wrong?

 

amando 

Alain Verleyen
Moderator
32406
Alain Verleyen  

Did you try to read the documentation ?

Returned value

Returns the handle of a specified technical indicator,  in case of failure returns INVALID_HANDLE. The computer memory can be freed from an indicator that is no more utilized, using the IndicatorRelease() function, to which the indicator handle is passed.

See this article https://www.mql5.com/en/articles/31

MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors
  • 2010.03.18
  • Sergey Pavlov
  • www.mql5.com
In order to obtain values of a built-in or custom indicator in an Expert Advisor, first its handle should be created using the corresponding function. Examples in the article show how to use this or that technical indicator while creating your own programs. The article describes indicators that are built n the MQL5 language. It is intended for those who don't have much experience in the development of trading strategies and offers simple and clear ways of working with indicators using the offered library of functions.
amando
434
amando  

what does this means exactly?

im not a professional coder

 

how i get right values for iMA? in general i see its an integer, so i cant get double values.

 

but how i can handle the function right?

 

amando 

amando
434
amando  

when i want to use this code from the MovingAvarege.mqh

 

double ExponentialMA(const int position,const int period,const double prev_value,const double &price[])
  {
//---
   double result=0.0;
//--- calculate value
   if(period>0)
     {
      double pr=2.0/(period+1.0);
      result=price[position]*pr+prev_value*(1-pr);
     }
//---
   return(result);
  }

 

what its meaning with

const int position: ??

const int period: is this Period_D1 and others ???

const double prev_value: ??

const double &price[]: is this PRICE_CLOSE ???? 

To add comments, please log in or register