Color Formulas

Extending The Range

Palette Editing

article 3/5

The majority of indicators use a limited number of plots, so a few basic colors can accommodate most charting requirements. Combining this with the fact that the primary colors are easier to distinguish apart, compared to graduations of any one color, makes the colors of the rainbow a stand-out choice for everyday color preferences. Conveniently, ROYGBIV is a mnemonic that makes the rainbow numbers easy to remember when using color indexing for quick code writing.

The first sixteen numbers of the color index are reserved for custom colors, so this provides an opportunity to apply this system. (The color index is based on a zero count system so the available numbers are 0 – 15).


To match the colors of the rainbow to number 2 – 8 of the color index:

a) go to Tools > Preferences > Colors [TAB] and click on the Palette editor button ( the Color window will open);
b) select the first box in the top row of Custom colors;


c) click on White, in the Basic colors table;


d) click on the Add to Custom Colors button (White will become colorCustom1 or index number 0).


e) select the second box in the top row of Custom colors;
f) click on Black, in the Basic colors table;
g) click on the Add to Custom Colors button (Black will become colorCustom2 or index number 1, which is the installed default for black).
e) Repeat the three stop process for Red, Orange, Yellow, Green, Blue, Indigo and Violet using boxes 3 – 9 inclusive.
f) Use the same procedure to set the remaining seven to any preferred color.
g) Close the Color window and click on Apply on the Preferences window before closing it (this will confirm the new color settings).

To use a color that is not in the Basic color table:

a) select the Custom color box to be changed, followed by the Basic color;
b) then modify the selected Basic color’s Luminescence by dragging the arrow head up and down the vertical scale. (In this example the graduated shades of grey were added to Custom Colors 13 – 16 using this technique).


c) Additionally the Hue or the Saturation can be changed by clicking and holding on the moving cursor, inside the color matrix panel, and dragging it up/down (Saturation) or left/right (Hue).
d) When the desired color is produced in the large Color/Solid box click the Add button.
e) Click on Apply on the way out.


(In this example the Basic color Medium Grey has been changed slightly by the addition of a little Blue and a slight reduction in Red (Saturation), as well as changes to the Hue settings, while the Luminescence is constant).

The new Custom Color settings will now be available in the Color Picker, or within formulas via color index numbers 0 – 7 and 8 – 15, or colorCustom1-16.


(Note that for maximum contrast between the colors it is better to use only six colors, along with black and white, as there are only three primary colors (RYB) with three possible primary combinations between them (O,G,V). Indigo is an exceptional color, not being derived solely from the Primary Colors. For this reason it is hard to distinguish between Indigo and Blue or Violet, so for clarity Indigo can be left out if desired).

Colored Plots

article 1/5

Color Picking

article 2/5

In AmiBroker, the colors of many of the chart elements can be customized from within simple AFL formulas. The most common application of this feature is when plotting indicators, where the third parameter of the Plot() function allows users to set the color to their own preference e.g. Plot(C,"Close",colorRed, styleLine).

A short hand method, to specify the color, is to substitute colorRed with the number 32, which is the color index number for Red e.g. Plot(C,"Close",32, styleLine). It can, however, be difficult to remember the color names and the index numbers. (Refer to the AFL Reference Manual reserved variables table for the complete list).

The Color-Picker, on the Format Toolbar, is used as a graphical method for setting the color of drawing objects placed on the chart, as well as chart plots. It can also act as a handy reminder tool when stipulating color preferences in formulas. A prompt appears, when the mouse is hovered over the Color-Picker, and provides the correct name for each color. The name can then be appended to the color parameter within formulas.

To use the Color-Picker as a name prompt:

a) open it from the drop-down on the Format Toolbar. (Note that the Color-Picker can be opened in the background, to act as a dynamic prompt, while working with the Formula Editor window open);


b) position the mouse over the color of choice.


c) replace Name, in colorName parameters, with the color title exactly as written e.g. colorName becomes colorRed. (Remove all gaps, hyphens and special characters e.g. Grey-50% becomes Grey50. Note that there are a few exceptions; Grey-80% becomes DarkGrey, Grey-25% becomes LightGrey, Light Green becomes PaleGreen and Light Turquoise becomes PaleTurquoise).

To use the Color-Picker as a color index prompt:

a) open the Color-Picker;
b) choose the preferred color, and obtain it’s index number, by counting to the right from the first number in each row (the index is zero based, and the first sixteen colors are reserved for custom colors, so the first row starts with 16 and the second starts with 16 + 8 = = 24 etc. (The color index number for Red, as the first color in the third row, is therefore 32).


Color indexing is a better method of changing colors, at the formula level, than using colorNames, as it is quicker and there are no exceptions to remember. As an example, the formula in the Editor image above, which was originally used in the Users’ Knowledge Base post ’How Many Trading Days In A Calendar Year?’ with colorBlack and styleLine settings, has been changed to a colorRed styleHistogram chart using the shorthand color index 32 (text highlighted in yellow).


The Color-Picker can be torn-off the toolbar if required:

a) drop the Color-Picker down;
b) click and hold the mouse pointer on the tear-off line;


c) when a moving pointer appears the window can be dragged to the desired position.