Errors, bugs, questions - page 1986

 
Alexey Kozitsyn:

There is initialisation in OnCalculate() at first run (prev_calculated == 0). Do you think moving it to OnInit() will change anything? Well, I'll try, of course, but this is something out of the realm of fantasy...

Cut. As I said, in OnDeinit() arrays are initialized, which are no longer used at next startup (changing input parameters). If this (initializing an array that isn't used as a buffer) helps - it would also be a MT bug. It would turn out that not only are the arrays not used, but they (unallocated) could still be initialized and it would affect the mapping...

Without code it's hard. Let us know what the service desk says afterwards.
 
Anatoli Kazharski:
It's difficult without the code. Let me know what the service department says afterwards.
I will.
 
Anatoli Kazharski:
It's difficult without code. Let me know here later what the service desk says.

Here's the test code, if you're interested.

Initially, the indicator parameter is false.

We put the indicator on the chart. It plots a histogram.

We set the parameters as true.

It draws the histogram and arrows.

Make the parameter false. On the current TF arrows disappear (not always). If we switch to different TFs, arrows appear chaotically in some of them in spite of buffers clearing at deinitialization.

#property indicator_separate_window
#property indicator_plots 3
#property indicator_buffers 4
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
input bool inpUseArrows=false;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double bufGisto[];
double bufGistoColor[];
double bufArrowUp[];
double bufArrowDn[];
//---
const double EMPTY=EMPTY_VALUE;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Размечаем массив цветов
   color colors[2];
   colors[ 0 ]= clrLime;
   colors[ 1 ] = clrRed;
//--- Устанавливаем параметры графических серий
   SetPlotParametersColorHistogram(0,0,bufGisto,bufGistoColor,false,"test gisto",colors,EMPTY,2);
//--- Проверяем, нужно ли отображать объемы
   if(inpUseArrows) // Если отображать нужно
     {
      SetPlotParametersArrow(1,2,bufArrowUp,false,"test up",EMPTY,clrLime,233,10);
      SetPlotParametersArrow(2,3,bufArrowDn,false,"test dn",EMPTY,clrRed,234,-10);
     }
//---
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(inpUseArrows)
     {
      ArrayInitialize(bufArrowUp,EMPTY);
      ArrayInitialize(bufArrowDn,EMPTY);
     }
  }
//+------------------------------------------------------------------+
//| 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==0)
     {
      ArrayInitialize(bufGisto,EMPTY);
      //---
      if(inpUseArrows)
        {
         ArrayInitialize(bufArrowUp,EMPTY);
         ArrayInitialize(bufArrowDn,EMPTY);
        }
      //---
      for(int i=0; i<rates_total; i++)
        {
         bufGisto[i]=(open[i]-close[i])/_Point;
         bufGistoColor[i]=(bufGisto[i]<0) ? 1 : 0;
         //---
         if(inpUseArrows)
           {
            if(bufGisto[i]>20)
               bufArrowDn[i]=bufGisto[i];
            else if(bufGisto[i]<-20)
               bufArrowUp[i]=bufGisto[i];
           }
        }
     }
   else if(rates_total>prev_calculated)
     {
      bufGisto[rates_total-1]=EMPTY;
      //---
      if(inpUseArrows)
        {
         bufArrowUp[ rates_total-1 ] = EMPTY;
         bufArrowDn[ rates_total-1 ] = EMPTY;
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Параметры графического построения: цветная гист-а от 0 линии                |
//+------------------------------------------------------------------+
void SetPlotParametersColorHistogram(const int plotIndex,// Индекс графической серии
                                     const int bufferNum,// Номер первого буфера серии
                                     double& value[],                              // Буфер значений
                                     double& clr[],                                 // Буфер цветов
                                     const bool asSeries,                           // Флаг нумерации как в таймсерии
                                     const string label,                           // Имя серии
                                     const color& colors[],                        // Цвета линии
                                     const double emptyValue = EMPTY_VALUE,         // Пустые значения серии
                                     const int width = 0,                           // Толщина линии
                                     const ENUM_LINE_STYLE style = STYLE_SOLID,      // Стиль линии
                                     const int drawBegin = 0,                        // Количество баров без отрисовки
                                     const int shift=0                           // Сдвиг построения в барах
                                     )
  {
//--- Привязываем буферы
   SetIndexBuffer(bufferNum,value,INDICATOR_DATA);
   SetIndexBuffer(bufferNum+1,clr,INDICATOR_COLOR_INDEX);
//--- Устанавливаем порядок нумерации в массивах-буферах
   ArraySetAsSeries(value,asSeries);
   ArraySetAsSeries(clr,asSeries);
//--- Устанавливаем тип графического построения
   PlotIndexSetInteger(plotIndex,PLOT_DRAW_TYPE,DRAW_COLOR_HISTOGRAM);
//--- Устанавливаем имя графической серии
   PlotIndexSetString(plotIndex,PLOT_LABEL,label);
//--- Устанавливаем пустые значения в буферах
   PlotIndexSetDouble(plotIndex,PLOT_EMPTY_VALUE,emptyValue);
//--- Устанавливаем количество цветов индикатора
   const int size=ArraySize(colors);
   PlotIndexSetInteger(plotIndex,PLOT_COLOR_INDEXES,size);
//--- Устанавливаем цвета индикатора
   for(int i=0; i<size; i++)
      PlotIndexSetInteger(plotIndex,PLOT_LINE_COLOR,i,colors[i]);
//--- Устанавливаем толщину линии
   PlotIndexSetInteger(plotIndex,PLOT_LINE_WIDTH,width);
//--- Устанавливаем стиль линии
   PlotIndexSetInteger(plotIndex,PLOT_LINE_STYLE,style);
//--- Устанавливаем количество баров без отрисовки и значений в DataWindow
   PlotIndexSetInteger(plotIndex,PLOT_DRAW_BEGIN,drawBegin);
//--- Устанавливаем сдвиг графического построения по оси времени в барах
   PlotIndexSetInteger(plotIndex,PLOT_SHIFT,shift);
  }
//+------------------------------------------------------------------+
//| Параметры графического построения: стрелки                                                          |
//+------------------------------------------------------------------+
void SetPlotParametersArrow(const int plotIndex,// Индекс графической серии
                            const int bufferNum,// Номер первого буфера серии
                            double &value[],// Буфер значений
                            const bool asSeries,// Флаг нумерации как в таймсерии
                            const string label,// Имя серии
                            const double emptyValue=EMPTY_VALUE,// Пустые значения серии
                            const color clr=clrRed,// Цвет стрелок
                            const int arrowCode= 159,// Код стрелок
                            const int arrowShift = 0,// Сдвиг стрелок по вертикали
                            const int width=0,// Толщина стрелок
                            const int drawBegin=0,// Количество баров без отрисовки
                            const int shift=0                     // Сдвиг построения в барах
                            )
  {
//--- Привязываем буферы
   SetIndexBuffer(bufferNum,value,INDICATOR_DATA);
//--- Устанавливаем порядок нумерации в массивах-буферах
   ArraySetAsSeries(value,asSeries);
//--- Устанавливаем тип графического построения
   PlotIndexSetInteger(plotIndex,PLOT_DRAW_TYPE,DRAW_ARROW);
//--- Устанавливаем имя графической серии
   PlotIndexSetString(plotIndex,PLOT_LABEL,label);
//--- Устанавливаем пустые значения в буферах
   PlotIndexSetDouble(plotIndex,PLOT_EMPTY_VALUE,emptyValue);
//--- Устанавливаем цвет индикатора
   PlotIndexSetInteger(plotIndex,PLOT_LINE_COLOR,0,clr);
//--- Устанавливаем код стрелок
   PlotIndexSetInteger(plotIndex,PLOT_ARROW,arrowCode);
//--- Устанавливаем смещение стрелок по вертикали
   PlotIndexSetInteger(plotIndex,PLOT_ARROW_SHIFT,arrowShift);
//--- Устанавливаем толщину стрелок
   PlotIndexSetInteger(plotIndex,PLOT_LINE_WIDTH,width);
//--- Устанавливаем количество баров без отрисовки и значений в DataWindow
   PlotIndexSetInteger(plotIndex,PLOT_DRAW_BEGIN,drawBegin);
//--- Устанавливаем сдвиг графического построения по оси времени в барах
   PlotIndexSetInteger(plotIndex,PLOT_SHIFT,shift);
  }
//+------------------------------------------------------------------+
 
Anatoli Kazharski:
It's not going anywhere. Servicedesk #1832411x64, 1643.
 
Alexey Kozitsyn:
It doesn't go in any way. Service Desk #1832411x64, 1643.

Regardless of whether you specify arrays for the arrows as buffers, they are still hardwired:

#property indicator_plots   3
#property indicator_buffers 4

//---

Alternatively, if arrows do not need to be displayed, they can simply be excluded from display by DRAW_NONE.

Try this way:

...
//--- Проверяем, нужно ли отображать объемы
   if(inpUseArrows) // Если отображать нужно
     {
      SetPlotParametersArrow(1,2,bufArrowUp,false,"test up",EMPTY,clrLime,233,10);
      SetPlotParametersArrow(2,3,bufArrowDn,false,"test dn",EMPTY,clrRed,234,-10);
     }
   else
     {
      //--- Устанавливаем тип графического построения
      PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_NONE);
      PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_NONE);
     }

...

 
Anatoli Kazharski:

Regardless of whether you specify arrays for the arrows as buffers, they are still hardwired:

//---

Alternatively, if arrows do not need to be displayed, they can simply be excluded from display by DRAW_NONE.

Try this variant:

I thought about it, but there is a disadvantage here. Arrays will be automatically marked and expanded, eating up resource. The developers'd better let the bug be fixed.

And what about being hard-coded... If I don't bind buffers to graphical series - why do I see some unknown rubbish, which I can't get rid of.

Otherwise it turns out that dynamic indicators cannot be built normally.

The most ideal option is to clean buffers in deinit and that's it. But clearing doesn't help...

 

In ME, please show ALT+M in the list of functions/methods the type of return value.

 

It would be nice to introduce a distinction on string type as it is used in other languages to a regular string and a "raw" string. I think they will come to this anyway, but at the initial stage it would eliminate many problems in the future.

For example Python uses r "string" to create a "raw" string
 

What's the reason for not fully outputting the logs in the tester? Everything you can look at has been looked at and checked, can't beat it.

 
Andrey Dik:

What is the reason for the logs not being fully displayed in the tester? All that can be looked at - looked at and checked, can't beat it.

A lot of entries. See log file.

Reason: