New to mql4 programming and in need of some advice please!

Hey, I’m very new to new to the forex world and also very new to programming, so I hope you will go easy on me.

I am following an mql4 tutorial and have written code for a very basic system which places buy and sell orders on a fast and slow EMA crossover basis. However, my code seems to an error saying “unbalance left parentheses”. After 2 days of going through the code with a fine comb, taking parts out to try and isolate the problem, and researching it I am still at a dead end. And as I am completely new to forums I’m not sure weather or not I’m meant to attach the code however I will anyway because I would LOVE some help.

Thankyou so much for taking the time!

extern int TakeProfit=300;
extern int StopLoss=100;
extern bool UseMoveToBreakEven=true;
extern int WhenToMoveBE=100;
extern int PipsToLockIn=5;

extern int FastMa = 5; //applied over 5 periods
extern int FastMaShift = 0; // not shifted
extern int FastMaMethod = 1; //Exponential Moving average
extern int FastMaAppliedTo = 0 ;//set to the close

extern int SlowMa=20;
extern int SlowMaShift=0;
extern int SlowMaMethod=1;
extern int SlowMaAppliedTo=0;

extern int MagicNumber=1234;
extern double LotSize=0.1;
double pips;

//±-----------------------------------------------------------------+
//| expert initialization function |
//±-----------------------------------------------------------------+
int init()
{
//----
double ticksize = MarketInfo(Symbol(), MODE_TICKSIZE); //allow it to self adjust “pip” size
if (ticksize == 0.00001 || ticksize == 0.001)
pips = ticksize*10;
else pips =ticksize;
//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert start function |
//±-----------------------------------------------------------------+
int start()
{
//----
if(UseMoveToBreakEven)MoveToBreakEven();
if(IsNewCandle()==true)CheckForMaTrade();
//----
return(0);
}
//±-----------------------------------------------------------------+

void MoveToBreakEven()
{
for(int b=OrdersTotal()-1; b >= 0; b–)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()==MagicNumber)
if(OrderSymbol()==Symbol()
if(OrderType()==OP_BUY)
if(Bid-OrderOpenPrice()>WhenToMoveBEpips)
if(OrderOpenPrice()>OrderStopLoss())
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(PipsToLockIn
pips),OrderTakeProfit(),0,CLR_NONE);
}
for(int s=OrdersTotal()-1; s>= 0; s–)
{
if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()==MagicNumber)
if OrderSymbol()==Symbol()
if(OrderType()==OP_SELL)
if(OrderOpenPrice()-Ask>WhenToMoveBEpips)
if(OrderOpenPrice()<OrderStopLoss())
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(PipsToLockIn
pips),OrderTakeProfit(),0,CLR_NONE);
}
}

bool IsNewCandle() // Recognises whether new candle has been formed.
{
static int BarsOnChart=0; //static integar only initialises once.
if (Bars == BarsOnChart)
return (false);
BarsOnChart = Bars;
return(true);
}

void CheckForMaTrade()
{
double PreviousFast = iMA(NULL,0,FastMa,FastMaShift,FastMaMethod,FastMaAppliedTo,2);
double CurrentFast = iMA(NULL,0,FastMa,FastMaShift,FastMaMethod,FastMaAppliedTo,1);
double PreviousSlow = iMA(NULL,0,SlowMa,SlowMaShift,SlowMaMethod,SlowMaAppliedTo,2);
double CurrentSlow = iMA(NULL,0,SlowMa,SlowMaShift,SlowMaMethod,SlowMaAppliedTo,1);
if(PreviousFast<PreviousSlow && CurrentFast>CurrentSlow)OrderEntry(0);
if(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)OrderEntry(1);
}

void OrderEntry (int direction)
{
if(direction==0)
if(OrdersTotal(Symbol()) <=3) // if(OrdersTotal()==0)
OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-(StopLosspips),Ask+(TakeProfitpips),“DailyMovingAverageEA has placed BUY trade”,0,0,Green);
if(direction==1)
if(OrdersTotal(Symbol()) <=3) // if(OrdersTotal()==0)
OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,Bid+(StopLosspips),Bid-(TakeProfitpips),“DailyMovingAverageEA has placed SELL trade”,0,0,Red);
}

two lines of code under “void MoveToBreakEven()”

with

if (OrderSymbol()==Symbol() )

error.

Thanks a lot for taking the time. really appreciate it. however another line of code seems to not be working. " if(OrdersTotal(Symbol()) <= 3) " isn’t being read properly. Im not sure how to determine the current and pending orders for a specific currency pair. Can the OrdersTotal() function have parameters?

OrdersTotal() doesnt allow inputs.

The surest way to check total orders for the current symbol is to :

CurrentOrders = 0;
for ( int a = OrdersTotal(); a>=0; a-- )
{
if ( OrderSelect(a; SELECT_BY_POS; MODE_TRADES) )
{
if ( OrderSymbol() == Symbol() )
{
CurrentOrders++;
}
}
}

However, running thru this at every tick is going to cost you valuable CPU resources. It is better to trigger the function if there is a change in orders. For example:

  1. at restart of the program.
  2. at every new order.
  3. at every closure of order.

Hope this helps!

Huge help, thanks!

So that worked perfectly, however my break even function hasn’t been executing! Are you able to help me with this aswell? Hope these questions aren’t too elementary and if there is any good sources for mql4 support? Appreciate your help.

I dont see anything wrong with the logic or syntax for that function, except for the first post that i have mentioned. mql4 forum or TSD should have more “help” with mql4 programming. But nothing beats tearing your hair out by yourself.