Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1129

 
Alexey Viktorov:

Why do you have to make such a big deal out of yourself? What's the problem with assigning the buffers to be displayed first and then the auxiliary buffers?

A peculiarity of the algorithm, the auxiliary buffers are always a fixed number, while the number of buffers to be displayed varies. Please answer the question from the previous post about how to specify it all correctly?


Alexey Viktorov:

For DRAW_HISTOGRAM2 3 buffers are specified and the sequence is mandatory, 2 value buffers first followed by a colour buffer. But there is a difference between DRAW_HISTOGRAM and DRAW_HISTOGRAM2 in that DRAW_HISTOGRAM is drawn from zero to the value in the buffer, while DRAW_HISTOGRAM2 is drawn from the value of one buffer to the value of another buffer.

From the description of DRAW_HISTOGRAM2 at https://www.mql5.com/ru/docs/customind/indicators_examples/draw_histogram2 :

"The number of buffers required to build DRAW_HISTOGRAM2 is 2."

Where would the third buffer come from then? And in the example in the same link there are only two buffers, but it is not specified whether the colours can be interleaved in the same way as with a normal DRAW_HISTOGRA?
 
The_Sheikh:

A peculiarity of the algorithm, the auxiliary buffers are always a fixed number, while the number of mapped buffers varies. Please answer the question from the previous post about how to specify it all correctly?


From the description of DRAW_HISTOGRAM2 at https://www.mql5.com/ru/docs/customind/indicators_examples/draw_histogram2 :

"The number of buffers required to build DRAW_HISTOGRAM2 is 2."

Where would the third buffer come from then? And in the example in the same link there are only two buffers, but it is not specified whether the colours can be interleaved in the same way as with a normal DRAW_HISTOGRA?

Yes, sorry for my lack of attention. I meant DRAW_COLOR_HISTOGRAM2 and DRAW_COLOR_HISTOGRAM

 
The_Sheikh:

A peculiarity of the algorithm, the auxiliary buffers are always a fixed number and the displayed buffers are a different number. Please answer the question from the previous post about how to specify all this correctly?

I've never made fun of myself like this before. If you're willing, experiment.

 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 

How do I set the colours correctly with PlotIndexSetInteger()?

When I set

#property indicator_color3 clrRed,clrGreen

the colours are set correctly, but when I use the

PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,clrRed);

PlotIndexSetInteger(2,PLOT_LINE_COLOR,1,clrGreen);

then the first colour of the line is red, but the second (and subsequent ones) are black (by default) instead of green for some reason.

 
The_Sheikh:

How do I set the colours correctly with PlotIndexSetInteger()?

When I set

#property indicator_color3 clrRed,clrGreen

the colours are set correctly, but when I use the

PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,clrRed);

PlotIndexSetInteger(2,PLOT_LINE_COLOR,1,clrGreen);

then the first colour of the line is red, but the second is black (by default) instead of green for some reason.

Why put a modifier in there?

 
Alexey Viktorov:

Why put a modifier in there?

Which one, where? I looked at the example in MQL5 documentation and did the same. Write it down, how is it correct?

 
The_Sheikh:

Which one, where? I looked at the example in the MQL5 documentation and did the same. Write it down, how is it correct?

Show all code for initialisation of indicator buffers.
 
The_Sheikh:

Which one, where? I looked at the example in MQL5 documentation and did the same. How to do it right?

Looked it up

bool  PlotIndexSetInteger( 
   int  plot_index,        // индекс графического стиля 
   int  prop_id,           // идентификатор свойства 
   int  prop_value         // устанавливаемое значение 
   );

and did this.

bool  PlotIndexSetInteger( 
   int  2,                 // индекс графического стиля 
   int  PLOT_LINE_COLOR,   // идентификатор свойства 
   int  0,                 // модификатор свойства 
   int  clrGreen           // устанавливаемое значение 
   )

And it says in the documentation

[in] Modifier of specified property. Only colour index properties require a modifier.


This means that the modifier must be if different colours of basement indicator levels, Fibo levels or something similar are to be assigned
 
Artyom Trishkin:
Show all code for initialisation of indicator buffers.

Something like this

#property indicator_chart_window
//#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 2

#define  GreenC 0x00FF00
#define  RedC 0x0000FF
#property indicator_type1 DRAW_NONE
#property indicator_type2 DRAW_COLOR_HISTOGRAM2
//#property indicator_color2 GreenC,RedC

double
Arr11[],
Arr21[],
Arr22[],
Arr23[];

void OnInit()
{
SetIndexBuffer(0,Arr11,INDICATOR_CALCULATIONS);
SetIndexBuffer(1,Arr21,INDICATOR_DATA);
SetIndexBuffer(2,Arr22,INDICATOR_DATA);
SetIndexBuffer(3,Arr23,INDICATOR_COLOR_INDEX);
IndicatorSetInteger(INDICATOR_DIGITS,Digits());
PlotIndexSetInteger(1,PLOT_LINE_WIDTH,4);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,GreenC);
PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,RedC);
//PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);
}

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[]
)
{
ArraySetAsSeries(open,0);
ArraySetAsSeries(close,0);
ArraySetAsSeries(low,0);
ArraySetAsSeries(high,0);
ArrayInitialize(Arr11,0.0);
ArrayInitialize(Arr21,0.0);
ArrayInitialize(Arr22,0.0);
ArrayInitialize(Arr23,0.0);

for (int I=0;I<rates_total;I++)
{
Arr22[I]=low[I];
Arr23[I]=0.0;
//Arr23[I]=1.0;
}

return(rates_total);
}

Alexey Viktorov:

Looked it up

and did this.

And there, in the documentation it says

This means that the modifier should be if different colours of basement indicator levels, fibo levels and something similar are assigned

Exactly my case.

Here's a piece of the example for DRAW_COLOR_HISTOGRAM2 in the manual:

/--- для каждого цветового индекса зададим новый цвет случайным образом
   for(int plot_color_ind=0;plot_color_ind<plot_colors;plot_color_ind++)
     {
      //--- получим случайное число
      int number=MathRand();
      //--- получим индекс в массиве col[] как остаток от целочисленного деления
      int i=number%size;
      //--- установим цвет для каждого индекса как свойство PLOT_LINE_COLOR
      PlotIndexSetInteger(0,                    //  номер графического стиля
                          PLOT_LINE_COLOR,      //  идентификатор свойства
                          plot_color_ind,       //  индекс цвета, куда запишем цвет
                          cols[i]);             //  новый цвет

Here plot_colors = 8, cols[] - array with different colours. But terminal does not perceive any colours except for the first one.

Reason: