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);
}
//+------------------------------------------------------------------+
- docs.mql4.com
- Aplicaciones de trading gratuitas
- 8 000+ señales para copiar
- Noticias económicas para analizar los mercados financieros
Usted acepta la política del sitio web y las condiciones de uso
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);
}
//+------------------------------------------------------------------+