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()+(PipsToLockInpips),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()-(PipsToLockInpips),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);
}