I can not place Stop Loss and not Take Profit to open an order.

 
can someone explain me by that Stop Loss and Take Profit do not work in the execution of the order?

what I have is the following:

 

long order_magic=444444;
extern double Lots = 0.1;     
double  takese1  = 50;        // valor tp 
double  stopse1  =50;         // valor sl 
double tp;     double sl;
ulong ticket;  
int valor=0;

void OnTick()  
  { 

   sl=(SymbolInfoDouble(Symbol(),SYMBOL_ASK))-stopse1*_Point; 
   tp=(SymbolInfoDouble(Symbol(),SYMBOL_ASK))+takese1*_Point;
   
   MqlTradeRequest request={0}; 
   request.action= TRADE_ACTION_DEAL;           // definir una orden inmediata
   request.magic=order_magic;                   // ORDER_MAGIC
   request.order=ticket;                        // Ticket de la orden
   request.symbol=_Symbol;                      // instrumento
   request.volume=Lots;                         // volumen de 0.1 lote
   request.sl=sl;                               // Stop Loss sin especificar   Ask-stopse1*_Point; 
   request.tp=tp;                               // Take Profit sin especificar  Ask+takese1*_Point;
   request.deviation=1;                         // Desviación máxima aceptable del precio solicitado
   request.type= ORDER_TYPE_BUY;                // Tipo de orden BUY
   request.type_filling= ORDER_FILLING_RETURN;  // Tipo de ejecución de orden
   MqlTradeResult result={0};  


   if(valor==0){ valor=1; OrderSend(request,result);  }

 } // fin void OnTick()

 

 

Hi Dragon,

As I read, for the market(and exchange) execution types the sl and tp variables are ignored,

therefore you should open your position and immediately after set the sl and tp with the specific action

request.action = TRADE_ACTION_SLTP;

Another thing is that you should set also the price variable, for the buy the ask price is to be setted and the order number(ticket) is useless for the market order.

Hope this helps ;) 

 
DragonMQL:
can someone explain me by that Stop Loss and Take Profit do not work in the execution of the order?

what I have is the following:

What is the Stoplevels for the symbol you are using ?
 
angevoyageur:
¿Cuál es la Stoplevels para el símbolo que está utilizando?
I'm using EURUSD, the stop-loss minimum is 48, I in my test put it at 50.
 
DragonMQL:
I'm using EURUSD, the stop-loss minimum is 48, I in my test put it at 50.
  • You have to check to returned value of OrderSend(), you also have to check the value of result.retcode. (You can also read the documentation in Spanish)
  • Did you check what launic told you ?  What execution mode are your broker using (Market/Exchange or Instant)?
  • Do you have some error in the log ?
 
angevoyageur:
  • Usted tiene que comprobar el valor devuelto de OrderSend (), también hay que comprobar el valor de result.retcode. (También puedes leer la documentación en español )
  • ¿Has comprobado lo launic te dijo? ¿Qué modo de ejecución se utiliza su corredor ( Mercado / Exchange o instantánea )?
  • ¿Tiene algún error en el registro?
OK, voy has trying to figure all that out and I call again.
Thanks for the help.
Reason: