|
This script section defines each graph to include in the list of available daily stats graphs for any test that has been run.
If the active script does not include a Graphs section then the default graphs script graphs.rts is used.
Each graph type defined in this section becomes a button on the tab bar at the top of every Graph Window.
.png)
To access the underlying formulas for any Results, Graphs, Trades or Chart window, press the F9 key or use the context menu.
Each item defined in the Graphs section defines a graph to include. The item name becomes the name of the graph, and the item formula is evaluated for every date in the test results record and then plotted as either a continuous line or a histogram.
Every graph is drawn once for each strategy in the test and once for the test as a whole, which is why one formula produces the whole legend of lines shown above. The color of each line comes from the strategy palette in the graph options dialog, unless the Strategy (or Template, Benchmark, StatsGroup or Combined) section header carries a {color: ...} comment of its own.
The formulas refer to the Test Statistics Arrays, which can be indexed backward from the date being plotted — S.Equity[S.BPM] is equity as of one month ago, which is how the Monthly graph in the default script computes a rolling monthly return. Any item can also refer to any item defined earlier in the same section, by name, and those references can be indexed the same way.
If a graph 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.
Format Specifications
A format specification comment can be included in any item and has two purposes: it selects how the series is drawn, and it sets the number format used for the Y axis and for the value readout when the cursor is on a date. If no format is specified, the item is graphed as a line using default number formatting.
The named-attribute form is the recommended way to write these. 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 Graphs items:
•line: Line | Bars — a continuous line (the default) or a histogram. (Graphs accept Dashed and Dotted but treat them as Line.)
•base: n — with line: Bars, the value the bars are drawn from (0 unless you say otherwise)
•format: and places: — the number format for the axis and the cursor readout
•name: "label" — a tab and legend label that differs from the item name
•hat: 1 — include this graph in Test Summary Reports
The older short-glyph codes still work and can be mixed freely with named-attribute items in the same section. The default graphs.rts shown above is written entirely in that form: the vertical bar {|} is the same as {line: Bars} (and {|3} is that with base: 3), the accent {^} is the same as {hat: 1}, and {%2} is the same as {format: percent, places: 2}. So {%2|^} on the Drawdown graph could equally be written {format: percent, places: 2, line: Bars, hat: 1}.
Note that color:, pane: and width: have no effect here — they belong to Charts items. A graph’s colors are per strategy, not per graph.
Why the choice of line type matters
Two graph window features are available only for items drawn as bars:
•The Sort command re-plots the bars in descending order instead of by date, turning the graph into a distribution of the stat over the whole test. It is disabled for line graphs, whose x axis has to remain the date axis.
•Bar fills honor transparency, so overlapping strategies remain readable. Give a strategy a color with an alpha component (#RRGGBBAA or ARGB(a,r,g,b)), or set Bar Graph Opacity in the graph options dialog to make every bar graph translucent at once. Lines always draw opaque.
That is why the default script draws equity curves as lines and per-period returns, drawdowns and counts as bars.
Test Summary Reports
The special format code {^} (or {hat: 1}) is used to specify which graphs are included in Test Summary Reports.
A graph marked {^2} or {^3} is stacked beneath the preceding {^} graph in the report instead of getting its own image: the group becomes one combined image with a shared date axis, split 60/40 for two graphs or 50/30/20 for three, and named for the first graph in the group. A slot number less than or equal to its predecessor's starts a new image, so scripts that use plain {^} on every graph render exactly as before.
To apply Graphs section contents to all currently open Graph windows, press F4 or click Apply.
See also Default Scripts and Output Format Specification.
|