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

 
azolotta:
OK, then how do I rework the code if I need, for example, to select the highest high from the last 3 bars (which meet the conditions in if) and place a point on it (right on this high!), then also find the low point.

Try it this way, but not sure

//+------------------------------------------------------------------+
//|                                                           AZ.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Anastasiya Zolotareva"
#property link      "insta"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 5
//--- plot myAZ
#property indicator_label1  "myAZ"
#property indicator_color1  Black
#property indicator_color2  Blue
#property indicator_color3  Orange
#property indicator_color4  Blue
#property indicator_color5  Orange
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_SOLID
#property indicator_style3 STYLE_SOLID
#property indicator_style4 STYLE_SOLID
#property indicator_style5 STYLE_SOLID
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1

extern int barsToProcess=200; //количество последних баров в истории
//--- indicator buffers
double myAZBuffer[];
double ExtHighBuffer01[];
double ExtLowBuffer01[];
double ExtHighBuffer02[];
double ExtLowBuffer02[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexShift(1,-2);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexShift(2,-2);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexShift(3,-3);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexShift(4,-3);

//--- indicator buffers mapping
   SetIndexBuffer(0,myAZBuffer);
   SetIndexBuffer(1,ExtHighBuffer01);
   SetIndexBuffer(2,ExtLowBuffer01);
   SetIndexBuffer(3,ExtHighBuffer02);
   SetIndexBuffer(4,ExtLowBuffer02);
   IndicatorShortName("AZ");
//---
   return(0);
  }
//+------------------------------------------------------------------+
//|         deinit                                                         |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  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[])
  {
   if((rates_total-prev_calculated-barsToProcess)<=0)return(0);
   int limit, val_index;
   if(barsToProcess>0) limit=barsToProcess; 
   else
   limit=rates_total-prev_calculated-barsToProcess-1;
  
   for(int n=limit;n>=0;n--)
     {
      if(Close[n+1]>Open[n+1] && Open[n+2]>=Close[n+2])
        {
         val_index=iLowest(NULL,0,MODE_LOW,3,n+1);
         myAZBuffer[n]=Low[val_index];
         ExtLowBuffer01[n]=Low[val_index];
        }
      else
      if(Open[n+1]>Close[n+1] && Close[n+2]>=Open[n+2])
        {
         val_index=iHighest(NULL,0,MODE_HIGH,3,n+1);
         myAZBuffer[n]=High[val_index];
         ExtHighBuffer01[n]=High[val_index];
        }
      else
      if(Close[n+1]>Open[n+1] && Open[n+3]>Close[n+3])
        {
         val_index=iLowest(NULL,0,MODE_LOW,3,n+1);
         myAZBuffer[n]=Low[val_index];
         ExtLowBuffer02[n]=Low[val_index];
        }
      else
      if(Close[n+1]<Open[n+1] && Close[n+3]>Open[n+3])
        {
         val_index=iHighest(NULL,0,MODE_HIGH,3,n+1);
         myAZBuffer[n]=High[val_index];
         ExtHighBuffer02[n]=High[val_index];
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
MakarFX:

Try it this way, but I'm not sure

Unfortunately shift offset is not the right option. I'm thinking maybe I should try inserting my code into standard-zigzag. I'm trying it now, but so far to no avail. What do you think, can I go through zigzag? Because at the end I need to find vertices connected alternately, like high-low-high, and if I meet an option high-high, or low-low, then these second highs and lows do not include in the array, and wait for the opposite.

 
azolotta:

Unfortunately, shift offset is not a suitable option. I'm thinking maybe I should try inserting my code into the standard zigzag. Now I'm poking around, but so far to no avail. Do you think it's possible to go through zigzag? Because at the end I need to connect found tops alternately, like high-low-high, and if I meet an option high-low or low-low, then these second highs and lows should not include in arrays, and wait for the opposite.

No. The previous one should be zeroed out, and the current one should be added to the indicator buffer.

 
azolotta:

Unfortunately, shift offset is not a suitable option. I'm thinking maybe I should try inserting my code into the standard zigzag. Now I'm poking around, but so far to no avail. What do you think, can I go through zigzag? Because at the end I need to find vertices connected alternately, like high-low-high, and if I meet an option high-high, or low-low, then these second highs and lows do not include in the array, and wait for the opposite.

In any case, there will be a lag, i.e. until the conditions for 2-3 previous bars are met - it won't draw.

I understand that we need a zig-zag from the high to the low?
 
MakarFX:

In any case, there will be a lag, i.e. until the conditions for 2-3 previous bars are met - it won't draw.

I guess I need to zig-zag from highs to lows?

Yes, ideally we need a zig-zag from highs to lows (so these highs and lows are in my conditions in if, and if there are two or more highs/lows in a row, then these second highs/lows should not be displayed, and we should wait for the reversal). It is enough for me to display the last 6 lowes and 6 highs in the indicator. And then I want to call these found zig-zag points in the script/advisor for further needs.

 

Hello!

Can anyone advise why no values are showing through debug mode?

Looks like after updating the mt5 program, the problem started

And what does red mean in the column - Values?

 
Mikhail Toptunov:

Hello!

Can anyone advise why no values are showing through debug mode?

Looks like after updating the mt5 program, the problem started

And what does the red colour of the value in the column - Values mean?

1. Please give minimal information (first three lines from the journal tab after restarting the terminal)

2) Update the build

 
azolotta:

Yes, ideally we need a zig-zag from highs to lows (so that these highs and lows are in my conditions in if, and if there are two or more highs/lows in a row, then these second highs/lows should not be displayed, but wait for a reversal). It is enough for me to display the last 6 lowes and 6 highs in the indicator. And then I want to call these found zig-zag points in the script/advisor for further needs.

I'm not a programmer and don't know how to help yet, but I'll think about it...
 
MakarFX:
I'm not a programmer and don't know how to help yet, but I'll think about it...
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,                                                           |
//+----------------------------------------------------------------------------+
//|  Версия   : 07.10.2006                                                     |
//|  Описание : Возвращает экстремум ЗигЗага по его номеру.                    |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (NULL или "" - текущий символ)          |
//|    tf - таймфрейм                  (      0     - текущий ТФ)              |
//|    ne - номер экстремума           (      0     - последний)               |
//|    dp - ExtDepth                                                           |
//|    dv - ExtDeviation                                                       |
//|    bs - ExtBackstep                                                        |
//+----------------------------------------------------------------------------+
double GetExtremumZZPrice(string sy="", int tf=0, int ne=0, int dp=12, int dv=5, int bs=3) {
  if (sy=="" || sy=="0") sy=Symbol();
  double zz;
  int    i, k=iBars(sy, tf), ke=0;

  for (i=1; i<k; i++) {
    zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, i);
    if (zz!=0) {
      ke++;
      if (ke>ne) return(zz);
    }
  }
  Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
  return(0);
}

customZigZagindicator and returns its price level. The function accepts the following optional parameters:
  • sy- Name of the instrument."" orNULL- current symbol. Default value isNULL.
  • tf- Timeframe. Default value 0- current symbol.
  • ne- Extreme number. 0- last, 1- previous, 2- previous, etc.
  • dp,dv,bs- ZigZaga parameters: ExtDepth, ExtDeviation, ExtBackstep.

Переход на новые рельсы: пользовательские индикаторы в MQL5
Переход на новые рельсы: пользовательские индикаторы в MQL5
  • www.mql5.com
Я не буду перечислять все новые возможности и особенности нового терминала и языка. Их действительно много, и некоторые новинки вполне достойны освещения в отдельной статье. Вы не увидите здесь кода, написанного по принципам объектно-ориентированного программирования — это слишком серьезная тема для того, чтобы просто быть упомянутой в контексте как дополнительная вкусность для кодописателей. В этой статье остановимся подробней на индикаторах, их строении, отображении, видах, а также особенностях их написания по сравнению с MQL4.
 
Iurii Tokman:

customZigZagindicator and returns its price level. The function accepts the following optional parameters:
  • sy- Name of the instrument."" orNULL- current symbol. Default value isNULL.
  • tf- Timeframe. Default value 0- current symbol.
  • ne- Extreme number. 0- last, 1- previous, 2- previous, etc.
  • dp,dv,bs- ZigZaga parameters: ExtDepth, ExtDeviation, ExtBackstep.

this is not suitable, you need non zig-zag extremes