FLATAFTER
FLATAFTER is a DEFPARAM parameter that closes all positions and cancels pending orders after a set time each day in ProBacktest and ProOrder strategies.
Syntax
DEFPARAM FLATAFTER = HHMMSSParameters
| Name | Type | Default | Description |
|---|---|---|---|
FLATAFTER | time literal (HHMMSS) | none | Time of day after which all positions are closed, pending orders cancelled and new orders blocked. 24-hour clock, e.g. 153000 for 3:30 PM. |
How it works
FLATAFTER is declared once with DEFPARAM at the top of the strategy, before any trading logic. From the specified time onward, the platform closes whatever position is open, cancels every pending order, and refuses new orders for the rest of the trading day. The strategy code itself keeps running, it simply cannot hold or place trades past the cutoff, and normal operation resumes at the next session.
The time literal uses the HHMMSS format on a 24-hour clock, so 153000 means 15:30:00. Leading zeros can be written for readability (073000), the value is numeric either way.
The parameter is the standard way to build day-trading strategies that must never carry positions overnight. It pairs naturally with FLATBEFORE, which blocks trading before a chosen time, so the two together confine all activity to a fixed intraday window. Compared with hand-rolled exit logic based on TIME, the DEFPARAM approach also cancels pending orders, a step that manual flattening code often forgets.
Examples
Example 1, Flat after 3:30 PM (ProOrder)
// Close positions, cancel pending orders and stop trading after 15:30
DEFPARAM FLATAFTER = 153000The declaration preserved from the official reference. After 3:30 PM no position or pending order survives, which guarantees the strategy ends every day flat.
Example 2, Confining a breakout system to a session window (ProBacktest)
// Trade only between 08:00 and 17:00
DEFPARAM FLATBEFORE = 080000
DEFPARAM FLATAFTER = 170000
// Buy a breakout of the highest high of the last 20 bars
IF close crosses over highest[20](high)[1] THEN
BUY 1 CONTRACT AT MARKET
ENDIF
SET STOP %TRAILING 0.8FLATBEFORE and FLATAFTER bracket the session. The backtest then reflects a strategy that is always flat outside the 08:00 to 17:00 window, including its trailing stop orders.
Example 3, Avoiding an illiquid close on index futures (ProOrder)
// Force flat 15 minutes before the cash close
DEFPARAM FLATAFTER = 214500
DEFPARAM CumulateOrders = false
rsiVal = RSI[14](close)
IF rsiVal crosses under 30 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF LongOnMarket AND rsiVal crosses over 60 THEN
SELL AT MARKET
ENDIFWhatever the RSI logic is doing, FLATAFTER guarantees the position is liquidated ahead of the thin end-of-day tape.
Common errors and gotchas
- Declared after trading logic. All
DEFPARAMlines must precede every other instruction. PlacingFLATAFTERbelow anIFblock or an order instruction causes a compile error. - Wrong time format. The value is HHMMSS, not HHMM. Writing
1530is read as 00:15:30, not 15:30:00, which flattens the strategy just after midnight instead of mid-afternoon. - Timeframe mismatch. The cutoff resolves at bar granularity. On a 1-hour chart a
FLATAFTER = 153000cutoff cannot act at exactly 15:30, so intraday cutoffs belong on timeframes fine enough to represent the time. The parameter is meaningless on daily or higher timeframes. - Clock and time zone assumptions. The time is interpreted against the clock the platform applies to the chart's bars. When the instrument's exchange sits in another time zone, verify the effective cutoff on the chart rather than assuming a local wall-clock match.
Related instructions
FLATBEFORE, DEFPARAM parameter that keeps the strategy flat before 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.SELL, closes all or part of a long position.
