Cualquier pregunta de los recién llegados sobre MQL4 y MQL5, ayuda y discusión sobre algoritmos y códigos - página 39

 
trader781:
No sé cómo explicarlo. Pero sin duda es una obra maestra.
Te digo que aquí les gusta ser sarcásticos). Trishkin se ofendió por eso. Dijo que iba a buscar ayuda con el código.
 
Movlat Baghiyev:
Te digo que aquí les gusta ser sarcásticos ))) Trishkin también se ofendió. Dijo que el código ayudará.

Soy tan nuevo como tú pero incluso yo tengo muchas preguntas

for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,¡SELECT_BY_POS)==true)
{
if(OrderSymbol()!=Símbolo() ||¡OrdenNúmeroMágico()!=Magic) continuar;
si(OrderType()==OP_BUY||OrderType()==OP_SELL) p++;
if(OrderType()==OP_BUYSTOP)
if(signal_bue)OrderDelete(OrderTicket());
si no b++;
si(OrderType()==OP_SELLSTOP)
si(signal_sell)OrderDelete(OrderTicket());
si no s++;
}

}

1) ¿dónde has conseguido b++?

2) ¿dónde has conseguidos++?

3)si(señal_bue) es ¿qué más?

Y el resto del código. Perdona si te he ofendido.

 
Probablemente sea la forma correcta de hacerlo.
//+------------------------------------------------------------------+
//|                                                      ОТЛОЖКИ.mq4 |
//+------------------------------------------------------------------+
extern double StopLoss     = 100; //Стоплосс ордера  
extern double TakeProfit   = 150; //Тейкпрофит ордера
extern double TrailingStop = 100; // трал
extern int    Delta        = 100; //Расстояние от цены для установки ордера
extern double LOT          = 0.1; //Объём позиции
extern int    Magic        =2;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  if (TrailingStop!=0) Trailing();
  
   //ИНДИКАТОР RSI
   double RSI0=iRSI(NULL,0,5,PRICE_CLOSE,0);
   double RSI1=iRSI(NULL,0,5,PRICE_CLOSE,1);
  
   int b = 0, s = 0, p = 0, res = 0;

   double BuyPrice=Ask+Delta*Point;
   double SellPrice=Bid-Delta*Point;
  
   for (int i=0; i<OrdersTotal(); i++)
    {
     if (OrderSelect(i, SELECT_BY_POS)==true)
      {
        if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) p++;
        if (OrderType()==OP_BUYSTOP)
        {
           if(RSI0<50&&RSI1>50)
                OrderDelete(OrderTicket());
            else
                b++;
        }
        if (OrderType()==OP_SELLSTOP)
        {
           if(RSI0>50&&RSI1<50)
                OrderDelete(OrderTicket());
              else
                s++;
        }
      }
    }

   double SL,TP; // < !!!!!!!!! эти переменные не используются, можно удалить

//---- buy stop
   if(RSI0>50&&RSI1<50 && p<1 && b<1) // < !!!!!!!!!
     {
      res=OrderSend(Symbol(),OP_BUYSTOP,LOT,BuyPrice,0,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,"ОТЛОЖКИ",Magic,OP_SELLSTOP,Blue);
     }        
//---- sell stop  
   if(RSI0<50&&RSI1>50 && p<1 && s<1) // < !!!!!!!!!
     {
      res=OrderSend(Symbol(),OP_SELLSTOP,LOT,SellPrice,0,SellPrice+StopLoss*Point,SellPrice-TakeProfit*Point,"ОТЛОЖКИ",Magic,OP_BUYSTOP,Red);
     }
//----
   return(0);
}
 
Movlat Baghiyev:
Te digo que aquí les gusta ser sarcásticos). Y Trishkin se ofendió por ello. Dijo que me ayudaría con el código.

Así es más sencillo:

void OrderDelete_(int Type)
  {
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS)==true)
        {
         if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
         if(OrderType()==Type)
            OrderDelete(OrderTicket());
        }
     }
  }

Está en algún lugar fuera de la función void OnTick().

if (сигнал_bue) OrderDelete_(OP_SELLSTOP);

if (сигнал_sell)OrderDelete_(OP_BUYSTOP);

Y esto es en el cuerpo de la función void OnTick().

 
Alekseu Fedotov:


Y esto está en el cuerpo de la función void OnTick()

Por favor, haga correcciones en el código
 
trader781:

De acuerdo.

Terminé lo que pude. La descripción está hecha. El propósito es entender por qué no funciona como quiero.

Hay otra cosa dentro del bloque if(). ¿Realmente se pretendía que fuera así?

Además. La función Counts() acepta una variable global no inicializada count que, además, se define de nuevo dentro de la función.

La función Counts() cuenta las órdenes pero las compara con algún ticket que cambia varias veces en la función principal. Pero el valor del billete es el mismo durante la operación de la función. Entonces, ¿cuántos pedidos calculará la función? ¿Es más de uno?

En esta forma, esta función no necesita argumentos, sólo hay que llamarla y dejar que devuelva el resultado.

Siguiente. La función FindLastOType() es de nuevo una comparación con el ticket. ¿Puede garantizar que se compara con un billete válido? ¿No es más sencillo interrumpir el bucle cuando se encuentra la primera orden con el número y el símbolo mágico necesarios y devolver entonces el tipo de orden?

Lo mismo con FindLastOrderOpenPrice() y FindLastLot().

La función ModifyOrders() me horrorizó tanto que no la miré durante mucho tiempo para evitar pesadillas por la noche...

 
Movlat Baghiyev:
Por favor, haga correcciones en el código

Pruébalo ^_~

extern double StopLoss     = 100; //Стоплосс ордера  
extern double TakeProfit   = 150; //Тейкпрофит ордера
extern double TrailingStop = 100; // трал
extern int    Delta        = 100; //Расстояние от цены для установки ордера
extern double LOT          = 0.1; //Объём позиции
extern int    Magic        =2;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer


//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer


  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
  int  res = 0;

//ИНДИКАТОР RSI
   double RSI0=iRSI(NULL,0,5,PRICE_CLOSE,0);
   double RSI1=iRSI(NULL,0,5,PRICE_CLOSE,1);

   double BuyPrice=Ask+Delta*Point;
   double SellPrice=Bid-Delta*Point;
  
//---- buy stop
   if(RSI0>50&&RSI1<50 && Number(OP_BUYSTOP)<0 && Number(OP_BUY)<1) // < !!!!!!!!!
     {
      res=OrderSend(Symbol(),OP_BUYSTOP,LOT,BuyPrice,0,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,"ОТЛОЖКИ",Magic,OP_SELLSTOP,Blue);
     }        
//---- sell stop  
   if(RSI0<50&&RSI1>50 && Number(OP_SELLSTOP)<0 && Number(OP_SELL)<1) // < !!!!!!!!!
     {
      res=OrderSend(Symbol(),OP_SELLSTOP,LOT,SellPrice,0,SellPrice+StopLoss*Point,SellPrice-TakeProfit*Point,"ОТЛОЖКИ",Magic,OP_BUYSTOP,Red);
     }
//----  
  
  
if (RSI0>50&&RSI1<50) OrderDelete_(OP_SELLSTOP);

if (RSI0<50&&RSI1>50)OrderDelete_(OP_BUYSTOP);

  }

//+------------------------------------------------------------------+
void OrderDelete_(int Type)
  {
  bool  r;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS)==true)
        {
         if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
         if(OrderType()==Type)
          r = OrderDelete(OrderTicket());
        }
     }
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int Number(int Type)
  {
  int kp=0;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS)==true)
        {
         if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
         if(OrderType()==Type)
            kp++;
        }
     }
  return(kp);  
  }
//+------------------------------------------------------------------+
 
Alekseu Fedotov, gracias. Que Dios te bendiga.
 
Vitalie Postolache:

Hay otra cosa dentro del bloque if(). ¿Realmente tenía que ser así?

Además. La función Counts() acepta una variable global no inicializada, count, que también se declara de nuevo en la propia función.

La función Counts() cuenta las órdenes pero las compara con algún ticket que cambia varias veces en la función principal. Pero el valor del billete es el mismo durante la operación de la función. Entonces, ¿cuántos pedidos calculará la función? ¿Es más de uno?

En esta forma, esta función no necesita argumentos, sólo hay que llamarla y dejar que devuelva el resultado.

Siguiente. La función FindLastOType() vuelve a ser una comparación con la entrada. ¿Puede garantizar que se compara con un billete válido? ¿No es más sencillo interrumpir el bucle cuando se encuentra la primera orden con el número y el símbolo mágico necesarios y devolver entonces el tipo de orden?

Lo mismo con FindLastOrderOpenPrice() y FindLastLot().

La función ModifyOrders() me aterrorizó tanto que no la miré durante mucho tiempo para evitar pesadillas por la noche...

Corrección

No hay otra forma de ponerlo en otro sitio, serán parámetros erróneos

Tiene que tener en cuenta la más reciente

Intentaré cambiarlo.

Intenté utilizar la función estándar OrderModify(), pero se bloquea si muevo un montón de órdenes simultáneamente y constantemente

Gracias por la crítica.

 
spoiltboy:
Sí, es un error de imprenta en el soporte. El resto de la pregunta es válida.

bool condition;

if(condition) {}

equivale a

if(condition==true) {}

и

if(!condition) {}

es igual a

if(condition==false) {}

Simplemente es más corto y más familiar.

Razón de la queja: