ProBacktest/probacktest · proorder

FLATBEFORE

FLATBEFORE is a DEFPARAM parameter that blocks trading and keeps a ProBacktest or ProOrder strategy flat before a set time of day. Syntax and examples.

Syntax

probuilder
DEFPARAM FLATBEFORE = HHMMSS

Parameters

NameTypeDefaultDescription
FLATBEFOREtime literal (HHMMSS)noneTime of day before which positions are closed, pending orders cancelled and new orders blocked. 24-hour clock, e.g. 073000 for 7:30 AM.

How it works

FLATBEFORE is declared once with DEFPARAM at the top of the strategy, ahead of all trading logic, and is read when the strategy starts. Before the specified time each day, the platform enforces a flat state: it closes any position that would otherwise be open, cancels pending orders and rejects new ones. The strategy code continues to execute during that period, its calculations run and its variables update, only order placement is suppressed. From the specified time onward, trading proceeds normally.

The value uses the HHMMSS format on a 24-hour clock, so 073000 is 07:30:00. The parameter does not pause or delay the strategy, it acts purely as a trading gate.

The usual reason to gate the open of a session is to skip the erratic price action and thin books around market open or overnight hours. Combined with FLATAFTER, which enforces flatness after a time, the two parameters define a daily trading window without any hand-written time conditions.

Examples

Example 1, No trading before 7:30 AM (ProOrder)

probuilder
// Stay flat until 07:30, then trade normally
DEFPARAM FLATBEFORE = 073000

The declaration preserved from the official reference. Until 7:30 AM each day the strategy holds nothing and places nothing.

Example 2, Skipping the volatile cash open (ProBacktest)

probuilder
// Ignore the first 30 minutes after the 09:00 open
DEFPARAM FLATBEFORE = 093000
DEFPARAM FLATAFTER = 172500

// Mean-reversion entry on Bollinger band touch
lowerBand = BollingerDown[20](close)

IF close crosses under lowerBand THEN
  BUY 1 CONTRACT AT MARKET
ENDIF

SET TARGET %PROFIT 1
SET STOP %LOSS 0.5

Backtesting with the window in place shows how the system behaves when the first half hour, where band touches are most frequent and least reliable, is excluded.

Example 3, Restricting a forex system to the London session (ProOrder)

probuilder
// Trade only after the London open, flat again in the evening
DEFPARAM FLATBEFORE = 090000
DEFPARAM FLATAFTER = 200000
DEFPARAM CumulateOrders = false

fastMA = ExponentialAverage[9](close)
slowMA = ExponentialAverage[21](close)

IF fastMA crosses over slowMA THEN
  BUY 1 LOT AT MARKET
ENDIF

IF LongOnMarket AND fastMA crosses under slowMA THEN
  SELL AT MARKET
ENDIF

The two flat parameters restrict all activity, entries, exits and pending orders alike, to the chosen session hours.

Common errors and gotchas

  • Declared after trading logic. DEFPARAM declarations must be the first instructions in the program. A FLATBEFORE line placed after any order or condition fails to compile.
  • HHMM instead of HHMMSS. DEFPARAM FLATBEFORE = 0930 means 00:09:30, not 09:30:00. The seconds digits are mandatory, so a 9:30 AM gate is written 093000.
  • Expecting the strategy to pause. The parameter does not stop code execution. Indicators, counters and state variables keep updating before the cutoff, only order placement is blocked. Logic that assumes nothing ran before the gate opens can be wrong.
  • Coarse timeframes. The gate resolves at bar granularity, so on charts of one hour or more the effective release time can differ from the literal value, and on daily or higher timeframes the parameter serves no purpose.
  • FLATAFTER, DEFPARAM parameter that forces the strategy flat after a set time.
  • DEFPARAM, declares strategy parameters at the top of the code.
  • CumulateOrders, DEFPARAM parameter controlling same-direction order stacking.
  • QUIT, stops the strategy entirely after closing positions.
  • TIME, current bar time for hand-written time conditions.
  • CurrentTime, wall-clock time value usable in conditions.
  • ONMARKET, true while any position is open.
  • BUY, opens or adds to a long position.