Built-in Variables

Whale‑E exposes read-only built-in variables for performance metrics, position information, and candle data.

Performance Metrics

VariableDescription
initial_capitalThe starting capital of the backtest.
Constant for the whole backtest (set at initialization).
equityThe current equity of the portfolio, calculated as initial_capital + netprofit + openprofit.
Recomputed when the engine revalues open positions at market price, on every closed candle, and after each order execution or liquidation.
netprofitThe realized net profit of the strategy.
Updated whenever a position is closed or liquidated. Its final value is the sum of realized gains and losses.
grossprofitThe sum of realized gains from winning closed positions.
Updated whenever a position close or liquidation realizes a gain.
grosslossThe sum of realized losses from losing closed positions, expressed as a positive value.
Updated whenever a position close or liquidation realizes a loss.
openprofitThe unrealized profit or loss on open positions.
Recomputed when the engine revalues open positions at market price, on every closed candle, and after each order execution or liquidation.
openprofit_percentThe unrealized profit or loss on open positions, as a percentage of realized equity.
Recomputed when the engine revalues open positions at market price, on every closed candle, and after each order execution or liquidation.
grossprofit_percentThe sum of realized gains from winning closed positions, expressed as a percentage of initial capital.
Updated whenever a position close or liquidation realizes a gain.
grossloss_percentThe sum of realized losses from losing closed positions, expressed as a percentage of initial capital.
Updated whenever a position close or liquidation realizes a loss.
avg_winning_tradeThe average profit of winning trades.
Updated on each winning close or liquidation.
avg_losing_tradeThe average loss of losing trades.
Updated on each losing close or liquidation.
avg_winning_trade_percentThe average profit of winning trades, expressed as a percentage of the closed position’s entry value, including fees.
Recomputed on each recorded close (including partial closes and liquidations).
avg_losing_trade_percentThe average loss of losing trades, expressed as a percentage of the closed position’s entry value, including fees.
Recomputed on each recorded close (including partial closes and liquidations).
avg_tradeThe average profit or loss of all trades.
Recomputed on each recorded close (including partial closes and liquidations).
avg_trade_percentThe average profit or loss of all trades, expressed as a percentage of the closed position’s entry value, including fees.
Recomputed on each recorded close (including partial closes and liquidations).
closedtradesThe total number of closed trades.
Incremented on each recorded close (including partial closes and liquidations).
opentradesThe current number of open trades.
Updated on each entry, close, or liquidation.
max_drawdownThe maximum drawdown of the strategy.
Updated on every candle (using high/low extremes and close) and on realized PnL updates.
max_drawdown_percentThe maximum drawdown of the strategy, as a percentage from a peak equity value.
Updated on every candle (using high/low extremes and close) and on realized PnL updates.
max_runupThe maximum run-up of the strategy.
Updated on every candle from intrabar extremes.
max_runup_percentThe maximum run-up of the strategy, as a percentage from a trough equity value.
Updated on every candle from intrabar extremes.

Market Context

These variables describe the executing grid.

VariableDescription
tickerPrimary market symbol used for the backtest (e.g. BTCUSDT).
Constant during the whole backtest execution.
tickeridFull exchange:symbol identifier (e.g. BINANCE:BTCUSDT).
Constant during the whole backtest execution.

Position Information

These variables describe the current position.

VariableDescription
position_avg_priceThe average entry price of the current position.
Recomputed on position entries and scale-ins, kept unchanged on partial scale-outs, and reset to NaN when the position becomes flat.
margin_liquidation_priceThe estimated liquidation price for the current position.
Recomputed when position size or margin settings change, and reset to NaN when the position becomes flat or margin is disabled.

Candle Data

These variables are time series that expose the OHLCV data of the current candle.

Note on series and indexing

  • Direct access, for example close, is equivalent to close[0].
  • Bracket indexing gives access to history: close[1] returns the previous candle, close[2] the one before, and so on.
  • If the requested index exceeds the available history, the returned value is NaN.
VariableDescription
openThe opening price of the current candle.
Updated on each newly closed candle of the main timeframe.
highThe highest price of the current candle.
Updated on each newly closed candle of the main timeframe.
lowThe lowest price of the current candle.
Updated on each newly closed candle of the main timeframe.
closeThe closing price of the current candle.
Updated on each newly closed candle of the main timeframe.
volumeThe volume of the current candle.
Updated on each newly closed candle of the main timeframe.
hl2The average of the high and low prices of the current candle.
Updated on each newly closed candle of the main timeframe.
hlc3The average of the high, low, and closing prices of the current candle.
Updated on each newly closed candle of the main timeframe.
ohlc4The average of the opening, high, low, and closing prices of the current candle.
Updated on each newly closed candle of the main timeframe.
hlcc4The average of the high, low, and twice the closing price of the current candle.
Updated on each newly closed candle of the main timeframe.