Error '(' - function definition unexpected - page 3

 

Hi all,

 I'm looking to alternate buy orders and sell orders.

What I mean is;

  First  open by mean of an indicator is a buy (could be a sell of course)  and then a buy order is open, if  price bounce down to a level under the open price from the buy order, a sell order will open, but if price goes up again no new open buy should happen. Here a new buy order should only happen when price bounces back from the sell order. All the same if a sell order is the first to happen.

I've tried to get that with the following code but doesn't work. 

I really appreciate if one could help me here.

best regards

Luis

total=OrdersTotal();
        if(total<1)
                              
  // Buy Order Condition to Open

  if(Bid >= PricePosition + OpenDistance*pt && BuyTicket == 0)                    
          {//8  
          while(IsTradeContextBusy()) 
          Sleep(10);
          RefreshRates();       
               
     BuyTicket=OrderSend(Symbol(),OP_BUY,MLots,Ask,RealSlippage,0,0,"Buy Order",MagicNumber,0,Green);
     if(BuyTicket > -1)
        {//9
         Print("Opposite Buy order placed # ",BuyTicket);
         AddLimitsBuy();
         }//9
      else
         {//10 
         Print("Order Send failed, error # ", GetLastError());
         }//7 
      return(0);
      }//5
//-----------------------------------------------------------------------------+        
// Sell Order Condition to Open
                   
     if(Bid <= PricePosition - OpenDistance*pt && SellTicket == 0)                
        {//8                                
                  while(IsTradeContextBusy()) 
                  Sleep(10);
                  RefreshRates();       
                                                
                  SellTicket=OrderSend(Symbol(),OP_SELL,MLots,Bid,RealSlippage,0,0,"Sell Order",MagicNumber,0,Red);
                  if(SellTicket > -1)
                     {//9
           Print("Opposite Sell order placed # ", SellTicket);
           AddLimitsSell();
           }//9
        else
           {//10
           Print("Order Send failed, error # ", GetLastError());
           }//10
        return(0);
        }//8                                                            
//+---------------------------------------------------------------------------+  
 //Open Opposite Order (open opposite order if last order not reach TakeProfit)
 
   int Op;  
 
   for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--)
      {//14
      if(OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES))  
         {//15
         if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)
            {//16
            Op = OrderType();

            if(Op == OP_BUY && Bid < OrderOpenPrice() - (ReturnDist*pt)&& SellTicket == 0)
               {//17               
               SellTicket = OrderSend(Symbol(), OP_SELL, MLots, Bid, RealSlippage, 0, 0, "Sell Order", MagicNumber, 0, Red);
               if(SellTicket > -1) 
                  {//18
                  Print("Opposite Sell order placed # ", SellTicket);
                  AddLimitsSell();
                  }//18
               else
                  {//19
                  Print("Order Send failed, error # ", GetLastError() );
                  }//19
                }//17
                           
            if(Op == OP_SELL && Ask > OrderOpenPrice() + (ReturnDist*pt)&& BuyTicket == 0)
               {//20             
               BuyTicket = OrderSend(Symbol(), OP_BUY, MLots, Ask, RealSlippage, 0, 0, "Buy Order", MagicNumber, 0, Green);
               if(BuyTicket > -1)
                  {//21
                  Print("Opposite Buy order placed # ", BuyTicket);
                  AddLimitsBuy();
                  }//21
               else
                  {//22  
                  Print("Order Send failed, error # ", GetLastError());
                  }//22   
               }//20
            }//16
         }//15    
      }//14
 

Try coding with smaller functions. It makes life easier.

int Last_OrderType_Symbol(string Symb){
    for(int i=OrdersTotal()-1; i>=0; i--){
        if(!OrderSelect(i,SELECT_BY_POS)){continue;}
        if(OrderMagicNumber()!=Magic){continue;}
        if(OrderSymbol()!=Symb){continue;}
        return(OrderType());
}   }

The above function returns the Order_Type of the last order within the Trade_Pool which also matches the Symbol provided.

-It does not exclude Pending Orders.

-It does not include all Symbols.

-It filters by magic# which is Extern Global [recommended].

-It does not sort orders by Time.

-It does not Print Fail_Messages or Error#. 

-It does not Error_Handle | Retry | Send_Email ... Blah ... Blah ... Blah

Rename, customize or modify functions, but make extensive use of them. This one provided as sample only.

https://www.mql5.com/en/forum/139592 

https://book.mql4.com/basics/functions 

 
ubzen:

Try coding with smaller functions. It makes life easier.

The above function returns the Order_Type of the last order within the Trade_Pool which also matches the Symbol provided.

-It does not exclude Pending Orders.

-It does not include all Symbols.

-It filters by magic# which is global [recommended].

-It does not sort orders by Time.

-It does not Print Fail_Messages or Error#. 

 Rename, customize or modify functions, but make extensive use of them. This one provided as sample only.


Thank you for your advise ubzen. Regarding my issue o open alternate orders have any clue that could put me in the right direction?

Best Regards

Luis 

 
luisneves:


Thank you for your advise ubzen. Regarding my issue o open alternate orders have any clue that could put me in the right direction?

Best Regards

Luis 

Yeah, re-write the code using function.
Reason: