open opposite order at precise value

 

Hi all,

  This ea have a strategy that  open an opposite order at a precise distance. The issue is that it opens the order but many times with a different distance that it should.

Below is the code that ope the opposite order, could anyone show me where I'm wrong ?

 Thanks in advance for any support

Luis 

 

extern double OppositeDistance    =   2; 

 

void OpenOppositeOrder()
    {     
 int Op;  
   for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--)
      {//
      if(!OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES))continue;          
         {//
         if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)           
            {//16
             Op = OrderType();
             RefreshRates();            
            if(Op == OP_BUY && Bid <= (OrderOpenPrice() - (OppositeDistance*pips2dbl)) && SellAllowed)
           
               {//  
                while(IsTradeContextBusy()) 
                      Sleep(10);
                      RefreshRates();                             
                SellTicket = OrderSend(Symbol(), OP_SELL, MLots, Bid, Slippage*pips2points, 0, 0, "Open Opposite Sell Order", MagicNumber, 0, Red);
                if(SellTicket > -1) 
                  {//
                  BuyAllowed=true;SellAllowed=false;                                          
                  Print("Opposite Sell order placed # ", SellTicket);
                  AddLimitsSell();
                  return;
                  }//
               else
                  {//
                  Print("Opposite Sell Order Failed,order number:",OrderTicket(),"Error:",GetLastError());
                  }//
                }// 
                RefreshRates();           
            if(Op == OP_SELL && Ask >= (OrderOpenPrice() + (OppositeDistance*pips2dbl)) && BuyAllowed)
              
               {//  
               while(IsTradeContextBusy()) 
                    Sleep(10);
                         RefreshRates();                                
               BuyTicket = OrderSend(Symbol(), OP_BUY, MLots, Ask, Slippage*pips2points, 0, 0, " Open Opposite Buy Order", MagicNumber, 0, Green); 
               if(BuyTicket > -1)
                  {//
                  BuyAllowed=false;SellAllowed=true;                                                          
                  Print("Opposite Buy order placed # ", BuyTicket);                  
                  AddLimitsBuy();
                  return;
                  }//
               else
                  {//  
                  Print("Opposite Buy Order Failed, order number:",OrderTicket(),"Error:",GetLastError());
                  }//   
               }//
            }//
         }//    
      }//      
    }//
 

you are wrong in your thinking that it  opens an opposite order at a precise distance

Ask and Bid can change every tick and you send a command for OP_BUY or  OP_SELL so there is no precise distance 

 
deVries:

you are wrong in your thinking that it  opens an opposite order at a precise distance

Ask and Bid can change every tick and you send a command for OP_BUY or  OP_SELL so there is no precise distance 


Hi deVries,

 Thank you for your prompt response to my issue.

You are right. I though on that, but as I'm an ignorant in these mql issues was afraid that the code was wrong. So, just for clarification, there is no way to get an order open at a precise value ?

 Best regards

Luis 

 
luisneves: there is no way to get an order open at a precise value ?
Correct. Even using a stop or limit becomes a market when triggered.
Reason: