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

 
-Aleks-:

Estoy tratando de encontrarle sentido. Así que, en su opinión, la opción correcta es SVA_03, ¿verdad?

Sí, supongo que sí. Pero _02 está definitivamente mal.
 
Dmitry Fedoseev:
Sí, supongo que sí. Pero _02 está definitivamente mal.

Hmmm... encontré un error en mí mismo, ahora casi no hay discrepancia, aquí está el original

//+------------------------------------------------------------------+
//|                                                       SVA_04.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property strict

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow

//---- input parameters
extern int RSIPeriod=14;
extern int Levl=50;
extern int TF=0;
//---- buffers
double MABuffer[];
double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
   IndicatorBuffers(1);
   SetIndexBuffer(0,MABuffer);
   SetIndexBuffer(1,PosBuffer);
   SetIndexBuffer(2,NegBuffer);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
//----
//---- name for DataWindow and indicator subwindow label
//   short_name="RSI("+IntegerToString(RSIPeriod)+")";
   short_name="RSI("+RSIPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   SetIndexLabel(1,"U");
   SetIndexLabel(2,"D");
   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive,sma,x,y,Pos,Neg;
//----
   if(Bars<=RSIPeriod) return(0);
   if(TF!=0)
     {
      string name=WindowExpertName();
      for(i=0; i<Bars-counted_bars+1; i++)
        {
         int barIndex=iBarShift(NULL,TF,Time[i],false);
         MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex);
        }
      return(0);
     }

   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      if(i==Bars-RSIPeriod-1)
        {
         int k=Bars-2;
         //---- initial accumulation
         while(k>=i)
           {
            rel=Close[k]-Close[k+1];
            if(rel>0) sump+=rel;
            else      sumn-=rel;
            k--;
           }
         positive=sump/RSIPeriod;
         negative=sumn/RSIPeriod;
        }
      else
        {
         //---- smoothed moving average
         rel=Close[i]-Close[i+1];
         if(rel>0) sump=rel;
         else      sumn=-rel;
         positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod;
         negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod;
        }
      PosBuffer[i]=positive;
      NegBuffer[i]=negative;
      i--;
     }
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {

      x=PosBuffer[i+1];
      y=NegBuffer[i+1];
      if(x>0)sma=Close[i+1]+x;
      else sma=Close[i+1]-y;
      MABuffer[i]=sma;
      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Aquí está la versión de SVA_03 con la corrección

//+------------------------------------------------------------------+
//|                                                       SVA_03.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property strict

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow

//---- input parameters
extern int RSIPeriod=14;
extern int Levl=50;
extern int TF=0;
//---- buffers
double MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
   IndicatorBuffers(1);
   SetIndexBuffer(0,MABuffer);

//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
//----
//---- name for DataWindow and indicator subwindow label
//   short_name="RSI("+IntegerToString(RSIPeriod)+")";
   short_name="RSI("+RSIPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);

   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive,sma,x,y,Pos,Neg;
//----
   if(Bars<=RSIPeriod) return(0);
   if(TF!=0)
     {
      string name=WindowExpertName();
      for(i=0; i<Bars-counted_bars+1; i++)
        {
         int barIndex=iBarShift(NULL,TF,Time[i],false);
         MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex);
        }
      return(0);
     }

   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      if(i==Bars-RSIPeriod-1)
        {
         int k=Bars-2;
         //---- initial accumulation
         while(k>=i)
           {
            rel=Close[k]-Close[k+1];
            if(rel>0) sump+=rel;
            else      sumn-=rel;
            k--;
           }
         positive=sump/RSIPeriod;
         negative=sumn/RSIPeriod;
        }
      else
        {
         //---- smoothed moving average
         rel=Close[i]-Close[i+1];
         if(rel>0) sump=rel;
         else      sumn=-rel;
         positive=(Pos*(RSIPeriod-1)+sump)/RSIPeriod;
         negative=(Neg*(RSIPeriod-1)+sumn)/RSIPeriod;
        }

      x=Pos;
      y=Neg;
      Pos=positive;
      Neg=negative;
      if(x>0)sma=Close[i+1]+x;
      else sma=Close[i+1]-y;
      MABuffer[i]=sma;

      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

allí reemplazado

      x=positive;;
      y=negative;

a .

      x=Pos;
      y=Neg;
La historia encaja, pero los problemas en la barra cero - hay una discrepancia, ¿cómo comprarlos?
Archivos adjuntos:
SVA_03.mq4  3 kb
SVA_04.mq4  4 kb
 
Archivo equivocado publicado por error - cambiado arriba...
 
-Aleks-:
История сходится, но проблемы на нулевом баре - имеется расхождение, как их купировать?
Ciertamente, entiendo que el problema se debe a un exceso de cálculo en la barra de cero, pero no consigo averiguar cómo solucionarlo...
 

¡Buenas tardes!

¡Ayuda! Necesito un código para abrir una orden pendiente. Y en 20 min después de abrir la orden, si no se cierra, cambiará el SL a 50 pips. Gracias.

 

Buenas tardes

Por favor, ayuda con una pregunta muy simple (probablemente). Existe una función estándar:

int  ArraySize(const void& array[]);

¿Qué significa "const void &" y cómo utilizarlo? ? Incluso un simple intento de escribir una función similar conduce a un error de compilación:

int test(const void& array[]) {
    return ArraySize(array);
}

Error de compilación: 'const' - uso ilegal del tipo 'void

¿Cómo puedo utilizar correctamente "const void &" al escribir mi propio código? ¿Se puede hacer en absoluto?

 
mql4-2016:

Buenas tardes

Por favor, ayuda con una pregunta muy simple (probablemente). Existe una función estándar:

int  ArraySize(const void& array[]);

¿Qué significa "const void &" y cómo utilizarlo? ? Incluso un simple intento de escribir una función similar conduce a un error de compilación:

int test(const void& array[]) {
    return ArraySize(array);
}

Error de compilación: 'const' - uso ilegal del tipo 'void

¿Cómo puedo utilizar correctamente "const void &" al escribir mi propio código? ¿O se puede utilizar en absoluto?

Sustituye void por el tipo de datos que debe almacenar el array. La función estándar está diseñada como una plantilla.

De hecho, esta función del sistema es una función sobrecargada, y toda la implementación de dicha sobrecarga está oculta para el desarrollador de MQL4:

intArraySize(
void&array[]// array a comprobar
);

El compilador MQL4 realmente sustituye una implementación necesaria para cada llamada de esta función, por ejemplo, para matrices de tipo entero como esta

intArraySize(
int&array[]// array con elementos de tipo int
);

Y para un array de tipo MqlRates para trabajar con cotizaciones en formato de datos históricos, la función ArraySize() puede representarse como sigue

intArraySize(
MqlRates&array[]// array lleno de valores de tipo MqlRates
);

 
Kot:

¡Buenas tardes!

¡Ayuda! Necesito un código para abrir una orden pendiente. Y en 20 min después de abrir la orden, si no se cierra, cambiará el SL a 50 pips. Gracias.

¿En qué puedo ayudarle? ¿Escribir para ti? Por favor, sea autónomo.
 
Artyom Trishkin:

Sustituye void por el tipo de datos que debe almacenar el array. La función estándar está diseñada como una plantilla.

De hecho, esta función del sistema es una función sobrecargada, y toda la implementación de dicha sobrecarga está oculta para el desarrollador de programas en MQL4.

¿He entendido bien que en MQL4/MQL5 la construcción "const void &" - es de hecho una notación simbólica para la referencia y en la práctica no se puede escribir en sus propias funciones?

Gracias de antemano

 
mql4-2016:

¿He entendido bien que en MQL4/MQL5 la estructura "const void &" - es de hecho una notación simbólica para el libro de referencia y en la práctica no se puede utilizar en sus propias funciones?

Gracias de antemano

No.
Razón de la queja: