ProBacktest/probacktest

GRAPH

GRAPH plots the values of strategy variables in a separate window under the ProBacktest results chart. Syntax, RGB colour option, examples, limits.

Syntax

probuilder
GRAPH variableName AS "label"
probuilder
GRAPH variableName coloured(r, g, b) AS "label"

Parameters

NameTypeDefaultDescription
variableNamenumeric variablenoneThe variable whose value is recorded and plotted on every bar of the backtest.
r, g, bintegers 0 to 255platform defaultOptional RGB components of the line colour.
"label"stringnoneLegend text identifying the series in the GRAPH window.

How it works

GRAPH is the main debugging tool of ProBacktest. During a backtest run, the platform records the value of the graphed variable on every bar and, once the run finishes, draws the full series in a separate window below the price chart. This makes internal strategy state visible: entry filters, computed stop distances, counters, regime flags, anything stored in a variable can be inspected bar by bar next to the trades it produced.

The instruction can appear any number of times in the same system. All series are drawn in the same GRAPH window and distinguished by colour and label, so the coloured(r, g, b) clause and a descriptive label matter as soon as more than one variable is plotted. The window has a single value scale shared by every series it contains.

GRAPH exists only in the backtest environment. Indicators display values with RETURN, and live ProOrder systems have no results window to draw into, which is why the platform blocks live launch until GRAPH lines are removed. For values plotted on the price chart itself rather than in a separate window, GRAPHONPRICE is the companion instruction.

Examples

Example 1, Plotting a MACD signal flag (ProBacktest)

probuilder
myMACD = MACD[12,26,9](close)
longCondition = myMACD crosses over 0
IF myMACD > 0 THEN
    signals = 1
ELSE
    signals = -1
ENDIF
IF longCondition THEN
    BUY 1 LOT AT close + 10 LIMIT
ENDIF
SET STOP %TRAILING 0.5
// plot the regime flag in red under the backtest chart
GRAPH signals coloured(255,0,0) AS "MACD signals"

The variable signals switches between 1 and -1 with the sign of the MACD. Graphing it shows exactly when the strategy considered the regime bullish, next to the trades taken. This is the example from the official reference.

Example 2, Watching position state and equity together (ProBacktest)

probuilder
// entry logic
IF NOT onmarket AND close CROSSES OVER Average[50](close) THEN
  BUY 1 CONTRACT AT MARKET
  SET STOP PLOSS 30
ENDIF

// two series in the same GRAPH window
GRAPH countofposition coloured(0,0,255) AS "position size"
GRAPH strategyprofit coloured(0,150,0) AS "equity"

Plotting countofposition and strategyprofit side by side shows when the system was in the market and how the equity curve behaved during those periods.

Example 3, Debugging a volatility-scaled stop distance (ProBacktest)

probuilder
atr      = AverageTrueRange[14](close)
stopDist = 2 * atr

IF NOT onmarket AND close CROSSES OVER highest[20](high[1]) THEN
  BUY 1 CONTRACT AT MARKET
  SET STOP LOSS stopDist
ENDIF

// verify the stop distance actually used on each bar
GRAPH stopDist AS "stop distance"

Graphing the computed stop distance confirms that the ATR scaling produces sensible values across quiet and volatile periods before the number is trusted in live trading.

Common errors and gotchas

  • Blocks live launch. ProOrder rejects code containing GRAPH. The usual workflow is to debug with GRAPH in ProBacktest, then delete or comment out the lines before starting the live system.
  • One shared scale. All graphed series are drawn in the same window with a common value axis. A flag oscillating between -1 and 1 plotted next to an equity curve in the thousands becomes an invisible flat line. Group variables of similar magnitude, or normalize before graphing.
  • Backtest slowdown. Every GRAPH call stores a value per bar. On long histories with many graphed variables, run times grow noticeably. Keep only the series currently under investigation.
  • Not a substitute for RETURN. Indicators cannot use GRAPH. Code shared between an indicator and a strategy through CALL must keep display logic out of the called code.
  • GRAPHONPRICE, plots a variable directly on the price chart instead of a separate window.
  • PRINT, writes values as text output for debugging.
  • COLOURED, the colour clause used by drawing and graphing instructions.
  • DRAWTEXT, displays text on an indicator chart.
  • MACD, the indicator used in the reference example.
  • BUY, opens a long position.
  • STRATEGYPROFIT, the running profit of the strategy, a common variable to graph.
  • COUNTOFPOSITION, the current position size, useful for state debugging.