Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network. Improve your rating!
vivek visale
640
vivek visale 2014.02.15 19:52 

hi

first of all, thanks for reading this article,

this code i have taken from a mql5 EA, in this EA moving average indicator is used, and i am fascinated by its use,

i want to try it in mt4

input int MA_RED_PERIOD = 7; 

 input int MA_YEL_PERIOD = 14;
 int ma_red_handle, ma_yel_handle, macd_handle;
 double MA_RED[], MA_YEL[], MACD[];

int OnInit()
  {
   ma_red_handle = iMA(NULL, 0, MA_RED_PERIOD, 0, MODE_EMA, PRICE_CLOSE);
   ma_yel_handle = iMA(NULL, 0, MA_YEL_PERIOD, 0, MODE_EMA, PRICE_CLOSE);
   macd_handle = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE);
   
   return(0);
  }
void OnDeinit(const int reason)
  {
  }
void OnTick()
  {
   //---ïîëó÷àåì äàííûå îò èíäèêàòîðîâ---
   CopyBuffer(ma_red_handle, 0, 0, 4, MA_RED);
   CopyBuffer(ma_yel_handle, 0, 0, 4, MA_YEL);
   CopyBuffer(macd_handle, 0, 0, 4, MACD);
   ArraySetAsSeries(MA_RED, true);
   ArraySetAsSeries(MA_YEL, true);
   ArraySetAsSeries(MACD, true);


in the above code i know that 2 moving average and 1 macd indicators are being introduced, and as a c++ programmer i can understand most of it, but the part that i dont understand is below:
if(MA_RED[3] > MA_YEL[3] && MA_RED[1] < MA_YEL[1] && MA_RED[0] < MA_YEL[0] 
            && MACD[1] < 0)
can someone tell me how i can implement this above 1 line into mt4 ?
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.15 23:45  
visale:

hi

first of all, thanks for reading this article,

this code i have taken from a mql5 EA, in this EA moving average indicator is used, and i am fascinated by its use,

i want to try it in mt4


iMA() returns a double not an int . . . read the mql4 help in MetaEditor
vivek visale
640
vivek visale 2014.02.16 17:53  
raptorUK do you want to help ? or do mischief?
Ovo Cz
2955
Ovo Cz 2014.02.16 18:08  
iMA in MT4 is used directly, without a handle. Look into the help file.
whroeder1
13649
whroeder1 2014.02.16 18:13  
visale: raptorUK do you want to help ? or do mischief?
He is trying to help. I was going to say the same thing but didn't because I'm unsure if the mql5 version is valid in mql4.
https://docs.mql4.com​/indicators​/iMA
double iMA(string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)
Calculates the Moving average indicator and returns its value
https://www.mql5.com​/en/docs​/indicators​/ima
int iMA( string symbol, ENUM_TIMEFRAMES period, int ma_period, int ma_shift, ENUM_MA_METHOD ma_method, ENUM_APPLIED_PRICE applied_price);
The function returns the handle of the Moving Average indicator.
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.16 18:30  
visale:
raptorUK do you want to help ? or do mischief?

Next time I see you ask for help I won't bother . . . but for now . . .

From build 610 help file . . .

MQL4 Reference / Technical Indicators / iMA

iMA

Calculates the Moving Average indicator and returns its value.

double iMA(
string symbol, // symbol
int timeframe, // timeframe
int ma_period, // MA averaging period
int ma_shift, // MA shift
int ma_method, // averaging method
int applied_price, // applied price
int shift // shift
);

Parameters

symbol

[in] Symbol name on the data of which the indicator will be calculated. NULL means the current symbol.

timeframe

[in] Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.

ma_period

[in] Averaging period for calculation.

ma_shift

[in] MA shift. Indicators line offset relate to the chart by timeframe.

ma_method

[in] Moving Average method. It can be any of ENUM_MA_METHOD enumeration values.

applied_price

[in] Applied price. It can be any of ENUM_APPLIED_PRICE enumeration values.

shift

[in] Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Returned value

Numerical value of the Moving Average indicator.

Example:

AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);

vivek visale
640
vivek visale 2014.02.18 14:50  

hi

RaptorUK sorry for my mischief!

sorry i did not read the mt4 article as you said, but actually i know how to introduce the iMA moving average indicator in mql4, the real problem is that i have not understood the mql5 array codes, how to implement them in mql4, below are the codes

if(MA_RED[3] > MA_YEL[3] && MA_RED[1] < MA_YEL[1] && MA_RED[0] < MA_YEL[0] 
            && MACD[1] < 0)

only this above line i dont know how to make it work in mql4

hope i get help :)

whroeder1
13649
whroeder1 2014.02.18 15:06  
visale: only this above line i dont know how to make it work in mql4
if(MA_RED[3] > MA_YEL[3] && MA_RED[1] < MA_YEL[1] && MA_RED[0] < MA_YEL[0] 
            && MACD[1] < 0)
double MA_RED[4], MA_YEL[4], MACD[4]; // Arrays must have a size.
:
void OnTick(){
   for(int iBar=0; iBar <= 3; iBar++){
      MA_RED[iBar] = iMA(NULL, 0, MA_RED_PERIOD, 0, MODE_EMA, PRICE_CLOSE, iBar);
      MA_YEL[iBar] = iMA(NULL, 0, MA_YEL_PERIOD, 0, MODE_EMA, PRICE_CLOSE, iBar);
      MACD[iBar]   = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, iBar);
   }
   if(MA_RED[3] > MA_YEL[3] && MA_RED[1] < MA_YEL[1] && MA_RED[0] < MA_YEL[0] 
   && MACD[1] < 0)
vivek visale
640
vivek visale 2014.02.19 18:45  
thanks WHRoeder, will try it now and see
Ian Venner
2583
Ian Venner 2014.02.20 00:04  
RaptorUK:
iMA() returns a double not an int . . . read the mql4 help in MetaEditor

Looks to me like the integer ma_red_handle is a pointer, not related to the return value type of of the iMA. I am assuming ...while knowing very little about mql5 pointers/handles, perhaps it is supposed to be an integer ...

whroeder1
13649
whroeder1 2014.02.20 01:17  
SDC: Looks to me like the integer ma_red_handle is a pointer
Exactly true - that's mql5, fill an array using the handle. Thus the change to mql4, returns a double for a given shift:
MA_RED[iBar] = iMA(NULL, 0, MA_RED_PERIOD, 0, MODE_EMA, PRICE_CLOSE, iBar);
/
To add comments, please log in or register