Unbalanced Left parenthesis

 

Hey guys! I'm very new to writing EA and just trying to learn the basic of it by making a simple moving average cross over + RSI + trailing stop loss EA. My code is as below but I can't find any reason why it keeps saying unbalanced left parenthesis. I even check every single parenthesis with the "find" button on it and still can't find it. Here's the code below.. If anyone can help me with this, I'll certainly appreciate it!


//===========================================================================

#property copyright "Iducate Learning Technologies"
#property link "http://www.metaquotes.net"

//---------------------------------------------------------------------

static int lastDirection = 0;
extern double TakeProfit=20.0;
extern double Lots=0.1;
extern double StopLoss=10.0;
extern double TrailingStop = 30;

//---------------------------------------------------------------------

int init(){

return(0);
}

//===========================================================================

int deinit(){
return(0);
}

//===========================================================================

int start(){




//Setting all the Variables ---------------------------------------------

double shortEma, longEma, WeekEMA, RSI;
int currentDirection = 0;

shortEma = iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0);
longEma = iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0);

WeekEMA = iMA(NULL,PERIOD_W1,20,0,MODE_EMA,PRICE_CLOSE,0);

RSI = iRSI(NULL,0,14,PRICE_CLOSE,0);

//- - - - - - - - - - - - - - - - - - - - - - separator

// Defining uptrend and downtrend from Variables above

if(shortEma > longEma)
currentDirection = 1; // up trend
else
currentDirection = 2; // down trend

//-----------------------------------------------------------------------






//[][][][][][][][] The actual function part of the Program [][][][][][][][][]

// If there's crossover do this
if(lastDirection != currentDirection){ //"if crossover" start
//+++++++++++++++++++++++++++++++++++
if (currentDirection == 1 && RSI > 70 && WeekEMA > Ask+30*Point) { // If there's crossover and it's up trend, then do this:

Print("Cross over up, man!");

// Buying command----
int ticketNo = 0;
ticketNo = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,(Ask+TakeProfit*Point),"My EA",12345,0,Green);
if(ticketNo<0){ //checks for error on ordering
Print("OrderSend failed with error #",GetLastError());
return(0);
}
// End of buying command----

} // if cross and uptrend sub-function ends
//++++++++++++++++++++++++++++++++++
if (currentDirection == 2 && RSI < 30 && WeekEMA > Bid-30*Point) { // If there's crossover and it's down trend, then do this:

Print("Cross over down, bro!");

// Selling command----
ticketNo = OrderSend(Symbol(),OP_BUY,Lots,Bid,3,0,(Bid-TakeProfit*Point),"My EA",12345,0,Green);
if(ticketNo<0){ //checks for error on ordering
Print("OrderSend failed with error #",GetLastError());
return(0);
}
// End of selling command----

}// if cross and downtrend sub-function ends
//++++++++++++++++++++++++++++++++++
} //"if crossover" ends

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - separator
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - separator

// Closing orders and stop loss

int totalOrdersOpened = 0;
totalOrdersOpened = OrdersTotal();

//++++++++++++++++++++++++++++++++++

if(totalOrdersOpened >= 1){ //if there is an order,

for(int count = 0;count < totalOrdersOpened;count++){ //for each order, count it
OrderSelect(count,SELECT_BY_POS,MODE_TRADES); //and then, select the order

//++++++++++++++++++++++++++++++++++

if(
OrderType() == OP_BUY
&& currentDirection == 2
&& TrailingStop>0
&& (Bid-OrderOpenPrice()>Point*TrailingStop)
&& (OrderStopLoss()<Bid-Point*TrailingStop)
)

{ //select the order, and if buy and MA crosses in opposite direction
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
} //"select, if buy and MA crosses" end

//++++++++++++++++++++++++++++++++++

else if (
OrderType() == OP_SELL
&& currentDirection == 1
&& TrailingStop>0
&& ((OrderOpenPrice()-Ask)>(Point*TrailingStop))
&& ((OrderStopLoss()>(Ask+Point*TrailingStop))
)

{ //select the order, and if sell and MA crosses in opposite direction
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
} //"select, if sell and MA crosses" end

//++++++++++++++++++++++++++++++++++

} //"for each order" end
} //"if there's an order" end

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - separator
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - separator

//If there isn't, then do this

else{
double gap = shortEma - longEma;
Print("shortEma = "+shortEma+" longEma = "+longEma+" Gap” + “ = " + gap);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - separator
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - separator

lastDirection = currentDirection; // Set the current direction as last direction for next start() cycle

//[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]







return(0);
}



//========================================================
 
Malv85:

Hey guys! I'm very new to writing EA and just trying to learn the basic of it by making a simple moving average cross over + RSI + trailing stop loss EA. My code is as below but I can't find any reason why it keeps saying unbalanced left parenthesis. I even check every single parenthesis with the "find" button on it and still can't find it. Here's the code below.. If anyone can help me with this, I'll certainly appreciate it!

<CODE REMOVED>

Please read some other posts before posting . . .

Please edit your post . . . please use the SRC button to post code: How to use the SRC button.

 
Malv85:

Hey guys! I'm very new to writing EA and just trying to learn the basic of it by making a simple moving average cross over + RSI + trailing stop loss EA. My code is as below but I can't find any reason why it keeps saying unbalanced left parenthesis. I even check every single parenthesis with the "find" button on it and still can't find it. Here's the code below.. If anyone can help me with this, I'll certainly appreciate it!


Looks like it's here . . .

else if (
OrderType() == OP_SELL 
&& currentDirection == 1 
&& TrailingStop>0 
&& ( ( OrderOpenPrice()-Ask ) > ( Point*TrailingStop ) )
&& (  (  OrderStopLoss() > ( Ask+Point*TrailingStop ) )

. . . adding spaces helps to make things clearer.

 
RaptorUK:

Looks like it's here . . .

. . . adding spaces helps to make things clearer.


Hey thanks so much for that! adding spaces! why didn't I think of that. That's brilliant!
 
Malv85:

Hey thanks so much for that! adding spaces! why didn't I think of that. That's brilliant!

Can you now edit your first post please . . .

 
How did you find that so quickly? did you come across a lot of this problem before?
 
Malv85:
How did you find that so quickly? did you come across a lot of this problem before?

Thank you for editing . . .

Yes, it's a reasonably frequent question on this forum, with practice you get to know what to look for. You can also pull the code into the MT5 MetaEditor and it will show matching braces . . . it can help find issues faster.

( ) braces are easier to find than { } braces, consistent indenting style helps with { } braces.

Reason: