Unexpected token error

 
//+------------------------------------------------------------------+
//|                                                        MAENA.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#include "D:\Metatrader 5\MQL5\Include\ExpertAdvisor.mqh"

input int    SL        =  50; // Stop Loss distance
input int    TP        = 100; // Take Profit distance
input int    TS        =  50; // Trailing Stop distance
input int    MAPer     =  12; // MA period
input int    LMAPer    =  40;
input double Risk      = 0.1; // Risk

//---
class CMyEA : public CExpertAdvisor
  {
protected:
   double            m_risk;          // size of risk
   int               m_sl;            // Stop Loss
   int               m_tp;            // Take Profit
   int               m_ts;            // Trailing Stop
   int               m_MAPer;         // MA period
   int               m_LMAPer         //Long moving average period
   int               m_hma;           // SMA indicator handle
   int               m_hlma;          // LMA indicator handle
public:
   void              CMyEA();
   void             ~CMyEA();
   virtual bool      Init(string smb,ENUM_TIMEFRAMES tf); // initialization
   virtual bool      Main();                              // main function
   virtual void      OpenPosition(long dir);              // open position on signal
   virtual void      ClosePosition(long dir);             // close position on signal
   virtual long      CheckSignal(bool bEntry);            // check signal
  };
//------------------------------------------------------------------    CMyEA
void CMyEA::CMyEA() { }
//------------------------------------------------------------------    ~CMyEA
void CMyEA::~CMyEA()
  {
   IndicatorRelease(m_hma);   // delete MA indicator
   IndicatorRelease(m_hlma);   // delete MA indicator
  
  }
//------------------------------------------------------------------    Init
bool CMyEA::Init(string smb,ENUM_TIMEFRAMES tf)
  {
   if(!CExpertAdvisor::Init(0,smb,tf)) return(false);                                // initialize parent class

   m_risk=Risk; m_tp=TP; m_sl=SL; m_ts=TS;                                           // copy parameters
   m_MAPer=MAPer;
   m_LMAPer=LMAPer;
  
   m_hma=iMA(m_smb,PERIOD_D1,m_MAPer,0,MODE_SMA,PRICE_CLOSE);      
   m_hlma=iMA(m_smb,PERIOD_D1,m_LMAPer,0,MODE_SMA,PRICE_CLOSE);                  // create MA indicator
  
   if(m_hma==INVALID_HANDLE  || m_hlma==INVALID_HANDLE) return(false);              // if there is an error, then exit
  
   m_bInit=true; return(true);                                                       // trade allowed
  }
//------------------------------------------------------------------    Main
bool CMyEA::Main() // main function
  {
   if(!CExpertAdvisor::Main()) return(false); // call function of parent class

   if(Bars(m_smb,m_tf)<=100) return(false);   // if there are insufficient number of bars

   if(!CheckNewBar()) return(true);           // check new bar

                                              // check each direction
   long dir;
   dir=ORDER_TYPE_BUY;
   OpenPosition(dir); ClosePosition(dir); TrailingPosition(dir,m_ts);
   dir=ORDER_TYPE_SELL;
   OpenPosition(dir); ClosePosition(dir); TrailingPosition(dir,m_ts);

   return(true);
  }
//------------------------------------------------------------------    OpenPos
void CMyEA::OpenPosition(long dir)
  {
// if there is an order, then exit
   if(PositionSelect(m_smb)) return;
// if there is no signal for current direction
   if(dir!=CheckSignal(true)) return;
   double lot=CountLotByRisk(m_sl,m_risk,0);
// if lot is not defined
   if(lot<=0) return;
// open position
   DealOpen(dir,lot,m_sl,m_tp);
  }
//------------------------------------------------------------------    ClosePos
void CMyEA::ClosePosition(long dir)
  {
// if there is no position, then exit
   if(!PositionSelect(m_smb)) return;
// if position of unchecked direction
   if(dir!=PositionGetInteger(POSITION_TYPE)) return;
// if the close signal didn't match the current position
   if(dir!=CheckSignal(false)) return;
// close position
   m_trade.PositionClose(m_smb,1);
  }
//------------------------------------------------------------------    CheckSignal
long CMyEA::CheckSignal(bool bEntry)
  {
   double ma[4],     // Array of MA indicator values
   double lma[4];
   
   MqlRates rt[3];   // Array of price values of last 3 bars
   
   if(CopyRates(m_smb,m_tf,0,3,rt)!=3) // Copy price values of last 3 bars to array
     { Print("CopyRates ",m_smb," history is not loaded"); return(WRONG_VALUE); }
   // Copy indicator values to array
   if(CopyBuffer(m_hma,0,0,4,ma)<4 || CopyBuffer(m_hlma,0,0,4,lma)<4)
     { Print("CopyBuffer - no data"); return(WRONG_VALUE); }
   // buy if the SMA crosses the LMA upwards and if the LMA trend is also upwards
   if(ma[1]<lma[1] &&  ma[2]>lma[2] && lma[1]<lma[2] &&  lma[2]<lma[3])
      return(bEntry ? ORDER_TYPE_BUY:ORDER_TYPE_SELL); // condition for buy
   // sell if the SMA crosses the LMA downwards and if the LMA trend is also downwards
   if(ma[1]>lma[1] &&  ma[2]<lma[2] && lma[1]>lma[2] &&  lma[2]>lma[3])
      return(bEntry ? ORDER_TYPE_SELL:ORDER_TYPE_BUY); // condition for sell

   return(WRONG_VALUE); // if there is no signal
  }

CMyEA ea; // class instance
//------------------------------------------------------------------    OnInit
int OnInit()
  {
   ea.Init(Symbol(),Period());   // initialize expert

                                 // initialization example
// ea.Init(Symbol(), PERIOD_M5); // for fixed timeframe
// ea.Init("USDJPY", PERIOD_H2); // for fixed symbol and timeframe

   return(0);
  }
//------------------------------------------------------------------    OnDeinit
void OnDeinit(const int reason) { }
//------------------------------------------------------------------    OnTick
void OnTick()
  {
   ea.Main(); // process incoming tick
  }
//+------------------------------------------------------------------+

Hi guys,

I tried to do a simple 2 MA crossover by editing the code from here:https://www.mql5.com/en/articles/148

but I keep getting this error:

  

appreciate if you could explain the problem, tried googling but couldn't find the solution...thanks in advance! :D

How to Quickly Create an Expert Advisor for Automated Trading Championship 2010
  • 2010.09.01
  • Andrew Kornishkin
  • www.mql5.com
In order to develop an expert to participate in Automated Trading Championship 2010, let's use a template of ready expert advisor. Even novice MQL5 programmer will be capable of this task, because for your strategies the basic classes, functions, templates are already developed. It's enough to write a minimal amount of code to implement your trading idea.
 
you just forgot ";" in line 29 after "m_LMAPer"...
 
code9527:
you just forgot ";" in line 29 after "m_LMAPer"...
I think I should get glasses...hehe, thanks man! :D
 
class CTradeo
{
public:
MqlTradeRequest request;
bool ModifyPosition(string pSymbol,double pStop,double pProfit=0);
MqlTradeResult result;
};

bool CTradeo::ModifyPosition(string pSymbol,double pStop,double pProfit=0.000000){

request.action=TRADE_ACTION_SLTP;
request.symbol=pSymbol;
request.sl=pStop;
request.tp=pProfit;
//orderloop
int retrycount=0;
int checkCode=0;

do{
OrderSend(request,result);
checkCode=CheckReturnCode(result.retcode);
if(checkCode==CHECK_RETCODE_OK)break;
else if(checkCode==CHECK_RETCODE_ERROR){

string errDesc=TradeServerReturnCodeDescription(result.retcode);
Alert("Modify position:Error",result.retcode," _ ",errDesc);
break;
}
else{
Print("Server error detected, retrying...");
Sleep(RETRY_DELAY);
retrycount++;

};

}while(retrycount<MAX_RETRIES);
if(retrycount<MAX_RETRIES){

string errDesc=TradeServerReturnCodeDescription(result.retcode);
Alert ("Max retries eceeded:Error "," _ ",errDesc);
}
string errDesc=TradeServerReturnCodeDescription(result.retcode);
Print("Modify position: ",result.retcode," _ ",errDesc,", SL: ",request.sl,",TP:",request.tp,",Bid:",SymbolInfoDouble(pSymbol,SYMBOL_BID),",Ask:",SymbolInfoDouble(pSymbol,SYMBOL_ASK),",stop Level:",SymbolInfoInteger(pSymbol,SYMBOL_TRADE_STOPS_LEVEL));
if(checkCode==CHECK_RETCODE_OK){

Comment("position modified on",pSymbol,", SL: ",request.sl,",TP: ",request.tp);
return(true);
}

else return(false);

}

Why does it make this mistake?   ')' - unexpected token  and ';' - unexpected token  on 

Sleep(RETRY_DELAY);
retrycount++;

and

while(retrycount<MAX_RETRIES);
Files:
Untitled.png  201 kb
 
MANIGHORBANPOUR #:

Why does it make this mistake?   ')' - unexpected token  and ';' - unexpected token  on 

and

Format your code properly and you'll understand the errors easily.

 
Alexandre Borela #:
Format your code properly and you'll understand the errors




Alexandre Borela #:
Format your code properly and you'll understand the errors easily.

I did this, but I made this mistake again  ')' - unexpected token  and ';' - unexpected token

Please look at this photo file and you will understand

Files:
Untitled.png  201 kb
 
MANIGHORBANPOUR #:




I did this, but I made this mistake again  ')' - unexpected token  and ';' - unexpected token

Please look at this photo file and you will understand

format your code so that it can be read properly, then you will be able to see where your brackets are not correctly paired...

post code with the </> button - don't use pictures for code noone is going to read it like that

Reason: