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

 
mila.com:

Gracias, pero me devuelve cero. ¿Cuál podría ser la razón?

No puede ser otra razón. Ningún ordenador conoce un año menos que 1970. Empiece por el año que aparece en las cotizaciones del corredor.

 
Alexey Viktorov:

No podía ser otro año. Ningún ordenador conoce un año menos que 1970. Empiece por el año que aparece en las cotizaciones del corredor.

Es un buen trabajo, el primer año de nuestra era).

 
Vitaly Muzichenko:

Qué pasa, es bueno, el primer año de nuestra era)

Y -1 sería el primer año BC.
 
Artyom Trishkin:
Utilice CopyXXX()

Gracias.


En MT5 se puede desplazar el gráfico de esta manera:

PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);

Si se compila en MT4 no da errores, sin embargo no funciona nada, ¿hay alguna contrapartida en MT4?
 
Aleksey Vyazmikin:

Gracias.


En MT5 es posible desplazar el gráfico de esta manera:

PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);

Si se compila en MT4 no da ningún error, sin embargo no funciona nada, ¿hay alguna contrapartida en MT4?
Пользовательские индикаторы - Справочник MQL4
Пользовательские индикаторы - Справочник MQL4
  • docs.mql4.com
Пользовательские индикаторы - Справочник MQL4
 
Alexey Viktorov:

Yo elegí allí.

SetIndexShift(0,InpChannelPeriod); 

pero el efecto es completamente diferente, es decir, el código no funciona, la lógica es diferente - no sé...
 

Tal vez alguien pueda ayudar. La esencia del indicador es dibujar el canal de Doncian como de costumbre y luego desplazar las líneas del último valor del canal detrás de la barra negativa.

En MT5 todo parece funcionar, pero en MT4 no entiendo qué es lo que falla - lo he redibujado aquí y allá, pero sigue dibujando sin sentido - desplaza el propio canal, aunque hago por separado el cálculo de los valores que irán a shift....

//+------------------------------------------------------------------+
//|                                             Donchian_Channel.mq5 |
//+------------------------------------------------------------------+
#property copyright "Vyazmikin Aleksey Vyacheslavovich"
#property link      "https://www.mql5.com/ru/users/-aleks-"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

//--- plot Label1
#property  indicator_label1  "High_Prognoz";
#property  indicator_type1   DRAW_LINE;
#property  indicator_color1  clrAquamarine;
#property  indicator_style1  STYLE_DOT;
#property  indicator_width1  1;
//--- plot Label2
#property  indicator_label2  "Low_Prognoz";
#property  indicator_type2   DRAW_LINE;
#property  indicator_color2  clrAquamarine;
#property  indicator_style2  STYLE_DOT;
#property  indicator_width2  1;


//--- input parameters
input int InpChannelPeriod=48; // Period

//--- indicator buffers
double ExtHighBufferPrognoz[];
double ExtLowBufferPrognoz[];
//---
int i,limit,start;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtHighBufferPrognoz,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowBufferPrognoz,INDICATOR_DATA);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set first bar from what index will be drawn
   SetIndexDrawBegin(0,InpChannelPeriod);
   SetIndexDrawBegin(1,InpChannelPeriod);

   SetIndexShift(0,InpChannelPeriod);
   SetIndexShift(1,InpChannelPeriod);

//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

//--- check for rates
   if(rates_total<InpChannelPeriod*2) return(0);
//--- preliminary calculations
   if(prev_calculated==0) limit=InpChannelPeriod;
   else limit=prev_calculated;
//--- the main loop of calculations

   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      start=i-InpChannelPeriod;
      ExtHighBufferPrognoz[i-InpChannelPeriod]=high[ArrayMaximum(high,InpChannelPeriod,start)];
      ExtLowBufferPrognoz[i-InpChannelPeriod] =low[ArrayMinimum(low,InpChannelPeriod,start)];

     }

   for(int x=rates_total-InpChannelPeriod;x<rates_total && !IsStopped();x++)
     {
      ExtHighBufferPrognoz[x]=ExtHighBufferPrognoz[rates_total-InpChannelPeriod];
      ExtLowBufferPrognoz[x]=ExtLowBufferPrognoz[rates_total-InpChannelPeriod];
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Aleksey Vyazmikin:

Tal vez alguien pueda ayudar. La esencia del indicador es dibujar el canal de Doncian como de costumbre y luego desplazar las líneas del último valor del canal detrás de la barra negativa.

En MT5 todo parece funcionar, pero en MT4 no entiendo qué es lo que falla - lo he redibujado aquí y allá, pero sigue dibujando sin sentido - desplaza el propio canal, aunque hago por separado el cálculo de los valores que irán a shift....

Bueno, mira el código del cocodrilo, el cambio funciona allí. Aunque, tal vez, la lógica sea diferente.

 
Alexey Viktorov:

Bueno, mira el código del caimán, ahí es donde funciona el turno. Sin embargo, la lógica puede ser diferente.


Sí, a mí también me funciona el turno.

Lleno el array con un desplazamiento, pero se llena como si no hubiera desplazamiento, pero el desplazamiento en sí sucede visualmente.

La primera parte del código deja el buffer sin llenar hasta la profundidad deInpChannelPeriod desde la última barra:

   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      start=i-InpChannelPeriod;
      ExtHighBufferPrognoz[i-InpChannelPeriod]=high[ArrayMaximum(high,InpChannelPeriod,start)];
      ExtLowBufferPrognoz[i-InpChannelPeriod] =low[ArrayMinimum(low,InpChannelPeriod,start)];

     }

La segunda parte debería llenar esta zona:

   for(int x=rates_total-InpChannelPeriod;x<rates_total && !IsStopped();x++)
     {
      ExtHighBufferPrognoz[x]=ExtHighBufferPrognoz[rates_total-InpChannelPeriod];
      ExtLowBufferPrognoz[x]=ExtLowBufferPrognoz[rates_total-InpChannelPeriod];
     }

Pero en realidad resulta así:


 

Código en MT5

#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

//--- plot Label1
#property indicator_label1  "Predicted_high_price";
#property indicator_type1   DRAW_LINE;
#property indicator_color1  clrAquamarine;
#property indicator_style1  STYLE_DOT;
#property indicator_width1  1;
//--- plot Label2
#property indicator_label2  "Predicted_low_price";
#property indicator_type2   DRAW_LINE;
#property indicator_color2  clrAquamarine;
#property indicator_style2  STYLE_DOT;
#property indicator_width2  1;


//--- input parameters
input int InpChannelPeriod=48; // Period

//--- indicator buffers
double ExtHighBufferPrognoz[];
double ExtLowBufferPrognoz[];
//---
int i,limit,start;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtHighBufferPrognoz,INDICATOR_DATA);
   SetIndexBuffer(1,ExtLowBufferPrognoz,INDICATOR_DATA);   
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpChannelPeriod);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpChannelPeriod);   

   PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);
   PlotIndexSetInteger(1,PLOT_SHIFT,InpChannelPeriod);   


//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

//--- check for rates
   if(rates_total<InpChannelPeriod) return(0);
//--- preliminary calculations
   if(prev_calculated==0) limit=InpChannelPeriod;
   else limit=prev_calculated;
//--- the main loop of calculations
   for(i=limit;i<rates_total && !IsStopped();i++)
     {
      start=i-InpChannelPeriod;          
      ExtHighBufferPrognoz[i-InpChannelPeriod]=high[ArrayMaximum(high,start,InpChannelPeriod)];
      ExtLowBufferPrognoz[i-InpChannelPeriod]=low[ArrayMinimum(low,start,InpChannelPeriod)];

     }

   for(int x=rates_total-InpChannelPeriod;x<rates_total && !IsStopped();x++)
     {
      //int calc=x--;
      ExtHighBufferPrognoz[x]=ExtHighBufferPrognoz[rates_total-InpChannelPeriod-1];
      ExtLowBufferPrognoz[x]=ExtLowBufferPrognoz[rates_total-InpChannelPeriod-1];             
     }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Resultado:


ZS: Cambiado el código - el ME equivocado era.
Razón de la queja: