The DRAW_COLOR_SECTION style is a color version of DRAW_SECTION, but unlike the latter, it allows drawing sections of different colors. The DRAW_COLOR_SECTION style, like all color styles with the word COLOR in their title, contains an additional special indicator buffer that stores the color index (number) from a specially set array of colors. Thus, the color of each sections can be defined by specifying the color index of the index of the bar that corresponds to the section end.
The width, color and style of the sections can be specified like for the DRAW_SECTION style - using compiler directives or dynamically using the PlotIndexSetInteger() function. Dynamic changes of the plotting properties allows "to enliven" indicators, so that their appearance changes depending on the current situation.
Sections are drawn from one non-empty value to another non-empty value of the indicator buffer, empty values are ignored. To specify what value should be considered as "empty", set this value in the PLOT_EMPTY_VALUE property: For example, if the indicator should be drawn as a sequence of sections on non-zero values, then you need to set the zero value as an empty one:
Always explicitly fill in the values of the indicator buffers, set an empty value in a buffer to the elements that should not be plotted.
The number of buffers required for plotting DRAW_COLOR_SECTION is 2.
•one buffer to store the indicator values used for drawing a line;
•one buffer to store the color index, which is used to draw the section (it makes sense to set only non-empty values).
Colors can be specified by the compiler directive #property indicator_color1 separated by a comma. The number of colors cannot exceed 64.
An example of the indicator that draws colored sections each 5 bars long, using the High price values. The color, width and style of sections change randomly every N ticks.
Note that initially for plot1 with DRAW_COLOR_SECTION 8 colors are set using the compiler directive #property. Then in the OnCalculate() function, colors are set randomly from the array of colors colors.
The N parameter is set in external parameters of the indicator for the possibility of manual configuration (the Parameters tab in the indicator's Properties window).