Error '(' - function definition unexpected - page 2

 

Hi RaptorUk,

Thank you for the corrections!

Two issues;

Is there any function that takes the order close by the TrailingStop that close all the orders ?

The code I have don't close the orders, even when the OrderTakeProfit is activated by the TrailingStop. 

int OrdType, GLError;
    RefreshRates();     
    for(int OrderPos = OrdersTotal()-1; OrderPos >= 0; OrderPos--)
       {//29 
       if(OrderSelect(OrderPos, SELECT_BY_POS, MODE_TRADES)
          && OrderMagicNumber()== MagicNumber && OrderSymbol()== Symbol()
          && OrderProfit() >= OrderTakeProfit())
          {//30
         OrdType = OrderType();
         if(OrdType == OP_BUY || OrdType==OP_SELL)
            {//31
            if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(),RealSlippage, Yellow))
               GLError = GetLastError();
            }//31
                     
           if(!ObjectDelete("highline"))
               GLError = GetLastError();
           }//30
         }//29 

 Other issue have to do with a way to identify what is the type of the open order in a way just to permit that next order will be  opposite type.

I've introduce some code to avoid multiple orders to open but now because the  order ticket is present is not possible to open other order of same type.

Suppose that order 1 is a buy then order 2 will be a sell after that if I need to open another buy  that is not possible because the order ticket is from order 1 is present. How can one identify just the last order type?

 

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

thank you

Luis 

 
luisneves:

Hi RaptorUk,

Thank you for the corrections!

Two issues;

Is there any function that takes the order close by the TrailingStop that close all the orders ?

The code I have don't close the orders, even when the OrderTakeProfit is activated by the TrailingStop.  

I don't understand what you are trying to do here ?  You have this code  . . . 

if(OrderSelect(OrderPos, SELECT_BY_POS, MODE_TRADES)
          && OrderMagicNumber()== MagicNumber && OrderSymbol()== Symbol()
          && OrderProfit() >= OrderTakeProfit())

 OrderProfit() is  "Returns the net profit value (without swaps or commissions) for the selected order."  it is a value in currency,  it is not a price.   You are comparing this to the order Take Profit price  . . .   this cannot make sense.

 
luisneves:


 Other issue have to do with a way to identify what is the type of the open order in a way just to permit that next order will be  opposite type.

I've introduce some code to avoid multiple orders to open but now because the  order ticket is present is not possible to open other order of same type.

Suppose that order 1 is a buy then order 2 will be a sell after that if I need to open another buy  that is not possible because the order ticket is from order 1 is present. How can one identify just the last order type?

OK,  I think I have a better idea of what yo are trying to do after I have read the comment you made in your code,  you said . . .

//Open Opposite Order (open opposite order if last order not reach TakeProfit)
   //Here every time the open order bounce back more than the Returndist an opposite order should open.
   //Some Problems here because every time the price picks the OrderOpenPrice another order is opening.
   //I'm looking to get a way for the code "look" the direction of the order that is open and just to open an opposite. 

So you have an Order,  lets call it  Fred  and it's a OP_BUY  each time  Fred bounces back from the TP by at least  Returndist you want to open a new OP_SELL . . . .  this is very difficult and involved to do.  If price is currently further than Returndis from TP how will you know if it is because price just hasn't got as far as the TP yet or if it got close and returned ?  and you need to make this determination several times  . . . and each time place a new OP_SELL.

 

Hi RaptorUk,

Thank you for your time to look for my issues.

So, as the Ea is working now when an order is open and the price goes up( buy) or down (sell) 5 pips the TrailingStop moves to 3 pips ,then if price bounce back the order will close. that is working fine.

Here what I'm looking for is to close any open order when an open order is closed by the TrailingStop.

 Regarding the multiple openings each time the price goes up or down crossing the OrderOpenPrice (plus or minus Returndist) I've introduced some code to limit this. What is happening now and because the EA "see" the ticket it will no open a same order type.

 Here I need to have the possibility to show the last order type (that is there already) but limit that to a behavior  that  sell (or buy) order should open only one time as long it not go down or up the last opposite order OrderOpenPrice.

In attach is the code where, besides to eliminate  a part of code that I think is redundant, contains the code to limit multiple openings. I've marked where I'm lost with the proper manner to close all open orders when the order close by means of TrailingStop. The redundant code eliminated is at the end.

Thank you in advance for any clue.

Best Regards

luis 

Files:
 
Sorry Luis,  each time I try to look at your code I have to sort the indenting,  I did it yesterday and posted the changes,  now your indenting is going haywire again,  I don't mind trying to help but I'm not going to waste my time continually sorting indenting so I can read "your" code. 
 

Hi RaptorUK,

 

Sorry for the mess. When try to get some modifications related to my last issues forgot to get that updated.

In attach is the file with the indenting by your advise. 

I've marked where code have been modified and where is the problem with the close by mean of the TrailingStop. 

Best Regards

Luis 

Files:
 

Hi RaptorUK,

 Just to say that the issue with the close of all open orders when the open order close by mean of TrailingStop is working.

The code is now as;

 

// Close All Positons if last order close

int OrdType, GLError;
    RefreshRates();
    
    for(int Closed = 0; Closed <= OrdersTotal()-1; Closed ++)
       {//29
       OrderSelect(Closed,SELECT_BY_POS,MODE_HISTORY);
       if(OrderCloseTime()!= 0)
                            
    for(int OrderPos = OrdersTotal()-1; OrderPos >= 0; OrderPos--)       
       if(OrderSelect(OrderPos, SELECT_BY_POS, MODE_TRADES)
          && OrderMagicNumber()== MagicNumber && OrderSymbol()== Symbol())                                       
          {//30
          OrdType = OrderType();
          if(OrdType == OP_BUY || OrdType==OP_SELL)
            {//31
            if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(),RealSlippage, Yellow))
               GLError = GetLastError();
            }//31           
            if(!ObjectDelete("highline"))
               GLError = GetLastError();
            }//30
        
           if(GLError > 0) Print("Error Closing/Deleting Order, error # ", GLError, " for ticket: ", OrderTicket());           
      }//29
    return(0);
    }//0

 Hope the indenting is ok...

Now just have to work out the issue to get opening orders alternatively. 

Luis 

 
RaptorUK: Sorry Luis,  each time I try to look at your code I have to sort the indenting,   
Luis, don't insert tabs, use spaces only
 

Hi WHRoeder,

Thank you for your attention to my issues and for the advise. Nevertheless could you mark where the problem is ?

 Best Regards

Luis 

 

Hi RaptorUK,

Have one issue,

Using the following code to get the close of all open orders after the last one have been closed by mean of TrailingStop works fine in Tester, but when in Demo don't close others than the order closed by TrailingStop. Could you tell me where I'm wrong ?

Best Regards

Luis 

 

// Close all open positons when last order have been closed

  int OrdType, GLError;
  double OrderClosed;
  RefreshRates();
    
  for(int Closed = 0; Closed <= OrdersTotal()-1; Closed ++)      
     if(OrderSelect(Closed,SELECT_BY_POS,MODE_HISTORY)
        && OrderMagicNumber()== MagicNumber
        && OrderSymbol()== Symbol())
        {//29
        OrderClosed=OrderCloseTime();
        if(OrderClosed!=0)
           {//30                                  
  for(int OrderPos = OrdersTotal()-1; OrderPos >= 0; OrderPos--)       
     if(OrderSelect(OrderPos, SELECT_BY_POS, MODE_TRADES)
        && OrderMagicNumber()== MagicNumber 
        && OrderSymbol()== Symbol())                                       
        {//31
        OrdType = OrderType();
        if(OrdType == OP_BUY || OrdType==OP_SELL)
           {//32
           if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(),RealSlippage, Yellow))
               GLError = GetLastError();
           }//32
                      
          if(!ObjectsDeleteAll(0,"highline"))
              GLError = GetLastError();
          }//31
       }//30
     }//29 
       
  if(GLError > 0) Print("Error Closing/Deleting Order, error # ", GLError, " for ticket: ", OrderTicket());           
  return(0);
  }//0       
Reason: