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

 

Para un probador esto

OrderSend

lo hará e incluso funcionará en servidores rápidos, pero si no es un probador es mejor hacerlo según la documentación :)

 
Chicos, necesito ayuda, hace unos días que no puedo hacer los cambios necesarios en el siguiente código:
void start()
{
   StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); 
   
   // Определение направления пересечения мувингов
   if (Init) InitMetod(); 
   
   // Трейлинг стоп открытых позиций
   if (Trailing != 0 ) RealTrailOrder(TrailStop, TrailStep, StopLevel, MagicNumber);
   
   // Ожидание нового бара на графике
   if(timeprev == Time[0]) return;
   timeprev = Time[0];
   
   // Открытие ордера по методу Пуриа
   CheckForOpen();
}
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen() // Открытие ордера по методу Пуриа
{
   double malw,mas1,mas2,macd;
   int    res;  
   // Считывание параметров индикаторов
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,0);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,0);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,0);
   macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,0);
  
   // Проверяем положение мувмнгов
   if(malw>mas1 && malw>mas2  && OrderSell)
     {
     OrderBuy=true;
     OrderSell=false;
     Order=true;
     }
   
   if(malw<mas1 && malw<mas2  && OrderBuy)
     {
     OrderBuy=false;
     OrderSell=true;
     Order=true;
     }

   // Открываем ордер Buy
   if(macd>0 && OrderBuy && Order)
     {
     res=OrderSend(Symbol(),OP_BUY,Lots(),Ask,Slip,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",MagicNumber,0,Blue);
     Order=false;
     return;
     }     
   // Открываем ордер Sell   
   if(macd<0 && OrderSell && Order)
     {
     res=OrderSend(Symbol(),OP_SELL,Lots(),Bid,Slip,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MagicNumber,0,Red);
     Order=false;
     return;
     }
 
}  
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double Lots()  // Расчет объема лота
{
   double Lots;
   if (Lot > 0) return(Lot);
   Lots=AccountFreeMargin()/5000;
   Lots=MathMin(15,MathMax(0.01,Lots));
   if(Lots<0.1) Lots=NormalizeDouble(Lots,2);
   else 
     {
     if(Lots<1) Lots=NormalizeDouble(Lots,1);
     else       Lots=NormalizeDouble(Lots,0);
     }
   return(Lots);
}
//+------------------------------------------------------------------+
//| Init metod Puria function                                        |
//+------------------------------------------------------------------+
void InitMetod()  // Опредеоение начального пересечения мувингов
{
   double malw,mas1,mas2;
   malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,0);
   mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,0);
   mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,0);

   if((malw<=mas1 && malw>=mas2) || (malw>=mas1 && malw<=mas2))
     {
     Init=false;
     OrderBuy=true;
     OrderSell=true;
     }   
   return;
}

En realidad, lo que intenté pero no pude añadir aquí: hacer que el EA espere 4 precios de apertura de vela seguidos después de que todos los indicadores ( precios de apertura de vela) coincidan:


  1. 1. El precio de apertura de la 1ª vela - (5) sobre (75) y (85) + barra MACD abierta por encima de 0- 1 de 4 confirmaciones es;
    2. El precio de apertura de la 2ª vela - (5) sobre (75) y (85) + barra MACD abierta por encima de 0- 2 de 4 confirmaciones es;
    3.3. El precio de apertura de la 3ª vela - (5) por encima de (75) y (85) + barra MACD abierta por encima de 0- 3 de 4 confirmaciones sí;
    4. El precio de apertura de la 4ª vela - (5) por encima de (75) y (85) + barra MACD abierta por encima de 0- 4 de 4 confirmaciones- Abrir operación de compra en la misma vela (4ª).

La misma situación con las órdenes de venta, sólo que en la otra dirección deben abrirse los indicadores. Y hay un punto importante - si en, digamos, cualquier etapa de la 1 ª vela a la 4 ª, los indicadores cambian su posición(por ejemplo, en la 3 ª vela de apertura, la barra de MACD se abre por debajo de 0, o = 0) - entonces todo se restablece, porque las señales no se verificaron en la apertura de 4 ª vela en una fila.

Por favor, programadores experimentados, ¿qué hay que cambiar en el código para que estas condiciones funcionen? He probado muchas cosas, y no sé...

 
   if(malw>mas1 && malw>mas2  && OrderSell)

Como dicen, no te fíes de nuestra palabra.

OrderSell

No sé qué puede haber en él, comparte la lógica de la toma de decisiones en el código.

 

artem artem #:

El precio de apertura de la 1ª vela - (5) sobre (75) y (85) + barra MACD abierta sobre 0 - 1 de 4 confirmaciones sí;

2 El precio de apertura de la 2ª vela - (5) sobre (75) y (85) + barra MACD abierta sobre 0- 2 de 4 confirmaciones sí;

3 El precio de apertura de la 3ª vela - (5) sobre (75) y (85) + barra MACD abierta sobre 0- 3 de 4 confirmaciones es;

4 El precio de apertura de la 4ª vela - (5) por encima de (75) y (85) + barra MACD abierta por encima de 0- 4 de 4 confirmaciones- Abrir operación de compra en la misma vela (4ª).

    //+------------------------------------------------------------------+
    //| Expert tick function                                             |
    //+------------------------------------------------------------------+
    void OnTick()
      {
    //---
       if(CheckForOpen()==0)
         {
          if(OrderSend(Symbol(),OP_BUY,Lots(),Ask,Slip,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",MagicNumber,0,Blue)) Print("BUY OK");
         }
       if(CheckForOpen()==1)
         {
          if(OrderSend(Symbol(),OP_SELL,Lots(),Bid,Slip,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",MagicNumber,0,Red)) Print("SELL OK");
         }
      }
    //+------------------------------------------------------------------+
    //| Check for open order conditions                                  |
    //+------------------------------------------------------------------+
    int CheckForOpen() // Открытие ордера по методу Пуриа
      {
       double malw,mas1,mas2,macd;
       int    res=-1, buy=0, sell=0;
       // Считывание параметров индикаторов 3 свечи
       malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,3);
       mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,3);
       mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,3);
       macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,3);
       if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
       if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
       // Считывание параметров индикаторов 2 свечи
       malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,2);
       mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,2);
       mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,2);
       macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,2);
       if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
       if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
       // Считывание параметров индикаторов 1 свечи
       malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,1);
       mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,1);
       mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,1);
       macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,1);
       if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
       if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
       // Считывание параметров индикаторов 0 свечи
       malw=iMA(NULL,0,MovingPeriodLw,0,MODE_EMA,PRICE_CLOSE,0);
       mas1=iMA(NULL,0,MovingPeriodS1,0,MODE_LWMA,PRICE_LOW,0);
       mas2=iMA(NULL,0,MovingPeriodS2,0,MODE_LWMA,PRICE_LOW,0);
       macd=iMACD(NULL,0,15,26,1,PRICE_CLOSE,MODE_MAIN,0);
       if(malw>mas1&&malw>mas2&&macd>0) {buy+=1; sell=0;}
       if(malw<mas1&&malw<mas2&&macd<0) {buy=0; sell+=1;}
       
       if(buy ==4) res=0;
       if(sell==4) res=1;
       return(res);
      }
     
    malw

    Anotar un valor con otro, ¿nada? Dividir primer bloque = solución, segundo bloque = solución, comparar bloques.

     
    Volodymyr Zubov #:

    Anotar un valor con otro, ¿nada? Dividir primer bloque = solución, segundo bloque = solución, comparar bloques.

    ¿Esto está escrito para quién? o ¿para qué?
     
    Resulta que tienes
    malw
    en el código y ahí sale un error lógico.
     
    Volodymyr Zubov #:
    Resulta que tienes, en el código, un error lógico.
    Compruebe antes de escribir
     

    Vale, pero las variables se colapsarán si las usas así y entonces no sabrás qué son los "milagros"

     
    Volodymyr Zubov #:

    Vale, pero las variables se colapsarán si las usas así y entonces no sabrás qué son los "milagros".

    Si conoces otra opción, escríbela...

    Puedes ayudar a la gente).

    Razón de la queja: