Doubts about BuyLimit and BuyStop (pending operations)

 

I make a EA to learn how pending operations works. This EA create a buyLimit and a buyStop simultaneous. 

When I run the code, both operations are triggered (by log) but the operations tab is pending and the log price values are wrong (the Market price was upper 3150, but the log shows prices around 2800). I'm doing some wrong?



#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>

CTrade trade;
CSymbolInfo symbolInfo;
CAccountInfo accInfo;
int counter = 0; 
bool finished = false;
ulong magicNum = 123456;
bool pending = false;


int OnInit(){
   trade.SetExpertMagicNumber(magicNum);
   symbolInfo.Name(_Symbol);
   if(!symbolInfo.IsSynchronized()){
      printf(__FUNCTION__+": Symbol is not syncronized!");
      return INIT_FAILED;
   }
   if(!accInfo.TradeAllowed()){
      printf(__FUNCTION__+": Trade is not allowed!");
      return INIT_FAILED;
   }

   if(!accInfo.TradeExpert()){
      printf(__FUNCTION__+": ExpertAdvisor is not allowed!");
      return INIT_FAILED;
   }
   return INIT_SUCCEEDED;
}

void OnTick(){
   if(finished) return;

   double price = SellPrice() - 300;
   double sl = price - 5;
   double tp = price + 5;
   if(trade.BuyStop(1, price, _Symbol, sl, tp)){
      if(trade.ResultRetcode() == 10008 || trade.ResultRetcode() == 10009){
          PrintFormat("BUYSTOP Ticket: %d", trade.ResultOrder());
          pending = true;
      } else {
         PrintFormat("%s: Error: %d(%s)",__FUNCTION__, trade.ResultRetcode(),trade.ResultRetcodeDescription());
         return;
      }
   } else {   
      PrintFormat("%s: Error: %d", __FUNCTION__, GetLastError());
      return;
   }
   
   if(trade.BuyLimit(1, price, _Symbol, sl, tp)){
      if(trade.ResultRetcode() == 10008 || trade.ResultRetcode() == 10009){
          PrintFormat("BUYLIMIT Ticket: %d", trade.ResultOrder());
          pending = true;
      } else {
         PrintFormat("%s: Error: %d(%s)",__FUNCTION__, trade.ResultRetcode(),trade.ResultRetcodeDescription());
         return;
      }
   } else {   
      PrintFormat("%s: Error: %d", __FUNCTION__, GetLastError());
      return;
   }
   
   finished = true;
}

 /*
 Gets the current price to sell
 */
 double SellPrice(){
     symbolInfo.RefreshRates();
     double value = symbolInfo.Ask();
     if(value == 0) value = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
     if(value == 0){
         MqlTick tick;
         ResetLastError();
         if(SymbolInfoTick(_Symbol,tick)){
             value = tick.ask;
         } else {
             PrintFormat("%s: Error: %d",__FUNCTION__, GetLastError());
         }
         if(value == 0) value = tick.last - SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);      
     }
     return value;
 }



All images were taken after execution finished:

logs

Operations:

operations

Deals:

history

Orders:

orders

 

There is obviously something weird.

Which broker is this ? Is this the data from that broker (not a custom symbol, just to be sure) ?

 

The broker is  demo.mt5.xpi.com.br:443 and the symbol is the WDO$D provided by the broker (not a custom symbol)