Buffer Number and Plot Index. What's the connection?

 

For example, the following code works as expected. The first plot, with plot index 0 uses data from buffer 0 and the second plot with index 1 uses data from buffer 1. Does this mean that the plot is associated with it's buffer by it's index number? eg. Plot 0 = Buffer 0, Plot 1 = Buffer 1. Or, is the association made some other way?

What I'm trying to achieve is to use ExtCalcBuffer1 as buffer 0, ExtDataBuffer1 as buffer 1 and ExtDataBuffer2 as buffer 2 in my indicator and refer to ExtCalcBuffer1 as buffer 0 in my EA code - buffer 1 and buffer 2 not being needed. I tried setting ExtCalcBuffer1 as buffer 0, ExtDataBuffer1 as buffer 1 and ExtDataBuffer2 as buffer 2, but only one plot appeared.

Thank you.

#property indicator_buffers 3
#property indicator_plots   2

SetIndexBuffer(0, ExtDataBuffer1, INDICATOR_DATA);
SetIndexBuffer(1, ExtDataBuffer2, INDICATOR_DATA);
SetIndexBuffer(2, ExtCalcBuffer1, INDICATOR_CALCULATIONS);

PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_ARROW);

 

I can't explain it well, but if you program it like this, it should display correctly.

#property indicator_buffers 3
#property indicator_plots   3

//--- plot ExtDataBuffer1
#property indicator_label2  "ExtDataBuffer1"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot ExtDataBuffer2
#property indicator_label3  "ExtDataBuffer2"
#property indicator_type3   DRAW_ARROW
#property indicator_color3  clrRed
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1

SetIndexBuffer(0, ExtCalcBuffer1, INDICATOR_CALCULATIONS);
SetIndexBuffer(1, ExtDataBuffer1, INDICATOR_DATA);
SetIndexBuffer(2, ExtDataBuffer2, INDICATOR_DATA);

PlotIndexSetInteger(1, PLOT_ARROW, 233);
PlotIndexSetInteger(2, PLOT_ARROW, 234);
 

Thank you Naguisa


This does work, but having to declare the number of plots to be 3, which is understandably confusing, when there are only 2. Where is this mentioned in the documentation?

In the relatively short time I've been using MQL5 I must say that the documentation is incredibly lacking. Without these forums to fill up the gaping holes, our life as programmers would be near impossible.

 

I don't know it.

Typically, the buffer used for plotting is placed before the calculating buffers, and the number of plots is counted from the first to N.

In this case, the number 0 is not plotted, but since the number 1 and 2 is plotted, the total is 3.

I understand like the way.
 
robnorthen:

Thank you Naguisa


This does work, but having to declare the number of plots to be 3, which is understandably confusing, when there are only 2. Where is this mentioned in the documentation?

In the relatively short time I've been using MQL5 I must say that the documentation is incredibly lacking. Without these forums to fill up the gaping holes, our life as programmers would be near impossible.

The problem of the documentation is not it "is incredibly lacking", the problem is it's scattered and sometimes not well translated (and so not always perfectly clear).

The other problem is people don't read it, mostly the ones complaining about it.

Documentation (snippet) :

Graphical plots automatically use indicator buffers in accordance with the plot number. Numbering of plots starts with 1, numbering of buffers starts with zero. If the first plotting requires 4 indicator buffers, then the first 4 indicator buffers will be used to draw it. These four buffers should be linked with the appropriate arrays with correct indexing using the SetIndexBuffer() function.
Documentation on MQL5: Custom Indicators / Indicator Styles in Examples
Documentation on MQL5: Custom Indicators / Indicator Styles in Examples
  • www.mql5.com
The MetaTrader 5 Client Terminal includes 38 technical indicators that can be used in MQL5 programs using appropriate functions. But the main advantage of the MQL5 language is the ability to create custom indicators, which can then be used in Expert Advisors or simply applied on price charts for the purpose of technical analysis. The entire set...
Reason: