EA error

 

Hello,


I'm trying to code an EA and everytime I compile it gives me 1 error message, PLEASE HELP ME ...


void OnTick()

  {

//---


   double movingAverage = iMA(NULL,0,9,0,MODE_EMA,PRICE_MEDIAN,0);

   double currentPrice = Open[0];

   double lastPrice = Open[1];

   

     if { (currentPrice > movingAverage) && (currentPrice < lastPrice) } {

      // Sell

      order = OrderSend(NULL,OP_SELL,0.10,currentPrice,0,NULL,NULL,NULL,0,0,NULL);

    

   } else if { (currentPrice < movingAverage) && (currentPrice > lastPrice) } {

      // Buy

      order = OrderSend(NULL,OP_BUY,0.10,currentPrice,0,NULL,NULL,NULL,0,0,NULL);

   }

      

   Alert("Last Price: "+lastPrice+" Current Price: "+currentPrice);

  }

 

So what is the error?

 
Marco vd Heijden:

So what is the error?


'if' - open parenthesis expected



 
void OnTick()

  {

//---


   double movingAverage = iMA(NULL,0,9,0,MODE_EMA,PRICE_MEDIAN,0);

   double currentPrice = Open[0];

   double lastPrice = Open[1];

   

     if { (currentPrice > movingAverage) && (currentPrice < lastPrice) } {

      // Sell

      order = OrderSend(NULL,OP_SELL,0.10,currentPrice,0,NULL,NULL,NULL,0,0,NULL);

    

   } else if { (currentPrice < movingAverage) && (currentPrice > lastPrice) } {

      // Buy

      order = OrderSend(NULL,OP_BUY,0.10,currentPrice,0,NULL,NULL,NULL,0,0,NULL);

   }

      

   Alert("Last Price: "+lastPrice+" Current Price: "+currentPrice);

  }
Maybe these guy's...
 
    if { (currentPrice > movingAverage) && (currentPrice < lastPrice) } {

      // Sell

      order = OrderSend(NULL,OP_SELL,0.10,currentPrice,0,NULL,NULL,NULL,0,0,NULL);

    

   } else if { (currentPrice < movingAverage) && (currentPrice > lastPrice) } {
Those are not parentheses. Perhaps you should read the manual.
          Language Basics / Operators / Conditional Operator if-else - Reference on algorithmic/automated trading language for MetaTrader 5
 
Marco vd Heijden:
Maybe these guy's...

Should i try removing them ?

 
whroeder1:
Those are not parentheses. Perhaps you should read the manual.
          Language Basics / Oper
ators / Conditional Operator if-else - Reference on algorithmic/automated trading language for MetaTrader 5

What should I do ?

 
2100111702:

What should I do ?


Read the link whroeder1 gave you, The answer is there!



 
2100111702:

Should i try removing them ?

It never hurt's to try ...