SELL gone through as a BUY order

 

I have a problem:

When I run this "SELL" trade request in the strategy tester, the journal reports it as a BUY order, and because of that the stop loss and take profits are swapped, resulting an [Invalid Stops] error.

   MqlTick price;

   MqlTradeRequest sellrequest;
   MqlTradeResult sellresult;


   SymbolInfoTick(Symbol(),price);
   CopyBuffer(hMA,0,0,2,MA);

   if((MA[1]-MA[0])>(9*0.00001))
   {
      StopLoss=price.bid+(11*0.00001);
      TakeProfit=price.bid-(10*0.00001);
      
      ZeroMemory(sellrequest);
      ZeroMemory(sellresult);
      
      sellrequest.action = TRADE_ACTION_DEAL;
      sellrequest.deviation = 10;
      sellrequest.magic = 6621376;
      sellrequest.order = ORDER_TYPE_SELL;
      sellrequest.price = NormalizeDouble(price.bid,_Digits);
      sellrequest.sl = price.bid+SL*10*Point();
      sellrequest.tp = price.bid-TP*10*Point();
      sellrequest.symbol = Symbol();
      sellrequest.volume = 0.1;
      sellrequest.type_filling = ORDER_FILLING_FOK;
      OrderSend(sellrequest,sellresult);
   }
 
sellrequest.order is for Order Ticket. sellrequest.type is what you need to assign ORDER_TYPE_SELL to.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 
Oh! Thank you, that worked.