Why are the indicators (lines, arrows, histograms) flickering in the MT5 terminal?

Eugene Myzrov
915

What can the blinking of indicators (lines, arrows, histograms) be related to, both in the main chart window and in a separate window? The impression is that the indicator is redrawn and at the same time the marks and the buffer values disappear from the list for a second, and then appear again in the list. Is there something wrong with the program code?

This is only observed in the MT5 terminal, it is not observed in MT4.

Vitalie Postolache
6928
Eugene Myzrov:

What can the flicker of the indicators (lines, arrows, histograms) be related to, both in the main chart window and in a separate window? The impression is that the indicator is redrawn, and at the same time in the data window the labels and buffer values disappear from the list for a second, and then appear again in the list. Something wrong in the program code?

And this is only observed in the MT5 terminal, it is not observed in MT4.


Are you suggesting that we try to guess? Feel free to contact me ; )
Eugene Myzrov
915
Eugene Myzrov  
Vitalie PostolacheAre you proposing a fortune-telling exercise? You're welcome ; )

No, it's just that the search didn't answer the question I'm interested in.
Maybe you know why the flicker is only observed in the MT5 exchange terminal, in the MT5 forex terminal the flicker does not occur?

Vitalie Postolache
6928
Eugene Myzrov:

No, the search just didn't answer the question I was interested in.
Maybe you know why the flicker is only observed in the MT5 exchange terminal, in the MT5 forex terminal there is no flicker?


Do all indicators flicker? The MT5 is the same, only the account type may be different - exchange or forex.
Eugene Myzrov
915
Eugene Myzrov  
Vitalie PostolacheThat straightforwardly all the indicators flicker? The MT5 is the same, only the account type may be different - exchange or forex.

That's what I meant when I mentioned the MT5 forex and stock exchange terminal for short. A more complete problem sounds like this. When I connect to forex broker the indicators in MT5 terminal do not flicker, but when I connect to stock broker I see flickering and also indicators buffer marks and values disappear in data window for a second or two.

As for the question of whether all indicators behave this way, I can't say so. Let me post one now, so as not to be unsubstantiated.

Eugene Myzrov
915
Eugene Myzrov  
This is an "AOM" indicator derived from the "AO" indicator with minor generalisations.
//+-----------------------------------------------------------------------------------------------------+
//| AOM = Awesome Oscillator Modernized (индикатор AO Модернизированный)
//+-----------------------------------------------------------------------------------------------------+
#property copyright  "Copyright© 2014, Scriptolog® [ myzrov@mail.ru ]"
#property link       "mailto:myzrov@mail.ru"
#property version    "2.0" // текущая версия

#property description "«AOM» - индикатор «AO» модернизированный.\n"

#property description "Предупреждение о рисках. Торговля на рынке Forex с использованием"
#property description "кредитного плеча несёт в себе значительные финансовые риски."

//#property icon "\\Images\\Constructor.ico" // путь к файлу заставки
#property strict

#property   indicator_separate_window
#property   indicator_buffers 2
#property   indicator_plots   2

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#property    indicator_label1  "AOM UP"
#property    indicator_color1  clrGreen
#property    indicator_width1  3
#property    indicator_style1  STYLE_SOLID
#property    indicator_type1   DRAW_HISTOGRAM

#property    indicator_label2  "AOM DN"
#property    indicator_color2  clrRed
#property    indicator_width2  3
#property    indicator_style2  STYLE_SOLID
#property    indicator_type2   DRAW_HISTOGRAM

#property    indicator_level1  0.0000 // Горизонтальный уровень в отдельном окне индикатора

   input int                  AOM_PERIOD_FACTOR  =   1;           // AOM. Коэф-т повышения периода усреднения
   input int                  AOM_PERIOD_FAST    =   5;           // AOM. Период усреднения MA быстрой 
   input int                  AOM_PERIOD_SLOW    =  34;           // AOM. Период усреднения MA медленной
   input int                  AOM_SHIFT          =   0;           // AOM. Сдвиг по горизонтали
   input ENUM_MA_METHOD       AOM_METHOD         =  MODE_SMA;     // AOM. Метод усреднения
   input ENUM_APPLIED_PRICE   AOM_PRICE          =  PRICE_MEDIAN; // AOM. Цена   усреднения

//+------------------------------------------------------------------+
//| Глобальные переменные
//+------------------------------------------------------------------+

   double   aUP[], aDN[]; // INDICATOR_DATA

   double   aom, last_aom;  // текущее и предыдущее значения индикатора AO

   int      ma_fast_handle; // =iMA(_Symbol, PERIOD_CURRENT, AOM_PERIOD_FAST, AOM_SHIFT, AOM_METHOD, AOM_PRICE);
   int      ma_slow_handle; // =iMA(_Symbol, PERIOD_CURRENT, AOM_PERIOD_SLOW, AOM_SHIFT, AOM_METHOD, AOM_PRICE);
 
   int      MAX_PERIOD;

// периоды усреднения быстрой и медленной MA (в барах)
   int      AOM1_PERIOD_FAST;    // =AOM_PERIOD_FAST*AOM_PERIOD_FACTOR;
   int      AOM1_PERIOD_SLOW;    // =AOM_PERIOD_SLOW*AOM_PERIOD_FACTOR;
  
//+------------------------------------------------------------------+
//| Custom indicator initialization function
//+------------------------------------------------------------------+
int OnInit()
{
// Подготовить периоды усреднения быстрой и медленной MA (в барах)
   AOM1_PERIOD_FAST=AOM_PERIOD_FAST*AOM_PERIOD_FACTOR;
   AOM1_PERIOD_SLOW=AOM_PERIOD_SLOW*AOM_PERIOD_FACTOR;

   MAX_PERIOD=(int)MathMax(AOM1_PERIOD_FAST, AOM1_PERIOD_SLOW)+1;

// Распределяет память под буферы, используемые для вычислений пользовательского индикатора
   ArraySetAsSeries(aUP, true); SetIndexBuffer(0, aUP, INDICATOR_DATA);
   ArraySetAsSeries(aDN, true); SetIndexBuffer(1, aDN, INDICATOR_DATA);

// Номер позиции начала отрисовки линии индикатора // sets drawing line empty value
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, MAX_PERIOD); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, MAX_PERIOD); PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);

// set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS, _Digits+1);
   string short_name; StringConcatenate(short_name, "AOM [", AOM_PERIOD_FACTOR, "]  (", AOM_PERIOD_FAST, ",", AOM_PERIOD_SLOW, ")");

   IndicatorSetString(INDICATOR_SHORTNAME, short_name);

   ResetLastError();

// Инициализация 2-х индикаторов MA
   ma_fast_handle=iMA(_Symbol, PERIOD_CURRENT, AOM1_PERIOD_FAST, AOM_SHIFT, AOM_METHOD, AOM_PRICE);
   ma_slow_handle=iMA(_Symbol, PERIOD_CURRENT, AOM1_PERIOD_SLOW, AOM_SHIFT, AOM_METHOD, AOM_PRICE);

   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Функция деинициализации является обработчиком события Deinit
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Удалить хэндлы индикаторов и освобождить расчетную часть индикатора
   if (ma_slow_handle!=INVALID_HANDLE) IndicatorRelease(ma_slow_handle);
   if (ma_fast_handle!=INVALID_HANDLE) IndicatorRelease(ma_fast_handle);
   return;
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,      // размер входных таймсерий 
                 const int prev_calculated,  // обработано баров на предыдущем вызове 
                 const datetime& time[],     // Time 
                 const double&   open[],     // Open 
                 const double&   high[],     // High 
                 const double&   low [],     // Low 
                 const double&   close[],    // Close 
                 const long& tick_volume[],  // Tick Volume 
                 const long& real_volume[],  // Real Volume 
                 const int&  spread[])       // Spread 
{
   int N=rates_total-prev_calculated; if (N>MAX_PERIOD) N-=MAX_PERIOD;

   for (int i=N; i>0 && !IsStopped(); i--) {
      double ma_fast=getMA(ma_fast_handle, i);
      double ma_slow=getMA(ma_slow_handle, i);;
      aom=ma_fast-ma_slow;
      if (aom>last_aom) {aUP[i]=aom; aDN[i]=EMPTY_VALUE;}
      else              {aDN[i]=aom; aUP[i]=EMPTY_VALUE;}
      last_aom=aom;
   }
   aUP[0]=EMPTY_VALUE; aDN[0]=EMPTY_VALUE;
   return(rates_total);
}
//+-------------------------------------------------------+
//| Возвращает значение индикатора «MA»
//+-------------------------------------------------------+
double getMA(int handle, int i) // откуда начнем копирование
{
   double aMA[1]; // массив для получения значениz индикатора
   double nMA=0;
   int k=CopyBuffer(handle, 0, i, 1, aMA); nMA=aMA[0];
   if (k<1) {int err=GetLastError(); Print("*** MA=", handle, " CopyBuffer error #", err);}
   return(nMA);
}
Eugene Myzrov
915
Eugene Myzrov  
Now I have watched this indicator for a while when connected to a stockbroker (tool RTS-6.17) and so far I have noticed only one of the two problems indicated. For some time the data in the data window, i.e. labels and values of the two buffers of the AOM indicator disappear.
Stanislav Korotky
40020

I observe this behaviour when there are many objects. When there are no objects, everything is more or less normal. Indicator buffers can also blink sometimes when a tick comes (when there are objects updating).

I think this is a feature of MT5, it is connected with the fact that now indicators are in separate threads for each symbol/timestamp and for updating the picture in GUI thread it needs synchronization, which adds slowness in comparison with the single thread model of MT4. Working with objects is the most resource intensive operation, that's why it causes this problem. If the problem is observed without objects, perhaps there is some other loading in the code of the indicator. If you try to localise it and exclude it, it should get better.

Eugene Myzrov
915
Eugene Myzrov  
Stanislav Korotky: I observe this behaviour when there are many objects. When there are no objects, everything is more or less normal. Indicator buffers sometimes can blink too, when a tick comes (when there are objects updating). I think this is a feature of MT5, it is connected with the fact that now indicators are in separate threads for each symbol/timestamp and for updating an image in GUI thread it needs synchronization, and it adds slowness comparing to the single thread model of MT4. Working with objects is the most resource intensive operation, that's why it causes this problem. If the problem is observed without objects, perhaps there is some other loading in the code of the indicator. If you try to localise it and exclude it, it should get better.

The indicator doesn't work with objects, so that can be ruled out. I admit that it may be related to software code, but the code I cited above is very simple and I just can't see where it is failing. The main questions still remain unanswered - who is to blame and what to do? Is there any way to deal with it or is it incorrigible in principle? Perhaps the developers will have their say here!

By the way, it's morning, stock exchange has not opened yet, so all indicators are standing like sticks, buffers in the "Data Window" are not redrawn, lines do not blink.

Eugene Myzrov
915
Eugene Myzrov  

Well, the exchange opened, and again all the same movie. I can understand that indicator data is recalculated with every tick, but why should I remove all indicator buffers from the data window table? Isn't it enough just to update their values in place? For example, the way it is done with the Close price. After all, with a new tick the Close price does not disappear from the data window to appear again with the updated value? Why then do indicator buffers disappear for some time? Also, some indicators are not recalculated on the current zero bar, but why are they also redrawn in the "Data Window"?

Still hoping for an answer from knowledgeable people, or at least a link.

Eugene Myzrov
915
Eugene Myzrov  

There seems to be something wrong. Either my question is no longer relevant and a solution has long since been found, or I asked it in the wrong thread. Maybe there are no more knowledgeable people on the forum, or the developers do not monitor this section of the forum?
Why in the "Data Window" indicator buffers disappear for some time? Is this not fixed in principle or is it fixable? What's wrong in the above code? And the indicator does not recalculate its value on the current bar.