Download MetaTrader 5

EA code not compiling

To add comments, please log in or register
ITM7
57
ITM7  

Hi there everyone

I am a total newbie to trading and coding, I tried coding a simple EA to test a strategy I had in mind but the code is not being compiled. The first error(s) which I think are the main problem 
 is as follows:"  ' iMA ' - constant expected " which repeats for the three instances I have a similar code intended to capture the value of a moving average. 

The code of the EA is attached (I removed some default comments to make the code as short as possible)

Any help or suggestion and advice will be highly appreciated

#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern double ema_red = iMA(NULL, 0, 6, 0, MODE_EMA, PRICE_CLOSE, 0);
extern double ema_purple = iMA(NULL, 0, 30, 0, MODE_EMA, PRICE_CLOSE, 0);
extern double ema_blue = iMA(NULL, 0, 8, 1, MODE_EMA, PRICE_CLOSE, 0);


int PipsToPointFactor()  //NOT MY OWN FUNCTION, takes care of pips to points issue
  {
   int point;

   if(Digits==5 || Digits==3) //Check whether it's a 5 digit broker (3 digits for Yen)
   point=10; //1 pip to 10 point if 5 digit
   
   else if(Digits==4 || Digits==2)
   point=1; //1 pip to 1 point if 4 digit

   return(point);
  }


int OnInit()
  {
//---  
//---
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
//---
   
  }

void OnTick()
  {
     if (OrdersTotal()<=21)
       {   
          if (ema_red == ema_purple)&&(ema_red > ema_blue) // check when the ea's cross/meet
            Buy_Order();
         
          if (ema_red == ema_purple)&&(ema_red < ema_blue) // check when the ea's cross/meet
            Sell_Order();                                
                                                          
       }
  }
    
        void Buy_Order()
          { 
             double TP = Ask +(PipsToPointFactor()*15);
             double SL = (MarketInfo(Symbol(),MODE_TICKVALUE)) - (PipsToPointFactor()*5);
             OrderSend(Symbol(),OP_BUY,0.6,Ask,(3*PipsToPointFactor()),SL,TP,"",0,0,Green);  
          }
   
        void Sell_Order()
          {  
             double TP = (Bid - (15*PipsToPointFactor()));
             double SL = ((MarketInfo(Symbol(),MODE_TICKVALUE)) + (PipsToPointFactor()*5 );
             OrderSend(Symbol(),OP_SELL,0.6,Bid,(3*PipsToPointFactor()),SL,TP,"",0,0,Red); 
          }
Roberto Jacobs
48878
Roberto Jacobs  
ITM7:

Hi there everyone

I am a total newbie to trading and coding, I tried coding a simple EA to test a strategy I had in mind but the code is not being compiled. The first error(s) which I think are the main problem 
 is as follows:"  ' iMA ' - constant expected " which repeats for the three instances I have a similar code intended to capture the value of a moving average. 

The code of the EA is attached (I removed some default comments to make the code as short as possible)

Any help or suggestion and advice will be highly appreciated

#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//extern double ema_red = iMA(NULL, 0, 6, 0, MODE_EMA, PRICE_CLOSE, 0);
//extern double ema_purple = iMA(NULL, 0, 30, 0, MODE_EMA, PRICE_CLOSE, 0);
//extern double ema_blue = iMA(NULL, 0, 8, 1, MODE_EMA, PRICE_CLOSE, 0);

int point;


int OnInit()
  {
//---  
//---
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
//---
   
  }

int PipsToPointFactor()  //NOT MY OWN FUNCTION, takes care of pips to points issue
  {
   //int point;

   if(Digits==5 || Digits==3) //Check whether it's a 5 digit broker (3 digits for Yen)
   point=10; //1 pip to 10 point if 5 digit
   
   else if(Digits==4 || Digits==2)
   point=1; //1 pip to 1 point if 4 digit

   return(point);
  }


void OnTick()
  {

     double ema_red = iMA(NULL, 0, 6, 0, MODE_EMA, PRICE_CLOSE, 0);
     double ema_purple = iMA(NULL, 0, 30, 0, MODE_EMA, PRICE_CLOSE, 0);
     double ema_blue = iMA(NULL, 0, 8, 1, MODE_EMA, PRICE_CLOSE, 0);

     if (OrdersTotal()<=21)
       {   
          if (ema_red == ema_purple)&&(ema_red > ema_blue) // check when the ea's cross/meet
            Buy_Order();
         
          if (ema_red == ema_purple)&&(ema_red < ema_blue) // check when the ea's cross/meet
            Sell_Order();                                
                                                          
       }
  }
    
        void Buy_Order()
          { 
             double TP = Ask +(PipsToPointFactor()*15);
             double SL = (MarketInfo(Symbol(),MODE_TICKVALUE)) - (PipsToPointFactor()*5);
             OrderSend(Symbol(),OP_BUY,0.6,Ask,(3*PipsToPointFactor()),SL,TP,"",0,0,Green);  
          }
   
        void Sell_Order()
          {  
             double TP = (Bid - (15*PipsToPointFactor()));
             double SL = ((MarketInfo(Symbol(),MODE_TICKVALUE)) + (PipsToPointFactor()*5 );
             OrderSend(Symbol(),OP_SELL,0.6,Bid,(3*PipsToPointFactor()),SL,TP,"",0,0,Red); 
          }
ITM7
57
ITM7  
Roberto Jacobs:


Thank you very much for your time, I tried re positioning the moving averages to that place before but still getting errors. I tried copying the whole code into meta editor incase 
  i had missed any corrections that you have made but its still not compiling, the first and second error is below, of which i think the first is the main problem but i still can't figure it out

first error: " ' && ' - operand expected "
second error: " ' Buy_Order  ' - some operator expected  "

honest_knave
Moderator
2293
honest_knave  
ITM7:


Thank you very much for your time, I tried re positioning the moving averages to that place before but still getting errors. I tried copying the whole code into meta editor incase 
  i had missed any corrections that you have made but its still not compiling, the first and second error is below, of which i think the first is the main problem but i still can't figure it out

first error: " ' && ' - operand expected "
second error: " ' Buy_Order  ' - some operator expected  "


You need to change this:

          if (ema_red == ema_purple)&&(ema_red > ema_blue) // check when the ea's cross/meet
            Buy_Order();
         
          if (ema_red == ema_purple)&&(ema_red < ema_blue) // check when the ea's cross/meet
            Sell_Order();  

To this:

          if (ema_red == ema_purple && ema_red > ema_blue) // check when the ea's cross/meet
            Buy_Order();
         
          if (ema_red == ema_purple && ema_red < ema_blue) // check when the ea's cross/meet
            Sell_Order();  


You'll also have some warnings about OrderSend return value should be checked. It's a warning, so you don't have to deal with it. But it is better to know why an OrderSend failed rather than guessing:

        void Buy_Order()
          { 
             double TP = Ask +(PipsToPointFactor()*15);
             double SL = (MarketInfo(Symbol(),MODE_TICKVALUE)) - (PipsToPointFactor()*5);
             if(!OrderSend(Symbol(),OP_BUY,0.6,Ask,(3*PipsToPointFactor()),SL,TP,"",0,0,Green))
               Print("OrderSend() failed - ",GetLastError()); 

          }
   
        void Sell_Order()
          {  
             double TP = (Bid - (15*PipsToPointFactor()));
             double SL = (MarketInfo(Symbol(),MODE_TICKVALUE)) + (PipsToPointFactor()*5 );
             if(!OrderSend(Symbol(),OP_SELL,0.6,Bid,(3*PipsToPointFactor()),SL,TP,"",0,0,Red))
               Print("OrderSend() failed - ",GetLastError()); 
          }
Keith Watford
Moderator
10541
Keith Watford  
ITM7:

Hi there everyone

I am a total newbie to trading and coding, I tried coding a simple EA to test a strategy I had in mind but the code is not being compiled. The first error(s) which I think are the main problem 
 is as follows:"  ' iMA ' - constant expected " which repeats for the three instances I have a similar code intended to capture the value of a moving average. 

The code of the EA is attached (I removed some default comments to make the code as short as possible)

Any help or suggestion and advice will be highly appreciated


Please do not double post.

I have deleted your post in the other thread.

ITM7
57
ITM7  
honest_knave:


You need to change this:

To this:


You'll also have some warnings about OrderSend return value should be checked. It's a warning, so you don't have to deal with it. But it is better to know why an OrderSend failed rather than guessing:


Thank you very much for the correction, it finally compiled without any errors
ITM7
57
ITM7  
Keith Watford:


Please do not double post.

I have deleted your post in the other thread.


My bad for double posting, I thought that post wouldn't get seen for me to get any help because of the time difference, and it being my first post, I didn't know where to start looking for help. 

Advice gladly taken

To add comments, please log in or register