Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 699

 
Dmitry Belov:

Hello, could you please tell me why ZigD[0] is not output in sommente?

Does ZigM[0] work?

 
Alexey Viktorov:

Does ZigM[0] output?

Yes it does...


	          
 
Dmitry Belov:

Yes it does...

Sorry, I didn't look at the code carefully...

When zzz>0 it means that the value may be equal to either high or low bar. Respectively this value should be checked against these values and depending on the result placed in one or the other array.

 
Alexey Viktorov:

Sorry, I didn't look at the code carefully...

When zzz>0, it means that the value can be equal to either high or low bar. Accordingly, this value should be checked against these values and depending on the result placed in one or the other array.

I do so, but for some reason it does not output ZigD[] and does not output at all if I add ZigD, if I comment it out, it outputs everything.

//+------------------------------------------------------------------+
//|                                                           01.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_width1 1

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
extern int nn=30;

int  ww=0, kk=0;
int dd=0;
double zz,SredRazmax, zzz;
double HZZ[], ZigM[];
int ZigD[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,HZZ);
   SetIndexBuffer(1,ZigM);
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexEmptyValue(0,0.0);
   SredRazmax=0.0;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int shift,limit;
//--- Первый вызов индикатора или смена таймфрейма или подгрузка данных из истории
   if(prev_calculated==0)
     {
      limit=rates_total-1;
      SredRazmax=0.0;
      ArrayInitialize(HZZ,0.0);
     }
   else limit=rates_total-prev_calculated+1;
   for(shift=limit; shift>=0; shift--)
     {
      zz=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,shift);
      if(zz>0.0)
        {
         HZZ[shift]=zz;
        }
     }
     for(ww = 0; ww <= Bars-1; ww++)
  {
      zzz = iCustom(NULL, 0, "ZigZag", ExtDepth, ExtDeviation, ExtBackstep, 0, ww);
      
           if(zzz > 0.0)   
           {
           ZigM[kk]=zzz;
            kk++; 
           ZigD[dd]=ww;
            dd++;  
            }
   }       
   
   // Расчет средних значений 
     for(kk=0;kk<=nn;kk++)
     {
        if(ZigM[kk]>ZigM[kk+1]){SredRazmax+=(ZigM[kk]-ZigM[kk+1]);}
        if(ZigM[kk]<ZigM[kk+1]){SredRazmax+=(ZigM[kk]-ZigM[kk+1])*(-1);}
     if(IsStopped()) 
     break; 
     }
    Comment("Средний размах = ",SredRazmax/nn,",",ZigM[0],",",ZigM[1]);
    Comment(ZigD[0]);
   return(0);
  }
  //+-  
 

Hello People!

I couldn't find a more suitable "window" to address a question on MT4.

When opening the terminal, the "status line", "standard", "charts","graphical instruments" and"chart periods" suddenly disappear. I switch it off and next time I open it again I get blank terminal, only current chart.

I have never seen such a bug before and I don't know what to do. Please advise me. I do not know what to do.

 
Vadens:

Hello People!

I couldn't find a more suitable "window" to address a question on MT4.

When opening the terminal, the "status line", "standard", "charts","graphical instruments" and"chart periods" suddenly disappear. I switch it off and next time I open it again I get blank terminal, only current chart.

I have never seen such a bug before and I don't know what to do. Please advise me. I do not know what to do.

It looks like you have a problem with write permissions to the directory where the terminal is located. If you are running as a restricted user, move the terminal to a directory where you can access files/folders.

 
Vadens:

Hello People!

I couldn't find a more suitable "window" to address a question on MT4.

When opening the terminal, the "status line", "standard", "charts","graphical instruments" and"chart periods" suddenly disappear. I switch it off and next time I open it again I get blank terminal, only current chart.

I have never seen such a bug before and I don't know what to do. Please advise me. I do not know what to do.

You have full screen mode (F11)
 
Dmitry Belov:

I do so, but for some reason it doesn't output ZigD[] and doesn't output at all if I add ZigD, if I comment it out, it outputs everything

Again, my inattention...

I hope it will be different now :)))

Doesn't the comment blink??? It's better to write it like this

    Comment("Средний размах = ",SredRazmax/nn,",",ZigM[0],",",ZigM[1],"\n" // Это перенос комментария на следующую строку
           , ZigD[0]);
 
Alexey Viktorov:

Once again, my inattention...

I hope it will be different now :)))

Doesn't the comment blink??? It's better to write it like this.

Thanks, I've already figured it out myself, I just needed to initialize the array as double and it worked. Here's the code of indicator if you want, but it's still raw, I have more ideas... Tell me, do you know how you can display a somment in the lower left corner or in the middle at the top?

//+------------------------------------------------------------------+
//|                                                           01.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_width1 1

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
extern int nn=30;

int  ww=0, kk=0;
int dd=0;
double zz,SredRazmax, zzz, SredDlin;
double HZZ[], ZigM[];
double ZigD[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,HZZ);
   SetIndexBuffer(1,ZigM);
   SetIndexBuffer(2,ZigD);
   SetIndexStyle(0,DRAW_SECTION);
   SetIndexEmptyValue(0,0.0);
   SredRazmax=0.0;
   SredDlin=0.0;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int shift,limit;
//--- Первый вызов индикатора или смена таймфрейма или подгрузка данных из истории
   if(prev_calculated==0)
     {
      limit=rates_total-1;
      SredRazmax=0.0;
      ArrayInitialize(HZZ,0.0);
     }
   else limit=rates_total-prev_calculated+1;
   for(shift=limit; shift>=0; shift--)
     {
      zz=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,shift);
      if(zz>0.0)
        {
         HZZ[shift]=zz;
        }
     }
     for(ww = 0; ww <= Bars-1; ww++)
  {
      zzz = iCustom(NULL, 0, "ZigZag", ExtDepth, ExtDeviation, ExtBackstep, 0, ww);
      
           if(zzz > 0.0)   
           {
           ZigM[kk]=zzz;
            kk++; 
           ZigD[dd]=ww;
            dd++;  
            }
   }       
   
   // Расчет средних значений 
     for(kk=0;kk<=nn;kk++)
     {
        if(ZigM[kk]>ZigM[kk+1]){SredRazmax+=(ZigM[kk]-ZigM[kk+1]);}
        if(ZigM[kk]<ZigM[kk+1]){SredRazmax+=(ZigM[kk]-ZigM[kk+1])*(-1);}
   //  if(IsStopped()) 
  //   break; 
     }
     for(dd=0;dd<=nn;dd++)
     {
        if(ZigD[dd]>0.0){SredDlin+=(ZigD[dd+1]-ZigD[dd]);}
        if(IsStopped()) 
     break;
     } 
    Comment("Средний размах = ",SredRazmax/nn,"//","Средняя продолжительность = ",SredDlin/nn,"//",ZigM[0],"//",ZigM[1],"//",ZigD[0],"//",ZigD[1]);
    return(0);
  }
  //+-  
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • www.mql5.com
Задавайте вопросы по техническому анализу, обсуждайте торговые системы и улучшайте свои навыки программирования торговых стратегий на языке MQL5. Общайтесь и обменивайтесь опытом на форуме с трейдерами всего мира и помогайте ответами новичкам — наше сообщество развивается вместе с вами. Машинное обучение в трейдинге: теория и практика...
 
Dmitry Belov:

Thanks, I was able to figure it out myself, I just needed to initialize the array as a double and everything worked. Here's the indicator code if you want, but it's still raw, there are more ideas... Tell me, do you know how you can display the somment in the lower left corner or in the middle at the top?

It's not possible. Only if you use graphical object OBJ_LABEL
Reason: