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

[Eliminado]  
Vitaly Muzichenko:

Se comprueba en una barra existente double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);

El precio sube, hay un cruce del nivel 70 y se entra en la operación. En el hecho de cerrar la barra, ya se ve que el RSI está más bajo, pero antes estaba más alto, y luego volvió por debajo del nivel.

Haga la comprobación en una barra cerrada, entonces esto no sucederá, y las entradas serán en una señal confirmada:

double rsi=iRSI(_Símbolo,0,RSIperiod,PRECIO_CIERRE,1);

double rsi1=iRSI(_Símbolo,0,RSIperiod,PRECIO_CIERRE,2);

Ya veo. Gracias.
[Eliminado]  

Lo escribí así: (probablemente equivocado).

double tp,sl,OrderBuy=0,OrderSell=0;
double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   OrderBuy=0; OrderSell=0;
   for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
        {
         if(OrderType()==OP_BUY)
           {
            OrderBuy++;                      //Кол. покупок
           }
         if(OrderType()==OP_SELL)
           {
            OrderSell++;                     //Кол. продаж
           }
        }
     }
   double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
   double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
   double rsi2=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);
//+------------------------------------------------------------------+

   double StopLossLevel;
   double TakeProfitLevel;
   if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
   if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;

   tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
   slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);

   tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
   slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
   if(OrderBuy==0 && rsi>Urov_70 && rsi1<Urov_70 && rsi2<Urov_70)
     {
      tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
      if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
     }
   if(OrderSell==0 && rsi<Urov_30 && rsi1>Urov_30 && rsi2>Urov_30)
     {
      tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
      if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
     }
  }
//+------------------------------------------------------------------+

Resultado: Las órdenes se abren cuando no hay cruce...


 
Ibragim Dzhanaev:

Lo escribí así: (probablemente equivocado).

        }
     }
   double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
   double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
   double rsi2=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);
//+------------------------------------------------------------------+

   double StopLossLevel;

El resultado es el siguiente: las órdenes se abren cuando no hay cruce...

¿Por qué necesita la barra actual?double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0); ?

Su código reescrito cumple exactamente la misma condición que antes - en la barra cero el precio cruzó el nivel y se abrió una operación, más tarde el precio regresó y el RSI volvió por debajo del nivel, como resultado, después de cerrar la barra no hay señal.

No utilice la barra de cero en el cálculo.

[Eliminado]  
Vitaly Muzichenko:

¿Por qué necesita la barra actual?double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0); ?

Su código reescrito cumple exactamente la misma condición que antes, en la barra cero el precio cruzó el nivel y se abrió una operación, más tarde el precio regresó y el RSI volvió por debajo del nivel, como resultado, después de cerrar la barra no hay señal.

No utilice la barra de cero en el cálculo.

Funciona. Gracias.
[Eliminado]  

¿Puede decirme por qué da un error?

double tp,sl,OrderBuy=0,OrderSell=0;
double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   OrderBuy=0; OrderSell=0;
   for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
        {
         if(OrderType()==OP_BUY)
           {
            OrderBuy++;                      //Кол. покупок
           }
         if(OrderType()==OP_SELL)
           {
            OrderSell++;                     //Кол. продаж
           }
        }
     }
//double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
   double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
   double rsi2=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);
//+------------------------------------------------------------------+

   double StopLossLevel;
   double TakeProfitLevel;
   if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
   if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;

   tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
   slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);

   tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
   slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
   if(CountBuy()+CountSell()==0 && rsi1>Urov_70 && rsi2<Urov_70)
     {
      tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
      if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
     }
   if(CountBuy()+CountSell()==0 && rsi1<Urov_30 && rsi2>Urov_30)
     {
      tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
      if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
     }
  }
//+------------------------------------------------------------------+
int CountBuy()
  {
   int count=0;
   for(int trade=OrdersTotal()-1; trade>0; trade--);
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUY)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
int CountSell()
  {
   int count=0;
   for(int trade=OrdersTotal()-1; trade>0; trade--);
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
 
Ibragim Dzhanaev:

¿Puede decirme por qué da un error?

double tp,sl,OrderBuy=0,OrderSell=0;
double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   OrderBuy=0; OrderSell=0;
   for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
        {
         if(OrderType()==OP_BUY)
           {
            OrderBuy++;                      //Кол. покупок
           }
         if(OrderType()==OP_SELL)
           {
            OrderSell++;                     //Кол. продаж
           }
        }
     }
//double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
   double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
   double rsi2=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,2);
//+------------------------------------------------------------------+

   double StopLossLevel;
   double TakeProfitLevel;
   if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
   if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;

   tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
   slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);

   tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
   slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
   if(CountBuy()+CountSell()==0 && rsi1>Urov_70 && rsi2<Urov_70)
     {
      tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
      if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
     }
   if(CountBuy()+CountSell()==0 && rsi1<Urov_30 && rsi2>Urov_30)
     {
      tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
      if(tiket<0)Print("Ошибка открытия ордера № - ",GetLastError());
     }
  }
//+------------------------------------------------------------------+
int CountBuy()
  {
   int count=0;
   for(int trade=OrdersTotal()-1; trade>0; trade--);
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUY)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
int CountSell()
  {
   int count=0;
   for(int trade=OrdersTotal()-1; trade>0; trade--);
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
Por cierto.
for(int trade=OrdersTotal()-1; trade>0; trade--);
tiene que ser así
for(int trade=OrdersTotal()-1; trade>=0; trade--);
de lo contrario se perderá la última orden
 
Ibragim Dzhanaev:

¿Puede decirme por qué aparece un error?


   for(int trade=OrdersTotal()-1; trade>0; trade--);
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+

extra " ; "

int CountBuy()
  {
   int count=0;
   for(int trade=OrdersTotal()-1; trade>0; trade--);  <<<
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUY)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
int CountSell()
  {
   int count=0;
   for(int trade=OrdersTotal()-1; trade>0; trade--);  <<<
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
            count++;
        }
     }
   return(count);
  }

Y eso sería mejor, en este caso:

for(int trade=0; trade<OrdersTotal(); trade++)
[Eliminado]  
Sergey Gritsay:
Por cierto.
for(int trade=OrdersTotal()-1; trade>0; trade--);
tiene que ser así
for(int trade=OrdersTotal()-1; trade>=0; trade--);
o perderás el último pedido.
Gracias.
[Eliminado]  
Vitaly Muzichenko:

superfluo " ; "

int CountBuy()
  {
   int count=0;
   for(int trade=OrdersTotal()-1; trade>0; trade--);  <<<
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_BUY)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
int CountSell()
  {
   int count=0;
   for(int trade=OrdersTotal()-1; trade>0; trade--);  <<<
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber && OrderType()==OP_SELL)
            count++;
        }
     }
   return(count);
  }

Y eso sería mejor, en este caso:

for(int trade=0; trade<OrdersTotal(); trade++)
Gracias.
 

Hola a todos, ¿cómo puedo escribir la expresión

el quinto lote es igual a la suma de los lotes 1 y 4 de los pedidos

para encontrar el primero o el último de todos se puede encontrar a través de la definición del billete

Pero, ¿cómo encontrar alguna intermedia teniendo en cuenta los cambios constantes en la red actual?

Me refiero a que cada orden debe ser almacenada en algún lugar o de alguna otra manera

y ¿hay alguna diferencia?

entre

void OnTick()
  {
    if uslovie1==true   {...}
    if uslovie2==true   {...}
    if uslovie3==true   {...}
  }

И

void OnTick()
  {
     {
        if uslovie1==true
                   {...}
        else  if   {...}
        else  if   {...}
     }
  }