ProBacktest/probacktest · proorder

STRATEGYPROFIT

STRATEGYPROFIT returns the cumulative profit or loss, in money, of every closed trade in a ProBacktest or ProOrder strategy. Open positions are excluded.

Syntax

probuilder
myCurrentProfit = STRATEGYPROFIT

How it works

Every time the strategy closes a trade, the realized result of that trade is added to a running total. STRATEGYPROFIT exposes that total on every bar, expressed in money rather than in points or percent. A value of 0 on the first bars simply means no trade has been closed yet.

Only closed trades contribute. A position that is still open, however far in profit, does not change the value until it is exited. To read the unrealized performance of the current position, use POSITIONPERF instead. The two are complementary: STRATEGYPROFIT describes the past, POSITIONPERF describes the present.

The variable is commonly used for equity-dependent logic, for example halting the system after a drawdown threshold, reducing size after a losing streak, or locking in a session once a profit goal is reached. When positions are accumulated across bars, set DEFPARAM CumulateOrders = true so the engine keeps the combined position open and realizes profit the way the logic expects.

Examples

Example 1, Scaling out once a profit threshold is reached (ProBacktest)

probuilder
DEFPARAM CumulateOrders = true  // allow accumulated positions

myCurrentProfit = STRATEGYPROFIT
IF myCurrentProfit > 1000 THEN
  SELL 100 SHARES AT MARKET
ENDIF

Once the realized profit of all closed trades exceeds 1000 currency units, the strategy sells 100 shares at market. This is the canonical usage pattern from the official reference.

Example 2, Equity stop that halts the strategy (ProOrder)

probuilder
// Stop the system permanently after 500 units of realized loss
IF STRATEGYPROFIT < -500 THEN
  SELL AT MARKET
  EXITSHORT AT MARKET
  QUIT
ENDIF

A capital-preservation guard. When the realized loss passes the limit, any open position is closed and QUIT stops the strategy from placing further orders.

Example 3, Plotting the realized equity curve (ProBacktest)

probuilder
// Inspect the realized equity curve while backtesting
GRAPH STRATEGYPROFIT AS "Realized PnL"

IF NOT onmarket AND close > average[50](close) THEN
  BUY 1 CONTRACT AT MARKET
  SET STOP LOSS 30
  SET TARGET PROFIT 60
ENDIF

GRAPH draws the running realized profit below the backtest chart, which makes it straightforward to see when the strategy earned or gave back money.

Common errors and gotchas

  • Open positions are invisible. STRATEGYPROFIT only moves when a trade closes. A strategy that checks it while a large position is open sees stale information. Combine with POSITIONPERF when the current trade matters.
  • Money, not points. The value is denominated in the account currency, so thresholds like > 1000 mean 1000 currency units, not 1000 points. The same threshold behaves very differently across instruments with different point values.
  • Backtest and live values differ. In a live ProOrder run the total restarts from zero when the strategy is launched, it does not inherit the backtest history. Equity-based rules therefore behave differently right after deployment.
  • GRAPH is backtest only. GRAPH STRATEGYPROFIT works in ProBacktest but is ignored in live ProOrder execution, so diagnostic plots disappear once the system trades live.
  • POSITIONPERF, unrealized performance of the position currently open.
  • PROFIT, percent take-profit configuration for a position.
  • LOSS, percent stop-loss configuration for a position.
  • CumulateOrders, DEFPARAM controlling whether orders accumulate into one position.
  • GRAPH, plots a value under the backtest chart for inspection.
  • ONMARKET, true while any position is open.
  • TRADEPRICE, entry price of the current position.
  • COUNTOFPOSITION, size of the position currently open.