Order Modify - page 2

 

I may be being stupid here but how about something simple like

if(ModifyOpenOrder(ticket,BuySell) < 0)
//
//
//
int ModifyOpenOrder(int ticket,string BuySell)
{  
   // Function Returns 1 for success, -1 for failure
   OrderSelect(ticket,SELECT_BY_TICKET);
      // Set SL and TP according to Buy or Sell signs
      if(BuySell == "Buy") { SL = OrderOpenPrice()-SL*Point; TP = OrderOpenPrice()+TP*Point; }
      if(BuySell == "Sell"){ SL = OrderOpenPrice()+SL*Point; TP = OrderOpenPrice()-TP*Point; }  
      
      if(OrderModify(ticket, OrderOpenPrice(),SL,TP,0,Blue) == true) 
         return(1);
      else
        { 
         Print("Error modifying order : ",GetLastError()); //<< Stupid simple idea!
         return(-1);
        }
}
 
deVries:

explain where did you do that after orderopening ??

Sorry for not explaining this very well.
int start()
{
              switch (TrendSignal)
              {
              case 1   : OpenOrders("Buy");  break; // if Trend = 1 (Buy)   
              case 2   : OpenOrders("Sell"); break; // if Trend = 2 (Sell)
              }  
} 

void OpenOrders(string BuySell)
{
// Trade Context Handling (https://www.mql5.com/en/articles/1412)
// Wait until the trade context is free and then occupy it globally (if an error occurs, leave it)
            if(_IsTradeAllowed() >= 0)
            {    // Trading Occupied Globally, check the terminal for activity
                 if(TradeIsBusy() < 0) 
                     return(-1); 
                 // Refresh the market info
                 RefreshRates();
                    
                      // Open orders using BuySell as criterion for OrderType
                    int ticket=OrderSend(Symbol(),intBuySell,LotSize(),BidAsk,3,0,0,"EA Order",Magic.Number,0,ColorCode);  //Open execution cannot include TP and SL, modify after execution
                        if(ticket<0)
                        {
                           Print("OrderSend failed with error #",GetLastError());
                        }else // Order was successful, Add SL and TP
                        {
                        if(ModifyOpenOrder(ticket,BuySell) < 0)
                           Print("OrderModify failed with error #",GetLastError());
                        }
                         
                 // Set the trade context back to free
                 TradeIsNotBusy();
                 return(0);
            }
}

int ModifyOpenOrder(int ticket,string BuySell)
{  
   // Function Returns 1 for success, -1 for failure
   OrderSelect(ticket,SELECT_BY_TICKET);
      // Set SL and TP according to Buy or Sell signs
      if(BuySell == "Buy") { SL = OrderOpenPrice()-SL*Point; TP = OrderOpenPrice()+TP*Point; }
      if(BuySell == "Sell"){ SL = OrderOpenPrice()+SL*Point; TP = OrderOpenPrice()-TP*Point; }  
      
      if(OrderModify(ticket, OrderOpenPrice(),SL,TP,0,Blue) == true) 
         return(1);
      else 
         return(-1);
}
 
SL = OrderOpenPrice()-SL*Point;

Assume you call the function correctly then look to above....

What is this doing ???

What is it doing the next trade ???

What is SL ???

TP same

 
deVries:

Assume you call the function correctly then look to above....

What is this doing ???

What is it doing the next trade ???

What is SL ???

TP same

GENIUS! Thanks a million. I understand completely now. I set SL and TP as globals via extern, then when another order is created the old SL value is re-called and is thus completely beyond the scope of price. That is why an OrderModify() would succeed and then fail later on.

Thanks a million.

Happy Trading DeVries

Reason: