Dynamic RGB color matrix for technical indicator

Sometimes we need color changing accordingly to the indicator value, that’s why I created this dynamic color scale matrix that can be added to any already made indicator of any kind in Prorealtime 10.3 and above version.

Dynamic color gradient

The idea behind this code is to modify dynamically the color gradient between a predefined color in 2 separate scale, a positive and a negative one (dark green for bullish sentiment in the example below and dark violet for bearish sentiment) and a middle value that can be adjusted to any value at will in the code.

Let’s take a simple MACD histogram:


and make it have a better look of what’s currently happen:


How to set the dynamic color scale for any indicator?

Firstly, we have to set what is the variable of the indicator that need to be coloured by the gradient scale, this is defined in our code with the “valueentry” variable, which here is equal to the MACD histogram value. Easy!

Then, we need to define the RGB (Red,Green,Blue) values of the positive (or buy zone) and the negative (sell zone) of the 2 colors we’d like to be gradually displayed.

In our example, the green color is: 0,102,0 (R,G,B) and the violet one is 102,0,102 (R,G,B)

Finally, the indicator’maximum, minimum and middle values have to be defined in these 3 lines below:

What I have done here is to set a dynamic maximum and minimum value for the example, since a MACD don’t have any fixed max/min area. This is not the case for any other bounded indicators, such as a RSI or a stochastic oscillator for instance, so if you want to add this color scale to an indicator that oscillate between 100 and -100, the “maxvalue” and “minvalue” should be set  like this:


Full code example:

Another example with an indicator of the library, the T3 Velocity:



This code example could be of course improved to perform a continuous grading color from negative to positive areas (like a rainbow ..), I may code it later. Enjoy this code and make your indicators even more beautiful 🙂

Once again, you can find the full code as ITF files that can be downloaded below this article.



Share this

Register or