RealTest User Guide
RealTest User Guide

 

 

Navigation: RealTest Script Language > Script Sections >

Charts Section

 

 

 

 

This script section defines the lines to be plotted on bar or candlestick charts whenever they are viewed. If the active script does not include a Charts section then the default charts script charts.rts is applied.

Each item defined in the Charts section defines one data series. The item name becomes the name of the line in the chart’s legend row, and the item formula is evaluated for every bar of the chart — at whatever bar size the chart is currently displaying — and then plotted.

If a Charts item name begins with an underscore, that item will not be plotted. Rather, it will just serve as an intermediate variable that other items can refer to. This can be useful to avoid repeating the same expression several times or to calculate an indicator that requires several steps.

Any item can refer to any item defined earlier in the same section, by name, and the reference can be indexed like any other bar array — _ma[1] is the previous bar’s value of _ma.

Chart formulas can use price bar elements and Data section elements, and — once a test has been run — test statistics, trade and current-position elements as well (see Trade Charts below).

The items defined above are plotted below.

To access the underlying formulas for any Charts, Results, Graphs or Trades window, press the F9 key or use the context menu. To apply the edited section to all currently open Chart windows, press F4 or click Apply in the Tool Bar.

Format Specifications

A format specification comment controls where and how each line is drawn. The named-attribute form is the recommended way to write these — it is self-describing, and the script editor pops up a list of the attributes that apply while the cursor is inside the { } block. These are the attributes that apply to Charts items:

pane: price | ind1 | ind2 | ind3 | volume — which pane to draw the line in (default price)

color: — a named color, #RRGGBB, RGB(r,g,b), or one of the transparency forms #RRGGBBAA / ARGB(a,r,g,b)

line: Line | Bars | Dashed | Dotted — how the series is rendered

width: n — pen width in pixels (1 to 20) for this line only, overriding the Line Width chart option; with line: Bars it sets each bar’s half-width

base: n — with line: Bars, the value the bars are drawn from (default 0)

format: and places: — how the value is written in the legend

name: "label" — a legend label that differs from the item name

The older short-glyph codes still work and can be mixed freely with named-attribute items in the same section. The accent {^} is the same as {pane: ind1} ({^2} and {^3} select the higher panes), and the vertical bar {|} is the same as {pane: volume}. Note that {|} always draws a line; only line: Bars draws actual bars.

If no format is specified at all, the item is plotted along with the price bars and uses their scale. If a number format is specified, it is used whenever the value of the item is displayed for a specific bar.

Panes

There are five possible destinations. price is the main pane with the price bars. ind1, ind2 and ind3 are indicator panes stacked above the price pane, with ind1 closest to the price and ind3 highest. volume is the pane below the price bars.

An indicator pane appears only if at least one item is assigned to it and the indicator pane display is turned on — press i or use the chart options dialog. The lower pane is likewise toggled with v. If no items are routed to the volume pane, it shows volume bars; assigning any item to it replaces them. (It is not currently possible to plot both indicators and volume bars in the lower pane.)

An item left in the price pane shares the price scale, so an indicator whose values are nowhere near the price will flatten the bars into a straight line. Put those in an indicator pane.

Turning a line off where you don’t want it

A bar whose formula evaluates to NaN is simply not drawn, and the line picks up again at the next bar that does have a value. Returning NaN deliberately is therefore the way to restrict a line to the part of the chart where it means something:

Charts:
   _atr:         ATR(14)
   HiVolBand:    {color: red}   IF(_atr > MA(_atr, 50), C + 2 * _atr, NaN)

The same thing happens by itself whenever a formula cannot be evaluated on a given chart — which is why it is safe to leave trade-only items in a Charts script that is also applied to ordinary symbol charts.

A line that changes color

Each item gets one color, but two items can share one path. Define the series twice with complementary conditions, giving each the color for its own case:

Charts:
   _ma:     MA(C, 50)
   MaUp:    {color: green}   IF(_ma >= _ma[1] or _ma[1] >= _ma[2], _ma, NaN)
   MaDn:    {color: red}     IF(_ma < _ma[1], _ma, NaN)

The two items draw as one continuous moving average that is green while it is rising and red while it is falling. The extra or _ma[1] >= _ma[2] term lets the green segment run one bar past each turn, so the hand-off between the colors has no gap in it. Both items appear in the legend, so give them short names.

Trade Charts

When a chart is opened from a row of a Trade List, it carries the context of that trade. All of the T. elements resolve to that trade, and the current position elements BarsHeld, FillPrice, FillValue and Shares resolve as they did during the test. That makes it possible to draw the exact stop line the strategy was using:

Charts:
   Trail:   {color: red, line: dashed}   Highest(H - 2 * ATR(14), BarsHeld)

Because BarsHeld counts from the entry bar of the trade being charted, Highest(..., BarsHeld) reproduces a trailing stop that starts fresh at entry rather than one that looks back a fixed number of bars. This example (for the long side) ships commented out in the default charts.rts.

To keep the line off the part of the chart before the trade began, gate it with BarDate:

   Trail:   {color: red, line: dashed}   IF(BarDate >= T.DateIn, Highest(H - 2 * ATR(14), BarsHeld), NaN)

Other useful trade-chart items are the entry price as a horizontal reference (IF(BarDate >= T.DateIn and BarDate <= T.DateOut, T.PriceIn, NaN)) and a profit target drawn the same way.

Histogram bars and transparency

line: Bars draws the item as vertical bars rising from base: (0 unless you say otherwise), which is how the MACD histogram in the default script is drawn. A color given with an alpha component makes the fills partly transparent so that overlapping bars and the chart grid show through:

   MacdHist:   {pane: ind1, line: Bars, color: blue}   MACDH(12,26,9)
   AtrBars:    {pane: ind2, line: Bars, color: ARGB(110, 30, 90, 160)}   ATR(14)

The Text item

If a special Charts item called Text is defined, it is not plotted. It is interpreted as a string formula and its output is appended to the chart’s legend row — the line above the price pane that shows the symbol, bar size, date and OHLC values for the bar under the crosshair.

This example adds the current bar’s "volume surge" to that line:

Charts:
   Text:    Format("VS = {%}", V / MA(V,20) - 1)

The legend then reads, for example, AAPL - Daily 8/4/23: O = 185.52, H = 187.38, L = 181.92, C = 181.99 (-4.80%), V = 115,956,840, VS = 112.79%.

See also Default Scripts and Output Format Specification.

 

 

 

Copyright © 2020-2026 Systematic Solutions, LLC