Errors, bugs, questions - page 1093

 
zfs:
Empty there, even though the colour is set in the code. With all that said, the positive result was there, but it disappeared, no matter how ridiculous it sounds).
Then a short code reproducing the problem would help to sort it out.
 
tol64:
Then a short code reproducing the problem will help.
#property indicator_separate_window

#property indicator_buffers 6                 // Количество буферов для расчёта индикатора
#property indicator_plots   2                 // Количество графических серий

#property  indicator_label1  "Open;High;Low;Close"

//перечисление методов отображения индикатора
enum ViewInd
  {
   Line,               // линии
   Bar,                // бары
   Candles             // свечи
  }; 
  
input ViewInd      _ViewInd= Line;     //вид индикатора  

double op[],cl[],hi[],lo[],s[];
double buffer_color_line[];//Буфер для индекса цвета



int OnInit()
  {
   for (int i=0;i<=5;i++)
    PlotIndexSetDouble(i,PLOT_EMPTY_VALUE,0);
   ArrayInitialize(op,0);ArrayInitialize(cl,0);  
   ArrayInitialize(hi,0);ArrayInitialize(lo,0);  
   ArrayInitialize(s,0);     

    
   if(_ViewInd==Line){
    SetIndexBuffer(5,s,INDICATOR_DATA);//Привязка массива к буферу
    PlotIndexSetInteger(5,PLOT_DRAW_TYPE,DRAW_LINE);
    PlotIndexSetInteger(5,PLOT_LINE_STYLE,STYLE_SOLID);
    PlotIndexSetInteger(5,PLOT_LINE_COLOR,clrRed);
    ArraySetAsSeries(s,true);
   }
   else{
   SetIndexBuffer(0,op,INDICATOR_DATA);
   SetIndexBuffer(1,hi,INDICATOR_DATA);
   SetIndexBuffer(2,lo,INDICATOR_DATA);
   SetIndexBuffer(3,cl,INDICATOR_DATA);
   SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX);//Сопоставляем массив-буфер индексов цветов с буфером индикатора
   ArraySetAsSeries(op,true);
   ArraySetAsSeries(hi,true);
   ArraySetAsSeries(lo,true);
   ArraySetAsSeries(cl,true);   
   ArraySetAsSeries(buffer_color_line,true);      
//Задаем количество индексов цветов для графического построения
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
   if (_ViewInd==Candles)PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_COLOR_CANDLES); else
    PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_BARS);
//Задаем цвет для каждого индекса
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrBlue);   //Нулевой индекс -> Синий
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrOrange); //Первый индекс  -> Оранжевый   
   }   
//---
   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 limit;//MQL 4 RULEZZZ
   int counted_bars=prev_calculated;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=rates_total-counted_bars;
   
   for (int i=0;i<limit;i++){
    if(_ViewInd==Line)s[i]=MathRand();
    else{
     op[i]=MathRand();
     cl[i]=MathRand();
   if (op[i]>cl[i])buffer_color_line[i]=1;else buffer_color_line[i]=0;
     hi[i]=32767;
     lo[i]=0;        
    }  
   }

   return(rates_total);
  }
//+------------------------------------------------------------------+
It goes something like this.
 
zfs:
Like this.

This is how the values after the short name will appear

for (int i=0;i<=5;i++)
    {PlotIndexSetDouble(i,PLOT_EMPTY_VALUE,0);};
This is about the order in the buffers. https://www.mql5.com/ru/forum/12882#comment_539990
В каком порядке делать SetIndexBuffer() и зависит ли он он порядка директив #property indicator_x ?
В каком порядке делать SetIndexBuffer() и зависит ли он он порядка директив #property indicator_x ?
  • www.mql5.com
может ли кто-то на пальцах обьяснить правила привязки индикаторного буфера к опр.
 
And how it helps me, I don't understand anything). Something can be changed to make it work, but it's still crooked, and I'd like to know more about it.
 
zfs:
It goes something like this.

Total chaos and mess. ) Here's a working version (corrected the mistakes and brushed it up):

//+------------------------------------------------------------------+
//|                                                        #Test.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
//---
#property indicator_buffers 5 // Количество буферов для расчёта индикатора
#property indicator_plots   1 // Количество графических серий
//---
#property  indicator_color1  clrDodgerBlue,C'0,50,100'
//--- Перечисление методов отображения индикатора
enum ViewInd
  {
   Line,   // линии
   Bar,    // бары
   Candles // свечи
  };
//--- Внешние параметры
input ViewInd _ViewInd=Line; // Вид индикатора  
//---
double op[],cl[],hi[],lo[];
double buffer_color_line[]; // Буфер для индекса цвета
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(_ViewInd==Line)
     {
      //--- Привязка массива к буферу
      SetIndexBuffer(0,cl,INDICATOR_DATA);
      //---
      PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
      PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_SOLID);
     }
   else
     {
      SetIndexBuffer(0,op,INDICATOR_DATA);
      SetIndexBuffer(1,hi,INDICATOR_DATA);
      SetIndexBuffer(2,lo,INDICATOR_DATA);
      SetIndexBuffer(3,cl,INDICATOR_DATA);
      //--- Сопоставляем массив-буфер индексов цветов с буфером индикатора
      SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX);
      //---
      if(_ViewInd==Candles)
         PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_CANDLES);
      else
         PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_BARS);
     }
//--- Установим метки для текущего таймфрейма
//    В режиме линия только цена закрытия
   if(_ViewInd==Line)
      PlotIndexSetString(0,PLOT_LABEL,"Close");
//--- В других режимах все цены баров/свеч
//    В качестве разделителя используется ";"
   else if(_ViewInd==Bar || _ViewInd==Candles)
      PlotIndexSetString(0,PLOT_LABEL,"Open;"+"High;"+"Low;"+"Close");
//---
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
//---
   ArrayInitialize(op,0);
   ArrayInitialize(cl,0);
   ArrayInitialize(hi,0);
   ArrayInitialize(lo,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 limit=0; //MQL 4 RULEZZZ
//---
   if(prev_calculated==0)
      limit=0;
   else
      limit=prev_calculated-1;
//---
   for(int i=limit; i<rates_total; i++)
     {
      if(_ViewInd==Line)
         cl[i]=MathRand();
      else
        {
         op[i]=MathRand();
         cl[i]=MathRand();
         hi[i]=32767;
         lo[i]=1;
         //---
         if(op[i]>cl[i])
            buffer_color_line[i]=1;
         else
            buffer_color_line[i]=0;
        }
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

How does it work

if(_ViewInd==Line){
}
   else{

if (_ViewInd==Candles)
else

if

enum ViewInd
  {
   Line,               // линии
   Bar,                // бары
   Candles             // свечи
  }; 

?

Double-check all conditions and brackets, and without a loop, set the buffer properties linearly, order from the link above.

 
Silent:

...

Double-check all conditions and brackets, and set buffer properties linearly without a loop, order from link above.

A loop is not needed there at all. More precisely, the property only needs to be set for one buffer, in all mapping options.
 
tol64:
There's no need for a loop at all.
Generally yes, but if there are a lot of buffers, it's shorter :-) although I don't do that. It's easier for me to read linear portraits.
 
Silent:
Generally yes, but if there are a lot of buffers, it's kind of shorter :-) although I don't do that. It's easier for me to read linear portmanteaus.
In fact, there can be so many buffers (max 512), that it's much harder to read the knitting without loops. ) In this variant there is just one buffer.
 
tol64:
There's no need for a loop at all.
Great). Thank you. Like clockwork. The cognac is chilling).