¡Por Favor! 2 minutos... Hacer que este EA en vez de TP ponga SL dejando todo igual:

 

Gracias por ayudar. Necesito cambiar en el código la función de TP por SL... lo he intentado de varias maneras pero siempre se abre con TP, aunque ponga los cambios a SL o stoploss. ¡Ayuda!



extern double Lots = 0.01 ;

extern int max_trades = 200 ;

extern int grid_lines = 100 ;

extern double RangeMid = 126.5000 ;

extern double grid_separation = 0.0200 ;

extern double TP = 50 ;

   

int BarCount;

int Current;

bool TickCheck = False;

//+------------------------------------------------------------------+

//| expert initialization function                                   |

//+------------------------------------------------------------------+

int init() {


   return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function                                 |

//+------------------------------------------------------------------+

int deinit() {

   return(0);

}

//+------------------------------------------------------------------+

//| expert start function                                            |

//+------------------------------------------------------------------+

int start() {

 

   int Entertradebuy =0 ;

   int Entertradesell =0 ;

   double level ;

   

   if(OrdersTotal()<max_trades)

   {

  for (int i = 1; i<grid_lines; i++)

   

   {

   level=GlobalVariableGet("level") ;

   if (Ask == RangeMid - grid_separation*i && level != RangeMid - grid_separation*i)

   {

   GlobalVariableSet("level", RangeMid - grid_separation*i) ;

   Entertradebuy=1 ;

   Print(level," and ", RangeMid - grid_separation*i );

   }

   if (Bid == RangeMid + grid_separation*i && level != RangeMid + grid_separation*i)

   {

   GlobalVariableSet("level", RangeMid + grid_separation*i) ;

   Entertradesell=1 ; 

   Print(level," and ",RangeMid + grid_separation*i );

   }

   }

   }

  

   

   if(Entertradebuy==1)

   {

   double Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, 5, 0, Ask+TP*Point, "Buy(#" + 1 + ")", 1, 0, DodgerBlue) ;         

   }

   

   

   if(Entertradesell==1)

   {

   double Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, 5, 0, Bid-TP*Point, "Sell(#" + 1 + ")", 1, 0, DeepPink) ;

   }

   


   return(0);

}

//+------------------------------------------------------------------+

 

No soy de Mt4 pero en MetaQuotes generalmente la funcion de OrderSend tiene un input de funcion para el SL y otro para el TP, si pones 0 en el input del SL no pone SL, y lo mismo en el TakeProfit.

Mirate la descripción de la función aqui: https://docs.mql4.com/trading/ordersend


extern double Lots = 0.01 ;

extern int max_trades = 200 ;

extern int grid_lines = 100 ;

extern double RangeMid = 126.5000 ;

extern double grid_separation = 0.0200 ;

// extern double TP = 50 ;

extern double SL = 50;

   

int BarCount;

int Current;

bool TickCheck = False;

//+------------------------------------------------------------------+

//| expert initialization function                                   |

//+------------------------------------------------------------------+

int init() {


   return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function                                 |

//+------------------------------------------------------------------+

int deinit() {

   return(0);

}

//+------------------------------------------------------------------+

//| expert start function                                            |

//+------------------------------------------------------------------+

int start() {

 

   int Entertradebuy =0 ;

   int Entertradesell =0 ;

   double level ;

   

   if(OrdersTotal()<max_trades)

   {

  for (int i = 1; i<grid_lines; i++)

   

   {

   level=GlobalVariableGet("level") ;

   if (Ask == RangeMid - grid_separation*i && level != RangeMid - grid_separation*i)

   {

   GlobalVariableSet("level", RangeMid - grid_separation*i) ;

   Entertradebuy=1 ;

   Print(level," and ", RangeMid - grid_separation*i );

   }

   if (Bid == RangeMid + grid_separation*i && level != RangeMid + grid_separation*i)

   {

   GlobalVariableSet("level", RangeMid + grid_separation*i) ;

   Entertradesell=1 ; 

   Print(level," and ",RangeMid + grid_separation*i );

   }

   }

   }

  

   

   if(Entertradebuy==1)

   {

   //double Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, 5, 0, Ask+TP*Point, "Buy(#" + 1 + ")", 1, 0, DodgerBlue) ;   

double Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, Ask, 5, (Bid-SL)*Point, 0, "Buy(#" + 1 + ")", 1, 0, DodgerBlue) ;     

   }

   

   

   if(Entertradesell==1)

   {

   //double Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, 5, 0, Bid-TP*Point, "Sell(#" + 1 + ")", 1, 0, DeepPink) ;

double Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, Bid, 5, (Ask+SL)*Point, 0, "Sell(#" + 1 + ")", 1, 0, DeepPink) ;

   }

   


   return(0);

}

//+------------------------------------------------------------------+

OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function. At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price. If operation is performed with a...