'{' unbalanced parentheses need to solve. 1 error to be correction.

 

Hi, I'm new to creating my first mql5 robot, I have one error and need to solve, could you please help me to correct it? Thank you.

#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include  <Trade/Trade.mqh>

CTrade           trade;
CPositionInfo    pos;
COrderInfo       ord;

input double          RiskPercent              = 2;
input int             TakeProfit               =100;
input int             StopLoss                 =200;
input int             TslTrigerPoints          =15;
input int             TslPoint                 =10;
input ENUM_TIMEFRAMES TimeFrame        = PERIOD_CURRENT;
input int            inpMagic  = 10001;
input string           TradeComment = "FMT-5min Scalper";

enum StartHour  {Inactive=0, _0100=1, _0200=2, _0300=3, _0400=4, _0500=5, _0600=6, _0700=7, _0800=8, _0900=9, _1000=10, _1100=11, _1200=12, _1300=13, _1400=14, _1500=15, _1600=16, _1700=17, _1800=18, _1900=19, _2000=20, _2100=21, _2200=22, _2300=23};
input StartHour  SHInput=0;
enum EndHour   {Inactive=0, _0100=1, _0200=2, _0300=3, _0400=4, _0500=5, _0600=6, _0700=7, _0800=8, _0900=9, _1000=10, _1100=11, _1200=12, _1300=13, _1400=14, _1500=15, _1600=16, _1700=17, _1800=18, _1900=19, _2000=20, _2100=21, _2200=22, _2300=23};
input EndHour    EHInput=0;
int SHChoice;
int EHChoice;

int       BarsN = 5;
int       ExpirationBars = 100;
int       OrderDistPoints  = 100;



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   trade.SetExpertMagicNumber(inpMagic);
   ChartSetInteger(0,CHART_SHOW_GRID,false);

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }

void OnTick()
  {
   TrailStop();

   if(!IsNewBar())
      return;
   MqlDateTime time;
   TimeToStruct(TimeCurrent(),time);
   int Hournow = time.hour;

   SHChoice = SHInput;
   EHChoice = EHInput;

   if(Hournow<SHChoice)
     {
      CloseAllOrders();
      return;
     }
   if(Hournow>=EHChoice && EHChoice =0)
     {
      CloseAllOrder();
      return;
     }

   int BuyTotal=0;
   int SellTotal=0;

   for(int i=PositionsTotal()-1; i>=0; i--)
     {
      pos.SelectByIndex(i);
      if(pos.PositionType()==POSITION_TYPE_BUY && pos.Symbol()==_Symbol && pos.Magic()==InputMagic)
         BuyTotal++;
      if(pos.PositionType()==POSITION_TYPE_SELL && pos.Symbol()==_Symbol && pos.Magic()==InputMagic)
         SellTotal++;
     }
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      ord.SelectByIndex(i);
      if(ord.OrderType()==ORDER_TYPE_BUY_STOP && ord.Symbol()==_Symbol && ord.Magic()==InputMagic)
         BuyTotal++;
      if(ord.OrderType()==ORDER_TYPE_SELL_STOP && ord.Symbol()==_Symbol && ord.Magic()==InputMagic)
         SellTotal++;
     }
   if(BuyTotal <=0)
     {
      double high = findHigh();
      if(high >0)
        {
         SendBuyOrder(high);
        }
      if(SellTotal <=0)
        {
         double low = findLow();
         if(low > 0)
           {
            SendSellOrder(low);
           }

   //+------------------------------------------------------------------+

    double findHigh()
        {

    double highestHigh = 0;
    for(int i = 0; i < 200; i++)
        {
    double high = iHigh{_Symbol,Timeframe,i);
       if(i > BarsN && iHighest(_Symbol,Timeframe,MODE_HIGH,BarsN*2+1,i-BarsN) == i)
      {
       if(high > highestHigh)
     {
       return high;
    }
     highestHigh = MatMax(high,highestHigh);
     }
      return -1;
    }

     double findLow()
     {
     double lowestLow = DBL_MAX;
      for(int i =0; i < 200; i++)
      {
       double low = iLow(_Symbol,TimeFrame,i);
     if(i > BarsN && iLowest(_Symbol,TimeFrame,MODE_LOW,BarsN*2+1,i-BarsN) == i)
      {
     if(low < lowestLow)
     {
      return low;
     }
     lowestLow = MathMin(low,lowesrLow);
     }
        return -1;
      }

      bool IsNewBar()
       {
     static datetime previousTime = 0;
     datetime currentTime = iTime(_Symbol,TimeFrame,0);
     if(previousTime=currentTime)
      {
      previousTime=currentTime;
          return true;
       }
          return false;
          }

                  void SendBuyOrder(double entry)
                    {

                     double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
                     if(ask > entry - OrderDistPoints * _Point)
                        return;

                     double tp = entry + Tppoints * _Point;
                     double sl = entry - SlPoints * _Point;

                     double lots = 0.01;
                     if(RiskPercent > 0)
                        lots = calclots(entry-sl);

                     datetime expiration = iTime(_Symbol,Timeframe,0) + ExpirationBars * PeriodSeconds(Timeframe);
                     trade.Buystop(lots,entry,_Symbol,sl,tp,ORDER_TIME_SPECIFIED,expiration);

                     void SendSellOrder(double entry)
                       {

                        double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
                        if(bid > entry - OrderDistPoints * _Point)
                           return;

                        double tp = entry + Tppoints * _Point;
                        double sl = entry - Slpoints * _Point;

                        double lots = 0.01;
                        if(RiskPercent > 0)
                           lots = calclots(sl-entry);

                        datetime expiration = iTime(_Symbol,Timeframe,0) + ExpirationBars * PeriodSeconds(Timeframe);
                        trade.Sellstop(lots,entry,_Symbol,sl,tp,ORDER_TIME_SPECIFIED,expiration);
                       }

                     double calcLots(double slPoints)
                       {
                        double risk = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent / 100;
                        double ticksize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
                        double tickvalue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE);
                        double lotstep = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
                        double minvolume = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
                        double maxvolume = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
                        double volumelimit = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_LIMIT);

                        double moneyPerLotstep = slPoints / ticksize * tickvalue * lotstep;
                        double lots = MathFloor(risk / moneyPerLotstep) * lotstep;

                        if(volumelimit! = 0)
                           lots = MathMin(lots,volumelimit);
                        if(maxvolume! = 0)
                           lots = Mathmin(lots,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX));
                        If(minvolume! = 0) lots = MathMax(lots,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN));
                        lots = NormalizeDouble(lots,2);

                        return lots;
                       }

                     void CloseAllOders()
                       {

                        for(int i=OrdersTotal()-1;i>=0;i--)
                          {
                           ord.SelectByIndex(i);
                           ulong ticket = ord.Ticket();
                           if(ord.Symbol()==_Symbol && ord.Magic()==InMagic)
                             {
                              trade.OrderDelete(ticket);

                             }
                           void TrasilStop()
                             {

                              double sl =0;
                              double tp =0;

                              double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
                              double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);

                              for(int i=PositionTotal()-1;i>=0;i--)
                                {
                                 if(pos.SelectByIndex(i))
                                   {
                                    ulong ticket = pos.Ticket();

                                    if(pos.Magic()==InpMagic && pos.Symbol()==_Symbol)
                                      {

                                       if(pos.PositionType()==POSITION_TYPE_BUY)
                                         {
                                          if(bid-pos.PriceOpen()>TslTrigerPoints*_Point)
                                            {
                                             tp =pos.TakeProfit();
                                             sl = bid - (TslPoints * _Point);

                                             if(sl > pos.StopLoss() && sl!=0)
                                               {
                                                trade.PositionModify(ticket,sl,tp);
                                               }

                                             else
                                                if(pos.PositionType()==POSITION_TYPE_SELL)
                                                  {
                                                   if(ask+(TslTrigerPoints*_Point)<pos.PriceOpen())
                                                     {
                                                      tp =pos.TakeProfit();
                                                      sl = ask + (TslPoints * _point);
                                                      if(sl < pos.StopLoss() && sl!=0)
                                                        {
                                                         trade.PositionModify(ticket,sl,tp);
                                                        }



                                                     }
                                                  }
//+------------------------------------------------------------------+

could not find out where to solve it, could you please help me to correct it?
 
fmtrader:

Hi, I'm new to creating my first mql5 robot, I have one error and need to solve, could you please help me to correct it? Thank you.


could not find out where to solve it, could you please help me to correct it?
Bro TBH you'll be lucky if anyone helps you on that one, it's such a trivial matter. 

Don't lose heart, just keep reading your code and trying again, thats what everyone here does.

Heres what I'd if I were in your position, MetaEditot has an option that highlights your braces for you, try enabling it to see if you can spot the incomplete pair. Or check if there are any missing semicolons.
 
Gamuchirai Zororo Ndawana #:
Bro TBH you'll be lucky if anyone helps you on that one, it's such a trivial matter. 

Don't lose heart, just keep reading your code and trying again, thats what everyone here does.

Heres what I'd if I were in your position, MetaEditot has an option that highlights your braces for you, try enabling it to see if you can spot the incomplete pair. Or check if there are any missing semicolons.

Yes bro, I wonder MetaEditor has corrected our wrong parentheses automatically. I'm new to coding MQL5 language, very tough for me.

 

no chance, in this case it's similar to asking "can you make sure my socks match? I just tried to match them". They're your socks, you deal with them.

Can't you see at least that there's no closing brace on your for loop as well as other conditions towards the end of the code? I'm not sure if you're reading the code at all, so if someone helps, you are not reading and learning