A small {} issue please help

Dilshad24  


this 2 error in the code below 

'}' - unexpected end of program

'{' - unbalanced parentheses

int OnInit()

{
  // Initialize the Moving Averages with the correct parameters
  Handle1 = iMA(Symbol(), 0, 20, 0, MODE_SMA, PRICE_CLOSE);
  if (Handle1 < 0) return INIT_FAILED;

  Handle2 = iMA(Symbol(), 0, 22, 0, MODE_SMA, PRICE_CLOSE);
  if (Handle2 < 0) return INIT_FAILED;


  return INIT_SUCCEEDED;
}

void OnDeinit(const int reason)
{
  // Release resources
}

void OnTick()
{
  // Get the Moving Averages values
  MA1 = iMA(Symbol(), 0, 20, Handle1, MODE_SMA, PRICE_CLOSE);
  MA2 = iMA(Symbol(), 0, 22, Handle2, MODE_SMA, PRICE_CLOSE);


  // Check the price relative to the Moving Averages
  if (Bid > MA1 && Bid > MA2)
  {
    // Buy if price is above both Moving Averages
    MqlTradeRequest request = {0};
    MqlTradeResult result = {0};
    request.action = TRADE_ACTION_DEAL;
    request.type = ORDER_TYPE_BUY;
    request.symbol = Symbol();
    request.price = Bid;
    request.volume = 0.1;
    request.sl = 0;
    request.tp = 0;
    request.deviation = 3;
    request.magic = 0;
    request.comment = NULL;
    request.type_time = ORDER_TIME_GTC;
    request.color = CLR_NONE;
    request.start_time = 0;
    request.expiration = 0;
    OrderSend(request, result);
  }
  else if (Bid < MA1 && Bid < MA2)
  {
    // Sell if price is below both Moving Averages
    MqlTradeRequest request = {0};
    MqlTradeResult result = {0};
    request.action = TRADE_ACTION_DEAL;
    request.type = ORDER_TYPE_SELL;
    request.symbol = Symbol();
    request.price = Bid;
    request.volume = 0.1;
    request.sl = 0;
    request.tp = 0;
    request.deviation = 3;
    request.magic = 0;
    request.comment = NULL;
    request.type_time = ORDER_TIME_GTC;
    request.color = CLR_NONE;
    request.start_time = 0;
    request.expiration = 0;
    OrderSend(request, result);
  }
  else
  {
// Close open trades if the price is between both Moving Averages

ArrayInt ticketList;
ArrayInt typeList;
ArrayDouble priceList;

int totalTrades = OrdersTotal();
for (int i = 0; i < totalTrades; i++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 0) {
ticketList.Add(OrderTicket());
typeList.Add(OrderType());
priceList.Add(OrderClosePrice());
}
}

if (ticketList.Total() > 0) {
for (int i = 0; i < ticketList.Total(); i++) {
OrderClose(ticketList[i], 0.1, priceList[i], 3);
}
}
}
Carl Schreiber  
  1. Please use the code button (Alt+s or </>) to post code!
  2. Use the Styler in the Editor (Tools => Styler or Alt+,) that will help you to find the missing } and where it belongs to.
Dilshad24  
void OnTick()
  { 
  
// Get the Moving Averages values
   MA1 = iMA(Symbol(), 0, 20, Handle1, MODE_SMA, PRICE_CLOSE);
   MA2 = iMA(Symbol(), 0, 22, Handle2, MODE_SMA, PRICE_CLOSE);


// Check the price relative to the Moving Averages
   if(Bid > MA1 && Bid > MA2)
     {
      // Buy if price is above both Moving Averages
      MqlTradeRequest request = {0};
      MqlTradeResult result = {0};
      request.action = TRADE_ACTION_DEAL;
      request.type = ORDER_TYPE_BUY;
      request.symbol = Symbol();
      request.price = Bid;
      request.volume = 0.1;
      request.sl = 0;
      request.tp = 0;
      request.deviation = 3;
      request.magic = 0;
      request.comment = NULL;
      request.type_time = ORDER_TIME_GTC;
      request.color = CLR_NONE;
      request.start_time = 0;
      request.expiration = 0;
      OrderSend(request, result);
     }
   else
      if(Bid < MA1 && Bid < MA2)
        {
         // Sell if price is below both Moving Averages
         MqlTradeRequest request = {0};
         MqlTradeResult result = {0};
         request.action = TRADE_ACTION_DEAL;
         request.type = ORDER_TYPE_SELL;
         request.symbol = Symbol();
         request.price = Bid;
         request.volume = 0.1;
         request.sl = 0;
         request.tp = 0;
         request.deviation = 3;
         request.magic = 0;
         request.comment = NULL;
         request.type_time = ORDER_TIME_GTC;
         request.color = CLR_NONE;
         request.start_time = 0;
         request.expiration = 0;
         OrderSend(request, result);
        }
      else
        {
         // Close open trades if the price is between both Moving Averages

         ArrayInt ticketList;
         ArrayInt typeList;
         ArrayDouble priceList;

         int totalTrades = OrdersTotal();
         for(int i = 0; i < totalTrades; i++)
           {
            OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == 0)
              {
               ticketList.Add(OrderTicket());
               typeList.Add(OrderType());
               priceList.Add(OrderClosePrice());
              }
           }

         if(ticketList.Total() > 0)
           {
            for(int i = 0; i < ticketList.Total(); i++)
              {
               OrderClose(ticketList[i], 0.1, priceList[i], 3);
              }
           }
        }
//+------------------------------------------------------------------+

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

do u mean like this  


but still i have the issues 

Carl Schreiber  
And where is the line with: "'{' - unbalanced parenthese" ?
Carl Schreiber  
Don't you see that the pairs of { and } are highlighted. So you can see the partner of the last }. So each { has a partner but not the first one right after OnTick() - so place a } at the very end.
Dilshad24  

if u mean like this   so i have now 44 new issues 


//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#include <Arrays\ArrayObj.mqh>
#include <Arrays\ArrayInt.mqh>
#include <Arrays\ArrayDouble.mqh>
#include <Math\stat\Math.mqh>
#include <Math\Alglib\Statistics.mqh>
#include <MovingAverages.mqh>
int Handle1, Handle2;
double MA1, MA2;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
// Initialize the Moving Averages with the correct parameters
   Handle1 = iMA(Symbol(), 0, 20, 0, MODE_SMA, PRICE_CLOSE);
   if(Handle1 < 0)
      return INIT_FAILED;

   Handle2 = iMA(Symbol(), 0, 22, 0, MODE_SMA, PRICE_CLOSE);
   if(Handle2 < 0)
      return INIT_FAILED;


   return INIT_SUCCEEDED;
  }

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

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()

  {
// Get the Moving Averages values
   MA1 = iMA(Symbol(), 0, 20, Handle1, MODE_SMA, PRICE_CLOSE);
   MA2 = iMA(Symbol(), 0, 22, Handle2, MODE_SMA, PRICE_CLOSE);


// Check the price relative to the Moving Averages
   if(Bid > MA1 && Bid > MA2)
     {
      // Buy if price is above both Moving Averages
      MqlTradeRequest request = {0};
      MqlTradeResult result = {0};
      request.action = TRADE_ACTION_DEAL;
      request.type = ORDER_TYPE_BUY;
      request.symbol = Symbol();
      request.price = Bid;
      request.volume = 0.1;
      request.sl = 0;
      request.tp = 0;
      request.deviation = 3;
      request.magic = 0;
      request.comment = NULL;
      request.type_time = ORDER_TIME_GTC;
      request.color = CLR_NONE;
      request.start_time = 0;
      request.expiration = 0;
      OrderSend(request, result);
     }
   else
      if(Bid < MA1 && Bid < MA2)
        {
         // Sell if price is below both Moving Averages
         MqlTradeRequest request = {0};
         MqlTradeResult result = {0};
         request.action = TRADE_ACTION_DEAL;
         request.type = ORDER_TYPE_SELL;
         request.symbol = Symbol();
         request.price = Bid;
         request.volume = 0.1;
         request.sl = 0;
         request.tp = 0;
         request.deviation = 3;
         request.magic = 0;
         request.comment = NULL;
         request.type_time = ORDER_TIME_GTC;
         request.color = CLR_NONE;
         request.start_time = 0;
         request.expiration = 0;
         OrderSend(request, result);
        }
      else
        {
         // Close open trades if the price is between both Moving Averages

         ArrayInt ticketList;
         ArrayInt typeList;
         ArrayDouble priceList;

         int totalTrades = OrdersTotal();
         for(int i = 0; i < totalTrades; i++)
           {
            OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == 0)
              {
               ticketList.Add(OrderTicket());
               typeList.Add(OrderType());
               priceList.Add(OrderClosePrice());
              }
           }

         if(ticketList.Total() > 0)
           {
            for(int i = 0; i < ticketList.Total(); i++)
              {
               OrderClose(ticketList[i], 0.1, priceList[i], 3);
              }
           }
        }
  }
//+------------------------------------------------------------------+

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

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

//+------------------------------------------------------------------+
Reason: