The problem is before the code you show. Post the code not a picture.
//+------------------------------------------------------------------+ //| 7&.mq5 | //| Copyright 2015, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //--- input parameters input char lot=1; //Order Size input int takeprofit=30; //Take Profit input int stoploss=10; //Stop Loss input char dev=10; //Deviation //input cahr f=10; input char ma_period=9; input char rsi_period=7; //RSI Period input char upperrsi=70; //Upper RSI input char lowwerrsi=30; //Lower RSI input int EA_magic=5913; //EA Magic Number //--- Other Parameters int mahandle; //handle for Moving Average int rsihandle; //handle for RSI double maval[]; //dynamic array to hold moving average values for each bar double rsival[]; //dynamic array to hold RSI values for each bar double p_close; //variable to store close price of the bar int stp; int tkp; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //---Get Handle for RSI rsihandle=iRSI(_Symbol,_Period,rsi_period,PRICE_CLOSE); //---Get Handle for Moving Average of RSI mahandle=iMA(_Symbol,_Period,ma_period,0,MODE_EMA,rsihandle); //---Return Error for wrong Handle if(rsihandle<0 || mahandle<0) { Alert("Error Creating Handle for Indicators - error: ",GetLastError()," !!"); } stp=stoploss; tkp=takeprofit; if(_Digits==5 || _Digits==3) { stp = stp*10; tkp = tkp*10; } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //---Release our indicator handles IndicatorRelease(rsihandle); IndicatorRelease(mahandle); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //---Define some MQL5 structures we will use for our trade MqlTick latest_price; //to be used for getting recent/latest price quotes MqlTradeRequest mrequest; //to be used for sending our trade request; MqlTradeResult mresult; //to be used to get our trade result MqlRates mrate[]; //to be used to store the prices, volumes and spread of each bar ZeroMemory(mrequest); //initiliazation of mrequest structure // the rates arrays ArraySetAsSeries(mrate,true); // the Moving Average values array ArraySetAsSeries(maval,true); // the RSI values array ArraySetAsSeries(rsival,true); //Do we have enough bars to work with if(Bars(_Symbol,_Period)<60); { Alert("We have less than 60 bars, EA will now exit!!"); } static datetime old_time; datetime new_time[1]; bool isnewbar=false; int copied=CopyTime(_Symbol,_Period,0,1,new_time); if(copied>0) //ok data has been copied successfully { if(old_time!=new_time[0]) { isnewbar=true; //if it is not a first call, the new bar has appeard if(MQL5InfoInteger(MQL5_DEBUGGING)) Print ("We have new bar here ",new_time[0]," old time was ", old_time); old_time=new_time[0]; } } else { Alert("error in copying historical times data, error = ", GetLastError()); ResetLastError(); return; } //--- EA should only check for new trade if we have a new bar if(isnewbar==false) { return; } //do we have nough bars to work with int mybars=Bars(_Symbol,_Period); if(mybars<60) { Alert("We have less than 60 bars, EA will now exit!!"); return; } //---------------------------------------------------------- if(!SymbolInfoTick(_Symbol,latest_price)) { Alert("Error getting the latest price quote - error: ",GetLastError(),"!!"); return; } //---Get the details of the latest 3 bars if(CopyRates(_Symbol,_Period,0,3,mrate)<0) { Alert("Error copying rates/history data - error: ",GetLastError(),"!!"); return; } if (CopyBuffer(rsihandle,0,0,3,rsival)<0) { Alert("Error copying RSI indicator buffers - error: ",GetLastError()); return; } if (CopyBuffer(mahandle,0,0,3,maval)<0) { Alert("Error copying Moving Average indicator buffers - error: ",GetLastError()); return; } bool buy_open=false; //variable to hold the result of buy opened position bool sell_open=false; //variable to hold the result of sell opened position if (PositionSelect(_Symbol)==true) //we have an opened position { if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { buy_open=true; //it is a buy } else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { sell_open=true; //it is a sell } } p_close=mrate[1].close //bar 1 close price bool buy_condition_1 = (maval[0]>maval[1]) && (maval[1]>maval[2]); bool buy_condition_2 = (rsival[0]>rsival[1] && rsival[1]>rsival[2]); bool buy_condition_3 = (rsival[0]>maval[0]); if(buy_condition_1 && buy_condition_2 && buy_condition_3) { if (buy_open) { Alert("We alredy have a buy position!!!"); return; //do not open a new buy position } ZeroMemory(mrequest); mrequest.action = TRADE_ACTION_DEAL; //immidiate order execution mrequest.price = NormalizeDouble(latest_price.ask,_Digits); //latest ask price mrequest.sl = NormalizeDouble(latest_price.ask - stp*_Point,_Digits); //Stop Loss mrequest.tp = NormalizeDouble(latest_price.ask + tkp*_Point,_Digits); //take profit mrequest.symbol = _Symbol; //symbol to trade mrequest.volume = lot; //lot size mrequest.magic = EA_magic; mrequest.type = ORDER_TYPE_BUY; //BUY ORDER mrequest.type_filling = ORDER_FILLING_FOK; //ORDER EXECUTION TYPE mrequest.deviation=dev; //deviation from current price OrderSend(mrequest,mresult); if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed { Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!"); } else { Alert("The Buy order request could not be completed -error:",GetLastError()); ResetLastError(); return; } } bool sell_condition_1 = (maval[0]<maval[1] && maval[1]<maval[2]); bool sell_condition_2 = (rsival[0]<rsival[1] && rsival[1]<rsival[2]); bool sell_condition_3 = (rsival[0]<maval[0]); if(sell_condition_1 && sell_condition_2 && sell_condition_3) { if (sell_open) { Alert("We alredy have a sell position!!!"); return; //do not open a new sell position } ZeroMemory(mrequest); mrequest.action = TRADE_ACTION_DEAL; //immidiate order execution mrequest.price = NormalizeDouble(latest_price.bid,_Digits); //latest ask price mrequest.sl = NormalizeDouble(latest_price.bid + stp*_Point,_Digits); //Stop Loss mrequest.tp = NormalizeDouble(latest_price.bid - tkp*_Point,_Digits); //take profit mrequest.symbol = _Symbol; //symbol to trade mrequest.volume = lot; //lot size mrequest.magic = EA_magic; mrequest.type = ORDER_TYPE_BUY; //BUY ORDER mrequest.type_filling = ORDER_FILLING_FOK; //ORDER EXECUTION TYPE mrequest.deviation=dev; //deviation from current price //---send order OrderSend(mrequest,mresult); // get the result code if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed { Alert("A Sell order has been successfully placed with Ticket#:",mresult.order,"!!"); } else { Alert("The Sell order request could not be completed -error:",GetLastError()); ResetLastError(); return; } } return; } //+------------------------------------------------------------------+

Automated Trading and Strategy Testing
- www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
//do we have nough bars to work with int mybars=Bars(_Symbol,_Period); if(mybars<60) { Alert("We have less than 60 bars, EA will now exit!!"); return; }
p_close=mrate[1].close; //bar 1 close price
I didn't see that! Thanks a lot!

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi all,
I'm new to coding and MQL5 and this is my first ea.
The problem I have is "unexpected token" for my buy conditions.
I did a google search and was not able to find any answer, so I was hoping you guys can help me with the issue.
Please let me know if I need to send more information.