Error with SendOrder (Buy/Sell) for failed market buy 0.01 EURUSD tp: xxxx [Invalid stops]

 

Hi all,

I have a boring issue with the execution of order (Buy or Sell) that use the TP.  I know that's a common issue reading others threads but the code seems correct so don't know what i have mistake.  I'm going crazy because the error happen when thet TP is lower than 120 pips. :(


I paste function called and the code of the method.

SendOrder(MagicNumber,ORDER_TYPE_BUY,LotSize,"TP1",TP1);     //TP1 - GetIndicatorValue(14) error if offeset < 120
SendOrder(MagicNumber,ORDER_TYPE_BUY,LotSize,"TP2",TP2);    //TP2 - GetIndicatorValue(15)

Function SendOrder():

//+------------------------------------------------------------------+
void SendOrder(long const magic_number, ENUM_ORDER_TYPE const order_type, double lotSize, string comment,int offset = 50)
  {
//--- declare and initialize the trade request and result of trade request
   MqlTradeRequest request= {0};
   MqlTradeResult  result= {0};
//--- parameters of request
   request.action   =TRADE_ACTION_DEAL;                     //type of trade operation
   request.symbol   =Symbol();                              //symbol
   request.volume   =lotSize;                               //volume of 0.1 lot
   request.type     =order_type;                            //order type

   request.deviation=5;                                     //allowed deviation from the price
   request.magic    =magic_number;                          //MagicNumber of the order
   request.comment  =comment;
   
// order triggering price
   double point=SymbolInfoDouble(Symbol(),SYMBOL_POINT);          //value of point
   int    digits=(int)SymbolInfoInteger(Symbol(),SYMBOL_DIGITS);  //number of decimal places (eg. 5 EURUSD)

   if(order_type == ORDER_TYPE_BUY)
     {
      //request.price=SymbolInfoDouble(Symbol(),SYMBOL_ASK); //price for opening
      request.tp = NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_ASK)+offset*point,digits);
     }
   else
     {
      //request.price=SymbolInfoDouble(Symbol(),SYMBOL_BID); //price for opening
      request.tp = NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID)-offset*point,digits);
     }

//--- send the request
   if(!OrderSend(request,result))
     {
      PrintFormat("OrderSend error %d",GetLastError());     //if unable to send the request, output the error code
     }
   else
      PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
  }

I hope that some god person and better developer of me can help.

Have a nice day

Marcello

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trading is done by sending orders to open positions using the OrderSend() function, as well as to place, modify or delete pending orders. Each trade order refers to the type of the requested operation. Trading operations are described in the ENUM_TRADE_REQUEST_ACTIONS enumeration...
 
William Roeder:
Your code is unreadable. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum
          Messages Editor

Ciao Williamo, Done. I have updated the comment. Thanks

 
Marcello Campagna:

Hi all,

I have a boring issue with the execution of order (Buy or Sell) that use the TP.  I know that's a common issue reading others threads but the code seems correct so don't know what i have mistake.  I'm going crazy because the error happen when thet TP is lower than 120 pips. :(


I paste function called and the code of the method.

Function SendOrder():

I hope that some god person and better developer of me can help.

Have a nice day

Marcello

Hello,

I think mean 120 points not pips.

Any way.

First, check broker stop level.

Reason: