unexpected end of program , un balanced parenthesis .

 

i am having a issue with this program. i am trying to make an ea  which should open a trade  when Ma crosses and  should have  gap in them ,if these two conditions met then should open trade on end of current candle/bar  ,   but this ea opens so many trades buy and sell at same time. Please help .

#include <stdlib.mqh>



extern string     Comment1    = "- Strategy Parameters -";
#define MAGICMA  2021037
extern double LotSize = 0.01;     //Lot size kitni ho, 
extern int Slippage = 10;         //Order bhejte waqt  tak kitna farq ho 

 
extern string     Comment         = "- MA & Gap Setup -";
extern int FastMAPeriod = 0;       //Fast moving average period
extern int SlowMAPeriod = 0;       //Slow moving average period
extern int Tradepip = 50;          //Distance in MA

 
extern string     Comment2         = "- SL / TP Setup -";
extern int StopLoss = 30;        //Stop Loss value in pip
extern int TakeProfit = 250;      //Take Profit value in pip



extern string     Comment3         = "- TrailingStop Settings -";
extern bool TrailingSt = true;            // Trail stop on off                                                
extern double     TrailingStop    = 50;    //Trailing Stop
extern double     TrailingStep    = 5;     // Trailing Step 


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

//Internally Global Values

//+------------------------------------------------------------------+  
double OrderType, OrderOpenPrice = 0;
double PipValue = 0;   //Smallest move in parity

 

double FastAverage = 0;

double SlowAverage = 0;

 

double PreviousFastAverage = 0;

double PreviousSlowAverage = 0;
//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buyCount=0,sellCount=0;
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buyCount++;
         if(OrderType()==OP_SELL) sellCount++;
        }
     }
//--- return orders volume
   if(buyCount>0) return(buyCount);
   else       return(-sellCount);

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+  =======================================================

//| Expert initialization function                                   |

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

int OnInit()

{

    PipValue = CalculatePipValue(Symbol(),PipValue);

    Slippage = CalculateSlippage(Symbol(), Slippage);

     return (INIT_SUCCEEDED);

}

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

//| Expert tick function                                             |

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

void OnTick()

{

    CalculateMA();

    CheckForNewTrader();

    {    //Trail Algorithm

        TrailingStop();

  }  

}
//Market Pip value calculation

double CalculatePipValue(string _parity)

{

    int digit = (int)MarketInfo(_parity, MODE_DIGITS);

    if (digit == 2 || digit == 3) return 0.01;

    else if (digit == 4 || digit == 5) return 0.0001;

    return 0;

}

//Calculate Slippage Value

int CalculateSlippage(string _parity, int _slippage)

{

    int digit = (int)MarketInfo(_parity, MODE_DIGITS);

    if (digit == 2 || digit == 4) return _slippage;

    else if (digit == 3 || digit == 5) return _slippage * 15;

    return 0;

}

//Calculate Moving Averages

void CalculateMA()

{


     FastAverage = iMA(Symbol(), 0, FastMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 0);

     SlowAverage = iMA(Symbol(), 0, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 0);


     PreviousFastAverage = iMA(Symbol(), 0, FastMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);

     PreviousSlowAverage = iMA(Symbol(), 0, SlowMAPeriod, 0, MODE_SMA, PRICE_CLOSE, 1);

}

//Check for new trade

void CheckForNewTrader()

{

    //Fast moving average cross up to slow moving average   //Buy position       // for order check
    
     if (OrdersTotal()<1) {
     }
   {

         if ((FastAverage > SlowAverage)
         &&(PreviousFastAverage < PreviousSlowAverage))
        
                && int pipsMA = (int)MathFloor( MathAbs(FastMAPeriod-SlowMAPeriod)/_Point );     //ye line gap k lye hai
         
                   
            
            
        && if  int BarCount;
 
         init()
 
         BarCount = Bars - 1;
 
         start()
 
 
        if(BarCount != Bars){
         EnterNewTrade(OP_BUY);
     }       
            
   }         

        
}
    
  //Fast moving average cross down to slow moving average   //Sell position          // for order check

     if (OrdersTotal() <1){
     }
     {
      
    
    

       if ((FastAverage < SlowAverage)
        &&(PreviousFastAverage > PreviousSlowAverage)){
        
        //for next candle
        
     && int pipsMA = (int)MathFloor( MathAbs(FastMAPeriod-SlowMAPeriod)/_Point );       // ye line gap k lye hai
        
// ///////////////////////////////////      open order on new Candle    option  //////////////////////////////////////////////////

       && if  int BarCount;
 
         init()
 
         BarCount = Bars - 1;
 
         start()
 
 
        if(BarCount != Bars)
         {
        EnterNewTrade(OP_SELL);
        }
        
    }
        

}

//Enter new trade    ==========================================================================================================

void EnterNewTrade(int _OrderType)

{

    //First variables are set as buy order

    double OrderOpenPrice = Ask;

    string OrderName = "Bought";

    double OrderStopLoss = OrderOpenPrice - StopLoss * PipValue;

    double OrderTakeProfit = OrderOpenPrice + TakeProfit * PipValue;

 

    //If the actual type of order is SELL then variables are set as sell order

    if (OrderType == OP_SELL)

    {

        OrderOpenPrice = Bid;

        OrderName = "Sold";

 

        OrderStopLoss = OrderOpenPrice + StopLoss * PipValue;

        OrderTakeProfit = OrderOpenPrice - TakeProfit * PipValue;

    
}
 

 

    //Enter Position  ============================================================================================================

    int TicketNumber = OrderSend(Symbol(), _orderType, LotSize,0, Slippage, OrderStopLoss, OrderTakeProfit, "NEUTRONsAlgorithem", 0, 0, clrAliceBlue);

 

    //Error Handling



//Count Open Orders===================================================================================================================



 

 


//TrailingStop Algorithm ///////////////////////////////////////NEW TRAILING  Parameters /////////////////////////////////////
             void TrailingStop()
             
             if (TrailingSt==true) {
  
             double PipValue=MarketInfo(OrderSymbol(), MODE_POINT);
             double Bid=MarketInfo(OrderSymbol(), MODE_BID);
             double Ask=MarketInfo(OrderSymbol(), MODE_ASK);
                    TakeProfit = PipValue*TakeProfit;
                      StopLoss = PipValue*StopLoss;
             double  (OrderType ()== OP_SELL) = Bid - TrailingStop*PipValue ;
             double  (OrderType ()== OP_BUY ) = Ask + TrailingStop*PipValue;
 }  
             if(OrdersTotal == 1) return;
   
    ////////////////////////////////////////////////////////---------TAKE profit --------//////////////////////////////////////         
   
        if(TakeProfit > 0){
      
      if(OrderType ()== OP_BUY  ) TakeProfit = Ask + TakeProfit;
      if(OrderType ()== OP_SELL ) TakeProfit = Bid - TakeProfit;
   
   }
///////////////////////////////////////////////////////////////----STOP LOSS------  /////////////////////////////////////////////
   if(StopLoss > 0){
      
      if(OrderType ()== OP_BUY  ) StopLoss = Ask - StopLoss;
      if(OrderType ()== OP_SELL ) StopLoss = Bid + StopLoss;
   
   }
   
   bool Order_Modified = false;
   if ((OrderTakeProfit()==0 && TakeProfit > 0) || (OrderStopLoss()==0 && StopLoss > 0)){
      if (OrderModify(OrderTicket(),0,StopLoss,TakeProfit,0,clrBlue)){ Order_Modified = true; }
   }
  //////////////////////////////////////////////////////////////////////// Trailing Stop /////////////////////////////////////// 
   if(TrailingStop){
      
      if (OrderType() == OP_BUY){
         if ((Bid-OrderOpenPrice())>TrailingStop*PipValue){
            if (OrderStopLoss()<Bid-(TrailingStop+TrailingStep-1)*PipValue && TrailingStop>StopLoss) {
               if (OrderModify(OrderTicket(),OrderOpenPrice(),TrailingStop,OrderTakeProfit(),0,clrMagenta)){ Order_Modified = true; }
            }
         }
      }
      
      if(OrderType() == OP_SELL){
         if (OrderOpenPrice()-Ask>TrailingStop*PipValue) {
            if (OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*PipValue && TrailingStop<StopLoss) {
               if (OrderModify(OrderTicket(),OrderOpenPrice(),TrailingStop,OrderTakeProfit(),0,clrMagenta)){ Order_Modified = true; }
            }
         }
     }
   
  } 
   
   return;



//////////////////////////////////////////////////////OLD Parameters  Trailing Stop///////////////////////////////////////////////
     //void TrailingStop()
  //  for (int i = 0; i < OrdersTotal(); i++)
    
    //       if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
  //        if (OrderType() == OP_BUY)
   //          if (Ask > OrderStopLoss() + TrailingStop * PipValue && OrderStopLoss() >= OrderOpenPrice() +  PipValue)
  //          ReviseStopLoss(OrderTicket(), Ask - TrailingStop * PipValue);
  //         else if (OrderType() == OP_SELL)
   //            if (Bid < OrderStopLoss() - TrailingStop * PipValue && OrderStopLoss() <= OrderOpenPrice() -  PipValue)
  //                  ReviseStopLoss(OrderTicket(), Bid + TrailingStop * PipValue);
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Stop Loss Revise

//Stop Loss Revise

    void ReviseStopLoss(int _orderNumber, double _newStopLoss)

{

    if (OrderSelect(_orderNumber, SELECT_BY_TICKET, MODE_TRADES))

   {

        int controlNumber = OrderModify(OrderTicket(), OrderOpenPrice(), _newStopLoss, OrderTakeProfit(), 0, clrNONE);

    }

}  

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

{

    //---

}
 

You are missing one below

//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buyCount=0,sellCount=0;
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buyCount++;
         if(OrderType()==OP_SELL) sellCount++;
        }
     }
//--- return orders volume
   if(buyCount>0) return(buyCount);
   else       return(-sellCount);
} <---
//+------------------------------------------------------------------+Using the styler 

Using the styler can help.

 
Marco vd Heijden:

You are missing one below

Using the styler can help.

Now it Shows more Then 20 errors , Can you please look into it. Thanks in advance
 

Learn to code.

            void TrailingStop()
             
             if (TrailingSt==true) {

No opening bracket for the function.

void EnterNewTrade(int _OrderType)

{

No closing bracket for the function.

 

What is utlity of this ?

void CheckForNewTrader()

{

    //Fast moving average cross up to slow moving average   //Buy position       // for order check
    
     if (OrdersTotal()<1) {
     }
   {

And this ?

        && if  int BarCount;

You have a lot of error open/close bracket, please clean up and justify your code for lisibility, you will find error more easily.

ps : it seem all your errors are in CheckForNewTrader function.
Reason: