June 19, 2007
Color Formulas
When a formula, containing the ParamColor function, is inserted into a new chart the ParamColor default will apply.
Save the following code as P_ForeignRGB and apply it as an indicator to demonstrate this point.
1 2 3 4 5 6 7 8 9 | /*P_ForeignRGB*/ Color = ParamColor("Color",colorCustom2); //Color = ParamColor("Color",ColorRGB(204,0,204)); Plot(C,"Close",Color,styleLine|styleThick); PlotForeign("GM","GM",colorCustom2, styleLine|styleThick); //PlotForeign("GM","GM",ColorRGB(204,0,204), styleLine|styleThick); |
(Note that for this example the style has been changed to a thick line, by adding styleThick to the code, to make it easier to see the color of the plots in a screenshot).
Any one of the 40 colors in the Color-Picker, or the 16 color favorites can be set as the ParamColor default. This can be extended to the full range of colors available in the 24 bit palette i.e. 255 * 255 * 255, which is approximately equal to 16 million colors, by the use of color functions within formulas.
To do this it is necessary to obtain the Red Green Blue numerical code for the color of choice.
To record the Color Matrix numerical code for an extended color:
a) open the ParamColor extended Color Palette (refer to the Users’ Knowledge Base Article ’Custom Colors - Extending The Range’ for instructions),
b) create the color of choice by maneuvering the pointer, either on the Luminescence Bar or within the Color Matrix and make a note of the numerical code for the chosen color e.g. Red 204, Green 0, Blue 204.
c) click on OK and the Properties window will open with the custom color settings displayed e.g. RGB (204,0,204).
The plot color, for the current symbol will change to reflect the parameter setting.
The plot color can be set to use any color in the extended palette as the default.
There are two ways to do this; first by replacing color with a ColorFunction within the standard plot (or plotForeign code) or alternatively by using a ColorFunction within ParamColor arguments.
To change the foreign plot to an extended color:
a) comment out line 8 in the formula and uncomment line 9,
b) type the Red Green Blue (RGB) numerical code into the ColorRGB function arguments exactly as they were written in the Properties box (refer to the example text highlighted in yellow),
c) Save the formula to enact the changes.
To change the current (parametrical) plot to use an extended color as the default (and demonstrate the functionality):
a) comment out line 3,
b) uncomment line 4,
c) Save the formula and then close the Formula Editor,
d) close the lower chart pane by clicking on the cross that appears when the mouse is hovered over the top right hand corner,
e) right click on P_Foreign in the Charts list and then Insert it (this will install a new chart in the lower pane with RGB(204,0,204) as the default color, along with the option of changing the color settings via the Palette Editor, in case you have changed your mind about the color in the few seconds it took to insert the formula).
With the following three lines of code the result in the chart below was produced.
1 2 3 | Color = ParamColor("Color",ColorRGB(204,0,204)); Plot(C,"Close",Color,styleLine|styleThick); PlotForeign("GM","GM",ColorRGB(204,0,204), styleLine|styleThick); |

Notice that the colors are identical.
The good news is, that if you have changed your mind about the current color, you still have the choice of 56 colors in the Picker, or the rest of the 16 million colors in the extended palette up your sleeve.
And now for a little fun let’s type 255, 255, 255 into the Color Matrix and see what we get.
No sense in doing things by half. Let’s try 000.
Finally the ’piece de resistance’.
Try the following code by Tomasz Janeczko (from the AFL Function Reference; ColorHSB examples).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // Example 1: // 3-d multicolor multiple moving average cloud chart side = 1; increment = Param("Increment",2, 1, 10, 1 ); for( i = 10; i < 80; i = i + increment ) { up = MA( C, i ); down = MA( C, i + increment ); if( ParamToggle("3D effect?", "No|Yes" ) ) side = IIf(up<=down AND Ref( up<=down, 1 ), 1, 0.6 ); PlotOHLC( up,up,down,down, "MA"+i, ColorHSB( 3*(i - 10), Param("Saturation", 128, 0, 255 ), side * Param("Brightness", 255, 0, 255 ) ), styleCloud | styleNoLabel ); } |

Filed by brian_z at 5:12 am under Using Custom Colors
No Comments


(3 votes, average: 4 out of 5)

























2 Comments



