'else' - illegal 'else' without matching 'if'

 
if( (MovingAverage1[0]>MovingAverage2[0]) && (MovingAverage1[1]<MovingAverage2[1]) )
if (PositionsTotal()==0)
{  
OrderSend(request,result);

else 

if (PositionsTotal()==1);

CloseAllOrders();
  }
 

Here is the code, i have this error message: "'else' - illegal 'else' without matching 'if' "

How can I fix it?

 

Good morning
This error message because you are missing a packet of {}

Learn to put them as soon as you write a code, because finding a { or } can be a real hassle!!!

 
Greg MK #:

Here is the code, i have this error message: "'else' - illegal 'else' without matching 'if' "

How can I fix it?

sort your brackets out...

if()
{
        code here
}
else if()
{
        code here
}
Greg MK
Greg MK
  • 2023.09.03
  • www.mql5.com
Trader's profile
 
Thank you it works.