Using Graph Styles
Using Graph Styles
Plot() function
Plot is the function used to plot a chart. It takes 9 parameters, out of which first 3 are
required.
An example, the following single function call plots a RSI indicator with red color line:
Plot( RSI(14), "My RSI", colorRed );
As you can see we have provided only first three (required) parameters. First parameter
is the array we need to plot. In our example it is RSI(14) indicator. Second parameter is
just the name. It can be any name you want. It will be displayed in the title line along
with indicator value as shown in the picture below:
Third parameter is the color. To specify plot color you can use one of the following pre-
defined constants:
Color constants
Custom colors refer to color user-defined palette editable using Tools->Preferences-
>Colors, the numerical values that appear after = (equation) mark are for reference
only and you don't need to use them. Use just the name such as colorDarkGreen.
colorCustom1 = 0
colorCustom2 = 1
colorCustom3 = 2
colorCustom4 = 3
colorCustom5 = 4
colorCustom6 = 5
colorCustom7 = 6
colorCustom8 = 7
colorCustom9 = 8
colorCustom10 = 9
colorCustom11 = 10
colorCustom12 = 11
colorCustom13 = 12
colorCustom14 = 13
colorCustom15 = 14
colorCustom16 = 15
colorBlack = 16
colorBrown = 17
colorDarkOliveGreen = 18
colorDarkGreen = 19
colorDarkTeal = 20
colorDarkBlue = 21
colorIndigo = 22
colorDarkGrey = 23
colorDarkRed = 24
colorOrange = 25
colorDarkYellow = 26
colorGreen = 27
colorTeal = 28
colorBlue = 29
colorBlueGrey = 30
colorGrey40 = 31
colorRed = 32
colorLightOrange = 33
colorLime = 34
colorSeaGreen = 35
colorAqua = 35
colorLightBlue = 37
colorViolet = 38
colorGrey50 = 39
colorPink = 40
colorGold = 41
colorYellow = 42
colorBrightGreen = 43
colorTurquoise = 44
colorSkyblue = 45
colorPlum = 46
colorLightGrey = 47
colorRose = 48
colorTan = 49
colorLightYellow = 50
colorPaleGreen = 51
colorPaleTurquoise = 52
colorPaleBlue = 53
colorLavender = 54
colorWhite = 55
You can also use new 24-bit (full color palette) functions ColorRGB and ColorHSB
You can easily plot multi colored charts using both Plot functions. All you need to do is
to define array of color indexes.
In the following example MACD is plotted with green color when it is above zero and
with red color when it is below zero.
In addition to defining the color we can supply 4th parameter that defines style of plot.
For example we can change previous MACD plot to thick histogram instead of line:
As you can see, multiple styles can be combined together using | (binary-or) operator.
(Note: the | character can be typed by pressing backslash key '\' while holding down
SHIFT key). Resulting chart looks like this:
Plot( Close, "Price", colorBlack, styleCandle );
To plot traditional bars with color (green up bars and red down bars) we just specify
color depending on relationship between open and close price and styleBar
in style argument:
Plot( Close, "Price", IIf( Close > Open, colorGreen, colorRed ), styleBar | styleT
hick );
Style constants
Style is defined as a combination (using either addition (+) or binary-or (|) operator) of
one or more following flags ( you can use predefined style__ constants instead of
numbers)
Not all flag combinations make sense, for example (64+1) (candlestick + line) will result
in candlestick chart (style=64)
Note on candlestick/bar charts: if these styles are applied to Plot() function then they
use indirectly O, H, L arrays.
If you want to specify your own OHL values you need to use PlotOHLC() function.
New styleCloud and styleClipMinMax styles bring new interesting possibilities shown in
the sample image below:
The formula for chart in the middle pane (rainbow 24-bit multiple moving averages)
looks as follows:
side = 1;
increment = Param("Increment",2, 1, 10, 1 );
up = MA( C, i );
if( ParamToggle("3D effect?", "No|Yes", 1 ) )
Param("Saturation", 128, 0, 255 ),
side
* Param("Brightness", 255, 0, 255 ) ), styleCloud | styleNoLabel );
The formula for the chart in the lower pane (slow stochastic %K with colored tops and
bottoms) looks as follows. It uses styleClipMinMax to achieve clipping of the cloud
region between min and max levels specified in the plot statement. Without this style
area between min/max would be filled. Please note that due to Windows GDI limitation
clipping region (styleClipMinMax) is supported only on raster (bitmap) devices so it is
not compatible with printers or WMF (windows metafile) output.
SetChartOptions(0,0,ChartGrid30 | ChartGrid70 );
r = StochK(14);
Plot( r, "StochK", colorBlack );
styleClipMinMax, 30, 70 );
X-shift feature
The XShift parameter allows to displace (shift) the plot in horizontal direction by
specified number of bars. This allows to plot displaced moving averages and projections
into the future. See the following sample code of displaced moving average:
Periods = Param("Periods", 30, 2, 100 );
);
PlotForeign() function
It is now easy to overlay price plots of multiple symbols using PlotForeign function:
PlotForeign( tickersymbol, name, color/barcolor, style = styleCandle |
styleOwnScale, minvalue = {empty}, maxvalue = {empty}, xshift = 0)
Two new styles can be used to plot multiple graphs using different Y-scale:
styleOwnScale and styleLeftAxisScale.
It also makes it easy to plot 2 or more "own scale" plots with the same scaling:
/* two plots below use OwnScale but the scale is common because we set min and max
values of Y axis */
minimum, maximum );
maximum );
New style: styleLeftAxisScale = 65536 - allows to plot more than one graph using
common scaling but different from regular (right axis) scale.
Example: price plot plus volume and moving average plot:
// Now plot volume and its moving average using left-hand axis scaling
styleThick );
"Ribbon",
AmiBroker allows to create user-defined parameters. Such parameters are then available
via Parameters dialog for quick and fast adjustment of indicator.
Most often used parameter functions are (click on the links to get more detailed
description):
They make it possible to define your own parameters in your indicators. Once Param
functions are included in the formula you can right click over chart pane and select
"Parameters" or press Ctrl+R, and change them via Parameters dialog and get
immediate response.
Right click over the chart and choose "Parameters" and move the slider and you will see
RSI plotted with different periods immediatelly as you move the slider.
Sample code below shows how to use ParamStr to get the ticker symbol
and ParamColor to get colors.
ticker = ParamStr( "Ticker", "MSFT" );
sp = Param( "MA Period", 12, 2, 100 );
Color", colorRed ) );
The following sample formula (from AmiBroker mailing list) that allows to visually align
price peak/troughs with sine curve on the chart:
xfactor = Param("Stretch",1,0.1,2,0.1);//1==1yr,2==2yr
y = sin(Cum(x)-xshift);
Plot(C,"Daily Chart", colorBlack, styleCandle | styleNoLabel);
Plot(y,
"cycle =" + WriteVal(Cycle*xfactor/22,1.0)+"months",
colorBlue,styleLine|styleNoLabel|styleOwnScale);
Right click over the chart and choose "Parameters" and move the sliders and you will
see chart immediatelly reflecting your changes.
AmiBroker now allows annotation of the chart with text placed on any x, y position
specified on the formula level using new PlotText function.
where
x - is x-coordinate in bars (like in LineArray)
y - is y-coordinate in dollars
color is text color, bkcolor is background color. If bkcolor is NOT specified (or equal to
colorDefault) text is written with TRANSPARENT background, any other value causes
solid background with specified background color
Example:
Plot(C,"Price", colorBlack, styleLine );
Plot(MA(C,20),"MA20", colorRed );
Buy=Cross( C, MA(C,20 ) );
Sell= Cross( MA( C, 20 ), C );
dist = 1.5*ATR(10);
+dist[i], colorRed, colorYellow );
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGreen, colo
rRed ) );
AmiBroker 4.90 allows to fill indicator background with gradually changing color. To
achieve this you need to use new function SetChartBkGradientFill( topcolor,
bottomcolor, titlebkcolor = default )
Example:
SetChartBkGradientFill( ParamColor("BgTop", colorWhite),ParamColor("BgBottom", col
orLightYellow));
Plot( C, "C", colorDefault, styleGradient | styleLine );
For detailed control over gradient colors and baseline there is an extra
function SetGradientFill( topcolor, bottomcolor, baseline, baselinecolor ) that should be
called before Plot().
For example to display three-color gradient Rate Of Change that will use green as "top"
color for positive values, background color as "baseline" color and red as "bottom" color
for negative values it is enough to write:
SetGradientFill( colorGreen /*top*/, colorRed /*bottom*/, 0 /*baseline
Plot( ROC( C, 14), "ROC", colorLightOrange, styleLine | styleGradient, Null, Null,
0, -1 );
Version 5.60 allows to define the line width beyond styleThick that was the only option
before.
Now 9th parameter of Plot() defines pixel or percent width of given plot. The default is 1
pixel. Positive values specify pixel width, negative values specify width in percent of
current bar width. So for example -20 will give you dynamic width that is 20% of bar
width. Example:
Miscellaneous
As you already know each plot has its own name that is used to create a title string
which displays names and values of indicators. AmiBroker however allows you to
override this automatic mechanism and define your own title string from the scratch.
The Title reserved variable is used for that. You just assign a string to it and it will be
displayed in the chart instead of automatically generated one.
Also there two more reserved variables (GraphXSpace and GraphZOrder) that allow to
fine-tune indicator look.
EncodeColor( colornumber ).
And you can write the above example like this:
For example:
Plot( my_value, "MyValueForTooltip", colorBlack,
styleHidden );
GraphXSpace defines how much extra space should be added Indicators
above and below graph line (in percent).
For example:
GraphXSpace = 5;
graphNbarcolor defines the array that holds palette indexes for each bar Indicators
drawn
graphNstyle defines the style of Nth graph. Style is defined as a Indicators
combination (sum) of one or more following flags ( you can
use predefined style__ constants instead of numbers)