Download MetaTrader 5

SELL gone through as a BUY order

To add comments, please log in or register
Have you developed an application? Publish it in Code Base!
Armand
48
Armand 2012.01.25 21:09 

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);
   }
Andrei Moraru
1157
Andrei Moraru 2012.01.26 12:41  
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
Armand
48
Armand 2012.01.28 08:25  
Oh! Thank you, that worked.
To add comments, please log in or register