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

 
PokrovMT5:

Hello, Can you please tell me if you need to type in iData for this indicator, no matter if it's any program or reference to the bar data, where you can specify the timeframe, why is the data from other timeframes are not reflected correctly in the current different on timeframe chart, but only in the chart of the specified timeframe? Thank you.


I don't quite understand

But I think this will help

Доступ к таймсериям и индикаторам - Справочник MQL4
Доступ к таймсериям и индикаторам - Справочник MQL4
  • docs.mql4.com
Функции для работы с таймсериями и индикаторами. Таймсерия отличается от обычного массива тем, что индексация элементов таймсерии производится от конца массива к началу (от самых свежих данных к самым старым). Для копирования значений таймсерий и индикаторов рекомендуется использовать только динамические массивы, так как функции копирования...
 

Thanks for the link, I have exactly the same picture, only a slightly different algorithm, the point is to make more points (in the final drawing), make them appear with a threshold.

 
Alekseu Fedotov:

I don't quite get it.

But I think it helps.


Thanks, I will definitely look into it, but as an example the principle why does it not work if instead of writing the data of another timeframe instead of zero, why is it not reflected correctly, should I copy it first and then render it ?

iClose(NULL,0,i);
 
Alekseu Fedotov:

Check it out here.


Novaja:

Thanks for the link, I have exactly the same picture, only a slightly different algorithm, the essence is to make more points (in the final drawing), to make them appear with a threshold.


You can do so, but it turns out Renco, ie divides into equal segments distance m / a vertex. This breaks the algorithm itself search vertices, the question how to make while maintaining the initial code, the threshold between points (on additionally drawing), should get a multiple of the distance between all but the last and the top (will be less than the threshold).

 
//+------------------------------------------------------------------+
//|                                                       FastZZ.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, Yurich"
#property link      "https://login.mql5.com/ru/users/Yurich"
//---
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Gold
#property indicator_color4 DodgerBlue

#property indicator_width3 3
#property indicator_width4 3

//--- input parameters
extern int  Depth    = 10;
//---
double zzH[], zzL[];
double depth;
int last, direction, pbars;
datetime lastbar;

double ArrUp[];
double ArrDn[];
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   SetIndexBuffer(0,zzH);
   SetIndexBuffer(1,zzL);
   SetIndexBuffer(2,ArrUp);
   SetIndexBuffer(3,ArrDn);
   
   SetIndexStyle(0,DRAW_ZIGZAG);
   SetIndexStyle(1,DRAW_ZIGZAG);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(3,DRAW_ARROW);
   
   SetIndexArrow(2,159);
   SetIndexArrow(3,159);
   
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   IndicatorDigits(Digits);
//----
   depth=Depth*Point;
   direction=1;
   last=0;
   pbars=0;
   lastbar=0;
   return(0);
}
//+------------------------------------------------------------------+
int start()
{
   int limit=Bars-IndicatorCounted()-1;
   if(lastbar!=Time[0])
   {
      lastbar=Time[0];
      last++;
   }
   if(MathAbs(Bars-pbars)>1) { last=Bars-1; limit=last;}
   pbars=Bars;
   //---
   for(int i=limit; i>0; i--)
   {
      bool set=false;
      zzL[i]=0;
      zzH[i]=0;
      ArrUp[i]=EMPTY_VALUE;
      ArrDn[i]=EMPTY_VALUE;
      //---
      if(direction>0)
      { 
         if(High[i]>zzH[last]+depth)
         {
            zzH[last]=0;
            zzH[i]=High[i];
           
            ArrUp[i]=High[i];
            
            if(Low[i]<High[last]-depth)
            {
               if(Open[i]<Close[i])
                {
                  zzH[last]=High[last]; 
                  ArrUp[last]=High[last];
                }else direction=-1;
               zzL[i]=Low[i];
               ArrDn[i]=Low[i];
            }
            last=i;
            set=true;
         }
         if(Low[i]<zzH[last]-depth && (!set || Open[i]>Close[i]))
         {
            zzL[i]=Low[i];
            ArrDn[i]=Low[i];
            
            if(High[i]>zzL[i]+depth && Open[i]<Close[i])
             {
               zzH[i]=High[i];
               ArrUp[i]=High[i]; 
             }else direction=-1;
            last=i;
         }
      } else //direction<0
      {
         if(Low[i]<zzL[last]-depth)
         {
            zzL[last]=0;
            zzL[i]=Low[i];
        
            ArrDn[i]=Low[i];            
            
            if(High[i]>Low[last]+depth)
            {
               if(Open[i]>Close[i])
                {
                  zzL[last]=Low[last]; 
                  ArrDn[last]=Low[last];
                }else direction=1;
               zzH[i]=High[i];
               ArrUp[i]=High[i];
            }
            last=i;
            set=true;
         }
         if(High[i]>zzL[last]+depth && (!set || Open[i]<Close[i]))
         {
            zzH[i]=High[i];
            ArrUp[i]=High[i];
            
            if(Low[i]<zzH[i]-depth && Open[i]>Close[i])
             {
               zzL[i]=Low[i]; 
               ArrDn[i]=Low[i];
             }else direction=1;
            last=i;
         }
      }
   }
//----
   zzH[0]=0;
   zzL[0]=0;
//----
   return(0);
}
//+------------------------------------------------------------------+
 

For some reason the code didn't insert the comment immediately, I had to rewrite it.

 
PokrovMT5:

Thank you, I will look into it, but as an example why does it not work if instead of writing zero you put in data of another timeframe, why is it not reflected correctly, should I copy it first and then draw it?



CopyClose is a more modern function, but ok,iClose(...) works fine

How does it not work correctly? A picture or a piece of code, please be more specific.

 
Alekseu Fedotov:

CopyClose is a more modern function, but okay, iClose(...) works fine

How does it work incorrectly? A picture or a piece of code, please be more precise.

Well, here is a simple example, I want to see close prices on the chart, I want to see one hour on the timeframe, everything is good on the clock, but it's different on any other timeframe. The idea was to see the closing prices of the higher ones on a smaller timeframe. The picture is 30 min.
//+------------------------------------------------------------------+
//|                                                   Проверка 2.mq4 |
//|                                                  Bugaev Vladimir |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Bugaev Vladimir"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 clrBlue
#property indicator_width1 2
int i,limit;

double C,CC[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
IndicatorBuffers(1);
//----      
   SetIndexBuffer(0,CC);
  
   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[])
 
 {
if(prev_calculated<1) limit=rates_total-1;
if(prev_calculated>0)limit=rates_total-prev_calculated;
for(i=limit; i>0; i--)  
  
  {
 C= iClose(NULL,60,i);
 CC[i]=C; 



  }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
PokrovMT5:
Well here is the simplest example, I want to see the closing prices on the chart, the timeframe is written one hour, everything is good on the clock, everything is different on any other timeframe. The idea was to see the closing prices of the higher ones on a smaller timeframe. The picture is 30 min.

Like this


     int shift;
     datetime  T;
  
   for(i=limit; i>=0; i--)
     {
      T = iTime(NULL,0,i); 
      shift=iBarShift(NULL,60,T); 
      C=iClose(NULL,60,shift);
      CC[i]=C;
     }
 
Alekseu Fedotov:

That's the way it is.



Thank you very much!

Reason: