Instructions/probacktest · proorder

DEFPARAM

DEFPARAM sets execution parameters for a ProRealTime strategy, such as CumulateOrders, FlatBefore, and FlatAfter, and must appear at the top of the code.

Syntax

probuilder
DEFPARAM ParameterName = Value

Parameters

NameTypeDefaultDescription
CumulateOrdersbooleantrueWhen true, new signals add to the open position. When false, only one position is open at a time and a new signal replaces the current one.
FlatBeforetime (HHMMSS)noneTime before which the strategy stays flat: positions are closed and no new orders are placed until this time.
FlatAftertime (HHMMSS)noneTime after which the strategy goes flat: open positions are closed and no new positions are opened for the rest of the session.
PreLoadBarsinteger200Number of historical bars loaded before the start so indicators have data from the first evaluated bar.
NoCashUpdatebooleanfalseWhen true, realized gains and losses do not change the capital used for position sizing, which stays at its initial value.

How it works

DEFPARAM lines are directives, not per-bar instructions. They are read when the strategy starts and fix its execution environment for the whole run. Place them at the top of the code, before any variable assignments or trading logic, one parameter per line.

CumulateOrders governs what a repeated entry signal means. With the default value of true, each signal stacks another order onto the position. Setting it to false enforces a single open position, which is the behavior most single-entry strategies expect.

FlatBefore and FlatAfter restrict the strategy to a trading window inside the session. Both take a time in HHMMSS format, interpreted in the local time zone of the instrument's exchange. PreLoadBars and NoCashUpdate tune the simulation itself: how much history the indicators can see at the start, and whether position sizing compounds with results.

Examples

Example 1, Session window with single positions (ProOrder)

probuilder
DEFPARAM CumulateOrders = false  // one position at a time
DEFPARAM FlatBefore = 090000     // stay flat before 9:00 AM
DEFPARAM FlatAfter = 173000      // go flat after 5:30 PM

This header keeps the strategy flat outside 9:00 to 17:30 exchange time and replaces, rather than accumulates, positions on each new signal.

Example 2, Preloaded history for slow indicators (ProBacktest)

probuilder
DEFPARAM PreLoadBars = 300   // enough history for the 200-bar average
DEFPARAM NoCashUpdate = true // size positions on initial capital only
ma = Average[200](close)
IF close CROSSES OVER ma AND NOT onmarket THEN
  BUY 1 CONTRACT AT MARKET
ENDIF
IF close CROSSES UNDER ma THEN
  SELL AT MARKET
ENDIF

Preloading 300 bars means the 200-period average is valid from the first tested bar, and NoCashUpdate keeps the backtest sizing constant regardless of accumulated profit or loss.

Example 3, Pyramiding with cumulated orders (ProOrder)

probuilder
DEFPARAM CumulateOrders = true  // allow entries to stack
IF close CROSSES OVER Average[20](close) AND countofposition < 3 THEN
  // add one contract per signal, up to three
  BUY 1 CONTRACT AT MARKET
ENDIF
IF close CROSSES UNDER Average[50](close) THEN
  SELL AT MARKET
ENDIF

With CumulateOrders enabled, each fresh crossover adds a contract until the position cap is reached, and the exit closes the whole stack at once.

Common errors and gotchas

  • DEFPARAM below other code. The directive must precede the strategy logic. A DEFPARAM placed after executable statements is rejected at compile time.
  • Forgetting that CumulateOrders defaults to true. A strategy that signals on every bar of a trend will keep adding positions unless CumulateOrders is explicitly set to false. Unexpectedly large positions in a backtest usually trace back to this default.
  • Wrong time format. FlatBefore and FlatAfter expect HHMMSS as a plain number, so 9:00 AM is 090000 and 5:30 PM is 173000. Values are read in the exchange's local time zone, not the machine's, which matters when trading foreign markets.
  • Too few preloaded bars. If PreLoadBars is smaller than the longest indicator lookback, early bars compute indicators on partial data and can produce signals that differ from the chart. Set it above the largest period used in the code.
  • CumulateOrders, the order accumulation parameter in detail.
  • FLATBEFORE, the session start constraint in detail.
  • FLATAFTER, the session end constraint in detail.
  • PRELOADBARS, the history preload parameter in detail.
  • NOCASHUPDATE, the cash handling parameter in detail.
  • ONCE, one-time variable initialization inside the script body.