dude, if the function is expressed correctly

 

i have a problem with \end_of_program - unbalanced left paranthesis, anyone can help?, i don't see the error.

the latest functions calculate the sum of the prices of each symbol and operational direction and the other the sum of each symbol and operational direction, and then split them and know the price = 0, so do not buy if the price is above, or sell if the price is below. is correct? tkn

PriceSell()

PriceBuy()

OpenedBuy()

OpenedSell()

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

extern int MagicNumber = 2;
extern double Lots = 0.1;
extern int Slippage = 3;
extern int Compra = -30;
extern int Venda = 45;

double PriceSell;
double PriceBuy;
int BarCount, Current, countbuy, countsell, openbuy, opensell, pricebuy, pricesell, pips2dbl, pips2point, pipValue;
bool TickCheck = False;
bool IsTradedOnThisBar; //only 1 trade for bar


int init() {
   
   if (Digits == 5 || Digits == 3)    // Adjust for five (5) digit brokers.
   {            
      pips2dbl = Point*10; pips2point = 10;pipValue = (MarketInfo(Symbol(),MODE_TICKVALUE))*10;
   } 
   else 
   {    
      pips2dbl = Point;   pips2point = 1;pipValue = (MarketInfo(Symbol(),MODE_TICKVALUE))*1;
   }
   

   return(0);
}

int deinit() {
   return(0);
}

int start() 
{
   int Order = SIGNAL_NONE;
   int Total; 
   int Ticket;
   double StopLossLevel = 0, TakeProfitLevel = 0;

   Total = OrdersTotal();
   Order = SIGNAL_NONE;
   
   openbuy = OpenedBuy();
   opensell =  OpenedSell();
   pricebuy = PriceBuy();
   pricesell = PriceSell();
   DoubleToStr(pricebuy,5);
   DoubleToStr(pricesell,5);


    double Buy2_1 = iCustom(Symbol(), PERIOD_M1, "JVC", 20,9,0.5,-0.5,100, 0, Current + 0);
    double Buy2_2 = Compra;

    double Sell2_1 = iCustom(Symbol(), PERIOD_M1, "JVC", 20,9,0.5,-0.5,100, 0, Current + 0);
    double Sell2_2 = Venda;

   if (Buy2_1 < Buy2_2) Order = SIGNAL_BUY;

   if (Sell2_1 > Sell2_2) Order = SIGNAL_SELL;

   if (Order == SIGNAL_BUY && ((pricebuy/openbuy)>Ask) && IsTradedOnThisBar!=Bars) 
   {
         {
         Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         IsTradedOnThisBar = Bars;}
         if(Ticket > 0) 
         {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) 
            {
                                Print("BUY order opened : ", OrderOpenPrice());
                           } 
                           else 
                           {
                                Print("Error opening BUY order : ", GetLastError());
                           }
         }
        
         return(0);   
   }

   if (Order == SIGNAL_SELL && ((pricesell/opensell<Bid) && IsTradedOnThisBar!=Bars) 
   {
         {
         Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         IsTradedOnThisBar = Bars;
         }
         if(Ticket > 0) 
         {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES))
            {
                                Print("SELL order opened : ", OrderOpenPrice());
                
                           } 
                           else 
                           {
                                Print("Error opening SELL order : ", GetLastError());
                           }
         }

      return(0);
      
   }    
}
   
double PriceBuy()
   {
       int total  = OrdersTotal();
       double pricebuy = 0;
         for (int cnt = total-1 ; cnt >=0 ; cnt--)
         {                                   
           OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
           
             if(OrderSymbol()==Symbol() && (OrderType()==OP_BUY))
              
               pricebuy+=OrderOpenPrice();
                          
         }
         return (pricebuy);
}
double PriceSell()
{
      int total  = OrdersTotal();
      double pricesell = 0;
        for (int cnt = total-1 ; cnt >=0 ; cnt--)
         {                                   
          OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

            if(OrderSymbol()==Symbol() && (OrderType()==OP_SELL))
             
              pricesell+=OrderOpenPrice();
                      
         }
         return (pricesell);
}  
int OpenedBuy()
{
     int total  = OrdersTotal();
     int countbuy = 0;
         for (int cnt = total-1 ; cnt >=0 ; cnt--)
         {
            OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
 
              if(OrderSymbol()==Symbol()&& OrderType()==OP_BUY)
               
               countbuy++;           
         }
         return (countbuy);
}
int OpenedSell()
{
       int total  = OrdersTotal();
       int countsell = 0;
         for (int cnt = total-1 ; cnt >=0 ; cnt--)
         {
           OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
         
            if(OrderSymbol()==Symbol() && (OrderType()==OP_SELL))
               
              countsell++;                                    
         }
         return (countsell);

}
 

Here is one . . . it took me 20s to find, are you not able to count braces ?

if ( Order == SIGNAL_BUY && ( ( pricebuy/openbuy)>Ask ) && IsTradedOnThisBar!=Bars ) 

3 x green (, 2 x red )

 
if ( Order == SIGNAL_BUY && ( ( pricebuy/openbuy ) >Ask ) && IsTradedOnThisBar!=Bars ) 
3 x green (, 3 x red ) excuse i'm a count 3 red 3 green, no?
 
sorry the error is that, but this in signal_SELL, thanks anyway
 
Bellagio:
3 x green (, 3 x red ) excuse i'm a count 3 red 3 green, no?
Yep, sorry I missed one . . .
 

This looks also strange to my eyes: (Not sure if such blocks are allowed in mql)

if (Order == SIGNAL_SELL && ((pricesell/opensell<Bid) && IsTradedOnThisBar!=Bars) 
   {
         {
         Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         IsTradedOnThisBar = Bars;
         }
 
Yest the extra braces are allowed. I have them in my code
int init(){
    :
    {//++++ One time variable initializations.
        chart.symbol    = Symbol();                     chart.period    = Period();
        :
    }//---- One time variable initializations.
    :
}
They do nothing. I use them for code folding in notepad2. (Shrink function definitions, for loops, sections of code to one line.)
 

line 87

if (Order == SIGNAL_SELL && ((pricesell/opensell<Bid) && IsTradedOnThisBar!=Bars)
 
  1.         for (int cnt = total-1 ; cnt >=0 ; cnt--)
             {                                   
              OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    
                if(OrderSymbol()==Symbol() && (OrderType()==OP_SELL))
                 
                  pricesell+=OrderOpenPrice();
                          
             }
    What are Function return values ? How do I use them ? - MQL4 forum
    No magic number mean's the EA in incompatible with every other including manual trading.

  2. What is the meaning of pricesell? 5 oranges for $1 + 7 oranges for $1.50 = $2.50 which means nothing. If you want average price then you need a weighted mean AveragePrice = Sum( amount*price )/Sum(amount) 5 oranges for $1 + 7 oranges for $1.50 = 12 @ $1.29
Reason: