EA error

To add comments, please log in or register
2100111702
40
2100111702  

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);

  }

Marco vd Heijden
Moderator
8178
Marco vd Heijden  

So what is the error?

2100111702
40
2100111702  
Marco vd Heijden:

So what is the error?


'if' - open parenthesis expected



Marco vd Heijden
Moderator
8178
Marco vd Heijden  
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...
whroeder1
17942
whroeder1  
    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
2100111702
40
2100111702  
Marco vd Heijden:
Maybe these guy's...

Should i try removing them ?

2100111702
40
2100111702  
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 ?

Enrique Dangeroux
410
Enrique Dangeroux  
2100111702:

What should I do ?


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



Marco vd Heijden
Moderator
8178
Marco vd Heijden  
2100111702:

Should i try removing them ?

It never hurt's to try ...

To add comments, please log in or register