Help Needed with iMA Function Parameter Error in MQL5

 

Hello everyone,

I am currently developing a custom indicator in MQL5 which utilizes multiple Exponential Moving Averages (EMAs). However, I am encountering a parameter count error with the iMA function and need some assistance in resolving it. 

The code is intended to calculate four EMAs (5, 10, 20, and 60 periods) and check certain conditions to generate signals. However, when I attempt to compile the script, I receive the following error:

Here is the code:

ema5[i] = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, i);

ema10[i] = iMA(NULL, 0, 10, 0, MODE_EMA, PRICE_CLOSE, i);

ema20[i] = iMA(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, i);

ema60[i] = iMA(NULL, 0, 60, 0, MODE_EMA, PRICE_CLOSE, i);


Error (All 4 EMA facing same error):

'iMA' - wrong parameters count

   built-in: int iMA(const string,ENUM_TIMEFRAMES,int,int,ENUM_MA_METHOD,int)


I have tried adjusting the parameters to match the iMA function signature but the error persists. I would appreciate it if someone could help me identify what I am doing wrong or suggest how I might correctly use the iMA function to avoid this error.

Thank you in advance for the help!

Custom Indicators in MQL5 for Newbies
Custom Indicators in MQL5 for Newbies
  • www.mql5.com
Any new subject seems complicated and hard-to-learn for a newbie. Subjects that we know seem very simple and clear to us. But we simply do not remember, that everyone has to study something from scratch, and even our native language. The same is with the MQL5 programming language that offers wide possibilities of developing one's own trading strategies - you can start learning it from basic notions and simplest examples. Interaction of a technical indicator with the MetaTrader 5 client terminal is consider in this article on the example of the simple custom indicator SMA.
 
Streak Winner:

Hello everyone,

I am currently developing a custom indicator in MQL5 which utilizes multiple Exponential Moving Averages (EMAs). However, I am encountering a parameter count error with the iMA function and need some assistance in resolving it. 

The code is intended to calculate four EMAs (5, 10, 20, and 60 periods) and check certain conditions to generate signals. However, when I attempt to compile the script, I receive the following error:

Here is the code:

ema5[i] = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, i);

ema10[i] = iMA(NULL, 0, 10, 0, MODE_EMA, PRICE_CLOSE, i);

ema20[i] = iMA(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, i);

ema60[i] = iMA(NULL, 0, 60, 0, MODE_EMA, PRICE_CLOSE, i);


Error (All 4 EMA facing same error):

'iMA' - wrong parameters count

   built-in: int iMA(const string,ENUM_TIMEFRAMES,int,int,ENUM_MA_METHOD,int)


I have tried adjusting the parameters to match the iMA function signature but the error persists. I would appreciate it if someone could help me identify what I am doing wrong or suggest how I might correctly use the iMA function to avoid this error.

Thank you in advance for the help!

Are you an MQL5/MQL4 programmer?
 
Flavio Javier Jarabeck #:
Are you an MQL5/MQL4 programmer?

Hi, I'm just the beginner of coding MQL5 (never did on MQL4), that's why I am here to seek for help. Thanks

 
Streak Winner #:

Hi, I'm just the beginner of coding MQL5 (never did on MQL4), that's why I am here to seek for help. Thanks

Then you need to read the mql5 documentation.  First you create a handle to work with an indicator then you use copybuffer to get values from it
 

Create handles of indicators into OnInit using iMA commands.

Use CopyBuffer to update your indicator buffers using iMA values.

You will find a lot of examples into CodeBase

MQL5 Code Base
MQL5 Code Base
  • www.mql5.com
MQL5 Source Code Library for MetaTrader 5
 
ema5[i] = iMA(NULL, 0, 5, 0, MODE_EMA, PRICE_CLOSE, i);

ema10[i] = iMA(NULL, 0, 10, 0, MODE_EMA, PRICE_CLOSE, i);

ema20[i] = iMA(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, i);

ema60[i] = iMA(NULL, 0, 60, 0, MODE_EMA, PRICE_CLOSE, i);
Those are MT4 calls.

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)

 

Thanks guys for providing all the informative suggestions, currently I have solved the error. Thank you so much

.

 
Streak Winner #: , currently I have solved the error.

Don't do that. Someone searching might find this thread and still be clueless. What was the problem? What solved what?
     How To Ask Questions The Smart Way. (2004)
       When You Ask.
          Follow up with a brief note on the solution.

 

Why don't you guys post in the correct place?

https://www.mql5.com/en/forum/indicators

MQL5 forum: Technical Indicators
MQL5 forum: Technical Indicators
  • www.mql5.com
Questions about the development of technical indicators in the MQL5 language
 
Conor Mcnamara #:

Why don't you guys post in the correct place?

https://www.mql5.com/en/forum/indicators

I'm having the same error. how do i solve it please!!?