images/contents.gifimages/index.gifimages/prev1.gifimages/next0.gif

Writing Color Rule Expressions

A simple example of a color rule expression is:

IF($1.close>$1.close[1],CLR_GREEN, CLR_RED)

where $1.close denotes the data series being colored, CLR_GREEN is the value if true, and CLR_RED is the value if false (built-in constants), and IF() is the logical function that governs the comparison. When applied to a bar data series, this rule causes bars with up closes (closes greater than prior bars close) to be painted green. Bars that do not satisfy this condition are painted red. If you were to apply this color rule to a moving average, rising parts of the study line are green while falling parts red.

In a color rule expression, you can refer to the data series being colored as a SERIES or $1. Any expression written in formula language can be used. The program evaluates a color rule expression once for each bar in a chart window; prior bars of the data series are accessible by subscripting. For more detailed information on the formula language and subscripting, please read chapter 15, Formulas.

When coloring the results of studies, you can refer to the underlying chart datathat is, the instrument or primitive formula on which the study is calculated. This data item is accessible as RAWDATA or $2. For example, if you are coloring the result of an RSI study, then,

IF(SERIES>SERIES[1], CLR_GREEN, CLR_RED)

produces a green where the RSI value is rising, whereas

IF(RAWDATA>RAWDATA[1], CLR_GREEN, CLR_RED)

produces green where the underlying bar data is rising, regardless of the RSI value.

When coloring basic bar charts, tick charts, etc., the SERIES and RAWDATA parameters are equivalent.

The result of a color rule formula is taken as a numeric code for the colors you want to use. You can use the following color names, or a unique numeric code to specify the colors you want drawn:

Color
Value
Clr_Yellow
0
Clr_Green
1
Clr_Cyan
2
Clr_White
3
Clr_Violet
4
Clr_Pink
5
Clr_Orange
6
Clr_Gray
7
Clr_Red
8
Clr_Blue
9
Clr_Purple
10
Clr_Black
11

The character string "CLR_" must be used before all proper names of colors. This convention avoids conflicts with NASDAQ level two instrument symbols (such symbol names include CYAN, and PINK).

You can write either CLR_GREEN or 1 and get the same result, but using the names will make your color rule formulas easier to understand. These twelve color names are reserved words in the formula language.

If you elect to use a numeric code instead of a color name, be careful to use a numeric code in the range of 0 to 11, as shown in the table above. If you make a mistake and specify a color code outside the range 0-11, the program divides the number you enter by 12 and uses the remainder as the numeric for the color code.