TUTORIAL - Creating a new buffer to use indicator colors.
-
Hello friends, there are often questions in the forum about how to use the color change of an indicator as a signal.
As you know, the color change is created in the indicator as a result of a calculation. If we can assign this calculation result as a value along with the color to a separate buffer (although it already exists but is not available as a buffer), you can use it as you wish.
Let's now examine how to do this.
(First of all, be sure to save your indicator under a different name. We don't want to lose its original state.)
First, let's open the indicator with IDE.

Let's add buffer with a new name to the buffer definitions under OnInit. I used the name buffer_value as an example. Use the sequence number when adding a new buffer.
(the following number is 3 in the example).
We increase the number of available buffers by one. Along with this, we also increase the number of buffers to be displayed by one.

In addition to the existing buffer definitions, we add a newly named buffer definition.

Our buffer definitions are finished. Now let's make this buffer get a value:Again, we determine the name of the INDICATOR_COLOR_INDEX buffer in the buffer definitions under OnInit. In this example "valc"

We go to the calculation section in OnCalculate and find the valc calculation (assignment).

What we are looking for is here, the result of Level Up and Level Dn:
((val[i]>inpLevelUp) ? 1 : (val[i]<inpLevelDown) ? 2 )Compile the code you edited and start using it. While there was only one buffer listed before, two buffer options will appear after these operations.
If the buffer value = 1, you can use it as an increase, and if it is 2, you can use it as a decrease.
-
@PhiLykia Simply impressive. Thank you very much.
