Colored Plots

article 1/5

The most used color, for chart plotting, is black, but this can be changed using simple AFL formulas.
This will be demonstrated in this article using the following code as a template.

(The template can be downloaded from the file attached to the end of this post and the lines commented/uncommented as required. Note that the attached file has been stripped of it’s capitals, and the underscore character, by the editing software used by the author. After downloading and saving the file rename it as written in this post).

1
2
3
4
5
6
7
/*P_PriceFields*/
 
Plot(C,"Close",colorBlack,styleLine);
//Plot(C,"Close",colorBlack);
//Plot(C,"Close",colorRed);
//color = ParamColor("color",colorRed); 
//Plot(C,"Close",color);


At the most fundamental level colors are customized from within formulas.

To create a black line price chart in a new pane:

a) open Formula Editor from the Tools Toolbar,

CustomColorsBasic003

b) copy/paste or type line 3 of the code into a new Formula Editor page,
c) check the syntax using the Verify Syntax tool from the Formula Editor Standard Toolbar before saving it as P_PriceFields,


CustomColorsBasic007


d) apply it as an indicator using the icon on the Formula Editor Standard Toolbar, (the chart will be opened in a new pane in the current window),


CustomColorsBasic005


Line view is the default for all charts, so it isn’t necessary to stipulate the styleName on every occasion.
The code can be shortened by leaving out the style setting, if Line is the preferred view.

To change the formula to line view as the default:

a) copy/paste line 3 of the code into line 4,
b) comment out line 3 by putting two forward slashes before the line (this line will then be ignored when the formula is processed),
c) delete styleLine from the line 4 code and save the new version (the result will be visible in the chart).


CustomColorsBasic008


(Note that when an indicator is applied from the Formula Editor toolbar the chart it opens interacts dynamically with the formula, so that the effect of changes to the formula can be immediately seen in the chart, once the formula has to be saved).

To change the color of chart plots:

a) copy line 4 of the code and paste it into line 5,
b) comment out line 4,
c) change colorBlack to colorRed in line 5.


CustomColorsBasic009


For convenience the color parameter can be accessed graphically by adding the Parameter function to the formula.

To add color to the Parameter options list:

a) comment out line 5,
b) add line 6 and 7 to the formula and Save,
c) right click inside the Chart and select Parameters from the context menu that appears, (the Properties window will open with the Parameter tabbed page in view),


CustomColorsBasic010


d) select a color from the Color-Picker that drops down, (the plot will then change color to match).


CustomColorsBasic013

(Note that whenever a formula, with the color parameter included, is inserted into a chart, the Parameter Window will open automatically and offer the user the choice of colors, for plotting, before proceeding).


Attached Files:


right click .afl files and Save Target As to download to the desktop at Program Files/AmiBroker/Formulas/Custom then access them as a formulas within AmiBroker Charts.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.67 out of 5)
Loading ... Loading ...

2 Responses to “Colored Plots”

  1. August 21st, 2007 | 10:44 am

    THE BASIC COLOR CODES
    green = 1; blue = 2; yellow = 3; red = 4; white = 5;

  2. Brian
    August 22nd, 2007 | 2:19 am

    I’m not familiar with the Basic Color Code. I don’t have a computing background so I am limited to the basics in most areas. I guess it is something from the computer lexicon?
    I assume you are suggesting an alternative color schema?

    Any system that people are familiar with, and can remember, is handy.

    I looked up the numbers in the AFL ref manual for a long time and it was a load off my back when I finally got around to setting up some custom colors – I soon memorised the 16 that I use. I also find that it works well for me because when I do use multiple plots I can simply start at the beginning of the CustomColor series and ‘work my way up’. I don’t need to stop and think about it because I know what is coming next and what it will lool like when plotted.

    Colors are definitely personal preference. For everyday use I like to use a few basic colors that are easy to tell apart when plotted as a thin line. I use a white background, and find the contrast of black too harsh, so I use white and grey as the primaries. Yellow tends to disappear on a white background, and obviously I have no need for white, so for my own use I replaced them with cyan and magenta so that brings my custom color set close to the 3-bit RGB or 4-bit RGBI palette. By comparison some of the colors of a 6-bit RGB palette are too close together to be of practical use when plotting.

    On the rare occasion that I use more than 16 plots in one chart, alternating the 16 custom colors with different line styles extends the range.

    http://en.wikipedia.org/wiki/List_of_palettes#3-bit_RGB

Leave a reply