error:" 'iMA' - wrong parameters count " in my expert for two moving average

To add comments, please log in or register
ramin Beygi
58
ramin Beygi  

hi.

I have error in my expert.

you can find my codes and errors in below. please advice me.

thanks.

//+------------------------------------------------------------------+
//|                                                      crossma.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

extern int MAFastPeriod=10;            //Fast moving average period
extern int MASlowPeriod=25;            //Slow moving average period



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
double SlowMovingAverage = iMA(Symbol(),0,MASlowPeriod,0,MODE_SMA,PRICE_CLOSE,0);
double LastSlowMovingAverage = iMA(Symbol(),0,MASlowPeriod,0,MODE_SMA,PRICE_CLOSE,1);
double FastMovingAverage = iMA(Symbol(),0,MAFastPeriod,0,MODE_SMA,PRICE_CLOSE,0);
double LastFastMovingAverage = iMA(Symbol(),0,MAFastPeriod,0,MODE_SMA,PRICE_CLOSE,1);  
if ((LastFastMovingAverage < LastSlowMovingAverage) && (FastMovingAverage > SlowMovingAverage))
Comment ("BUY"); 

if ((LastFastMovingAverage > LastSlowMovingAverage) && (FastMovingAverage < SlowMovingAverage))
Comment ("SELL"); 
  }
//+------------------------------------------------------------------+

my errors is in attachment.

Files:
errors.jpg 60 kb
William Roeder
22675
William Roeder  
Your code
 Documentation
double SlowMovingAverage = iMA(
Symbol(),
0,
MASlowPeriod,
0,
MODE_SMA,
PRICE_CLOSE,
0                         
);
int  iMA(
   string               symbol,            // symbol name
   ENUM_TIMEFRAMES      period,            // period
   int                  ma_period,         // averaging period
   int                  ma_shift,          // horizontal shift
   ENUM_MA_METHOD       ma_method,         // smoothing type
   ENUM_APPLIED_PRICE   applied_price      // type of price or handle
                                           
   );
Perhaps you should read the manual, especially the examples. They all returns a handle. 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

Creating an iMA indicator handle, getting indicator values.
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08

Also see my example for encapsulating calls
          Detailed explanation of iCustom - MQL4 programming forum

Vladimir Karputov
Moderator
206919
Vladimir Karputov  
ramin Beygi :

hi.

I have error in my expert.

you can find my codes and errors in below. please advice me.

thanks.

my errors is in attachment.

In MQL5, the handle of the indicator is received ONE time (in OnInit) and then used CopyBuffer (to receive data from the indicator). Example:

Creating an iMA indicator handle, getting indicator values

How to start with MQL5
How to start with MQL5
  • 2020.03.05
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
ramin Beygi
58
ramin Beygi  
William Roeder:
Your code
 Documentation
Perhaps you should read the manual, especially the examples. They all returns a handle. 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

Creating an iMA indicator handle, getting indicator values.
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08

Also see my example for encapsulating calls
          Detailed explanation of iCustom - MQL4 programming forum

hi.

I followed this link in youtube. please see it.

https://www.youtube.com/watch?v=qQ6H_WmkJmk

MQL4 Tutorial - Simple Moving Average Crossover Expert Advisor
MQL4 Tutorial - Simple Moving Average Crossover Expert Advisor
  • www.youtube.com
https://mql4tutorial.com With MQL4 for Metatrader you can program a Simple Moving Average Crossover Expert Advisor for automated trading. With a few lines of...
ramin Beygi
58
ramin Beygi  
Vladimir Karputov:

In MQL5, the handle of the indicator is received ONE time (in OnInit) and then used CopyBuffer (to receive data from the indicator). Example:

Creating an iMA indicator handle, getting indicator values

hi.

I followed this link in youtube. please see it.

https://www.youtube.com/watch?v=qQ6H_WmkJmk

MQL4 Tutorial - Simple Moving Average Crossover Expert Advisor
MQL4 Tutorial - Simple Moving Average Crossover Expert Advisor
  • www.youtube.com
https://mql4tutorial.com With MQL4 for Metatrader you can program a Simple Moving Average Crossover Expert Advisor for automated trading. With a few lines of...
Vladimir Karputov
Moderator
206919
Vladimir Karputov  
ramin Beygi :

hi.

I followed this link in youtube. please see it.

https://www.youtube.com/watch?v=qQ6H_WmkJmk

I showed you how to create an indicator in MQL5. But you can continue to make a mistake and continue to watch video in MQL4.

Kourosh Davallou
67035
Kourosh Davallou  
ramin Beygi:

hi.

I have error in my expert.

you can find my codes and errors in below. please advice me.

thanks.

my errors is in attachment.


double SlowMovingAverage = iMA(Symbol(),0,MASlowPeriod,0,MODE_SMA,PRICE_CLOSE);
double LastSlowMovingAverage = iMA(Symbol(),0,MASlowPeriod,0,MODE_SMA,PRICE_CLOSE);
double FastMovingAverage = iMA(Symbol(),0,MAFastPeriod,1,MODE_SMA,PRICE_CLOSE);
double LastFastMovingAverage = iMA(Symbol(),0,MAFastPeriod,1,MODE_SMA,PRICE_CLOSE);  
William Roeder
22675
William Roeder  
iMA does not return a double. #1
ramin Beygi
58
ramin Beygi  
Vladimir Karputov:

I showed you how to create an indicator in MQL5. But you can continue to make a mistake and continue to watch video in MQL4.

your right.

thanks.

can you advice me how can I find Slope of line for moving average curve.

my strategy is : when Slope of line of moving average curve change from negative to positive, this is a buy or sell time. 

William Roeder
22675
William Roeder  

Slope = Δ Price × Δ Time

Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum

To add comments, please log in or register