GRAPHONPRICE
GRAPHONPRICE plots strategy variables directly on the price chart in ProBacktest. Syntax, COLOURED colour and alpha options, examples, and limits.
Syntax
GRAPHONPRICE variableName COLOURED(r, g, b, alpha) AS "label"Parameters
| Name | Type | Default | Description |
|---|---|---|---|
variableName | numeric variable | none | The variable whose value is plotted on the price chart on every bar. |
r, g, b | integers 0 to 255 | platform default | Optional RGB components of the line colour. |
alpha | integer 0 to 255 | opaque | Optional transparency of the line. The clause also works with three arguments, colour only. |
"label" | string | none | Legend text identifying the series on the chart. |
How it works
GRAPHONPRICE is the price-pane counterpart of GRAPH. Where GRAPH opens a separate window with its own scale, GRAPHONPRICE draws the series over the candles, using the instrument price axis. That makes it the right tool for any value expressed in price units: moving averages, band boundaries, computed stop and target levels, breakout thresholds. Seeing those levels against the bars shows immediately whether the strategy logic places them where intended.
The instruction records the variable on every bar of the backtest and draws the complete line when the run finishes. It can appear multiple times in the same system, one line per statement, distinguished by colour and label.
Because the plotted values share the price axis, only variables in the neighbourhood of the traded price display usefully. Values on another scale, an RSI between 0 and 100, a position counter, a profit figure, compress the chart or vanish against it. Those belong in GRAPH instead.
Examples
Example 1, Daily bands on the backtest chart (ProBacktest)
timeframe(daily)
ema20daily = average[20,1]
bolupdaily = BollingerUp[20](close)
boldndaily = BollingerDown[20](close)
timeframe(default)
// draw the daily levels over the candles of the default timeframe
GRAPHONPRICE ema20daily COLOURED(200,200,0) AS "EMA 20 Daily"
GRAPHONPRICE bolupdaily COLOURED(0,200,0) AS "Bollinger Upper Band Daily"
GRAPHONPRICE boldndaily COLOURED(0,0,200) AS "Bollinger Lower Band Daily"Daily EMA and Bollinger values computed in a TIMEFRAME block are drawn on the default timeframe chart, where they update in steps at each new daily bar. This is the example from the official reference.
Example 2, Verifying the active stop level (ProBacktest)
IF NOT onmarket AND close CROSSES OVER Average[50](close) THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF longonmarket THEN
stoplevel = tradeprice - 50 * pointsize
SET STOP PLOSS 50
// draw the stop level in semi-transparent red while the trade is open
GRAPHONPRICE stoplevel COLOURED(255,0,0,150) AS "stop level"
ENDIFThe computed stop level is drawn under the candles for the life of each long trade, making it possible to check visually that stops sit where the arithmetic says they should.
Example 3, Breakout threshold against the candles (ProBacktest)
// entry level: highest high of the previous 20 bars
entryLevel = highest[20](high[1])
IF NOT onmarket AND close CROSSES OVER entryLevel THEN
BUY 1 CONTRACT AT MARKET
SET STOP %LOSS 1
ENDIF
GRAPHONPRICE entryLevel COLOURED(0,150,255) AS "breakout level"Plotting the breakout threshold shows how price interacted with the level before each entry, which helps judge whether the lookback of 20 bars fits the instrument.
Common errors and gotchas
- Blocks live launch. ProOrder rejects code containing GRAPHONPRICE. Debug in ProBacktest, then delete or comment out the lines before starting the live system.
- Price scale only. A variable far from the traded price distorts the chart or draws as a flat line at the edge. Oscillators, counters, and profit figures belong in
GRAPH, not on the price pane. - Stale values draw too. A variable that is only assigned inside a condition keeps its last value on other bars, and GRAPHONPRICE plots that stale value as a continuing line. Reset the variable, or accept the horizontal segments as part of the display.
- Backtest slowdown. Each statement stores one value per bar. On long histories, several GRAPHONPRICE lines add measurable run time.
Related instructions
GRAPH, plots a variable in a separate window under the chart.PRINT, writes debugging values as text.COLOURED, the colour and transparency clause.TIMEFRAME (PB/PO), computes values on another timeframe, as in the reference example.BollingerUp, upper Bollinger band, a typical price-scaled series to plot.BollingerDown, lower Bollinger band.Average, moving average function used for the EMA in the example.TRADEPRICE, the entry price of the current position, often plotted with stop levels.
