Quaisquer perguntas de recém-chegados sobre MQL4 e MQL5, ajuda e discussão sobre algoritmos e códigos - página 305

 
mila.com:

Obrigada, mas para mim não tem retorno. Qual poderia ser a razão?

Não pode ser qualquer outro motivo. Nenhum computador conhece um ano a menos do que 1970. Comece com o ano que aparece nas citações do corretor.

 
Alexey Viktorov:

Não poderia ser em outro ano. Nenhum computador conhece um ano a menos do que 1970. Comece com o ano que aparece nas citações do corretor.

É um bom trabalho, o primeiro ano de nossa era).

 
Vitaly Muzichenko:

O que está acontecendo, é bom, o primeiro ano de nossa era)

E -1 seria o primeiro ano AC.
 
Artyom Trishkin:
Use CopyXXX()

Obrigado.


No MT5 você pode mudar a tabela desta maneira:

PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);

Se compilado em MT4 não dá erros, por mais que nada funcione, existe uma contraparte MT4?
 
Aleksey Vyazmikin:

Obrigado.


No MT5 é possível deslocar o gráfico desta forma:

PlotIndexSetInteger(0,PLOT_SHIFT,InpChannelPeriod);

Se você compila no MT4 ele não dá erros, por mais que nada funcione, existe um analógico MT4?
Пользовательские индикаторы - Справочник MQL4
Пользовательские индикаторы - Справочник MQL4
  • docs.mql4.com
Пользовательские индикаторы - Справочник MQL4
 
Alexey Viktorov:

Eu escolhi lá.

SetIndexShift(0,InpChannelPeriod); 

mas o efeito é completamente diferente, ou seja, o código não funciona, a lógica é diferente - eu não sei...
 

Talvez alguém possa ajudar. A essência do indicador é desenhar o canal do Doncian como de costume e depois mudar as linhas do valor do último canal atrás da barra de menos.

No MT5 tudo parece funcionar, mas no MT4 eu não entendo o que está errado - eu o redesenho aqui e ali, mas ele ainda desenha bobagens - ele muda o canal em si, embora eu faça cálculos separados para valores que irão para 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:

Talvez alguém possa ajudar. A essência do indicador é desenhar o canal do Doncian como de costume e depois mudar as linhas do valor do último canal atrás da barra de menos.

No MT5 tudo parece funcionar, mas no MT4 eu não entendo o que está errado - eu o redesenho aqui e ali, mas ele ainda desenha bobagens - ele muda o canal em si, embora eu faça cálculos separados para valores que irão para shift....

Olhe bem para o código do jacaré, o turno funciona lá. Embora, talvez a lógica seja diferente.

 
Alexey Viktorov:

Bem, veja o código do jacaré, é aí que funciona o turno. A lógica pode ser diferente, porém.


Sim, o turno também funciona para mim.

Eu preencho o conjunto com um turno, mas parece que ele é preenchido sem um turno, mas o turno em si acontece visualmente.

A primeira parte do código deixa o tampão sem preenchimento até a profundidade doInpChannelPeriod a partir da ú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)];

     }

A segunda parte deve preencher esta área:

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

Mas, na realidade, acontece assim:


 

Código em 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: Mudou o código - o ME errado foi o ME.
Razão: