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 on each mark-to-market update, on every closed candle, and after each order execution or liquidation.
netprofitThe net profit of the strategy.
Updated on each realized PnL event (close or liquidation), then recomputed at the end of the backtest.
grossprofitThe gross profit of the strategy.
Updated on each close or liquidation with positive realized PnL.
grosslossThe gross loss of the strategy.
Updated on each close or liquidation with negative realized PnL.
openprofitThe unrealized profit or loss on open positions.
Recomputed on each mark-to-market update, 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 on each mark-to-market update, on every closed candle, and after each order execution or liquidation.
grossprofit_percentThe gross profit of the strategy, as a percentage of the initial capital.
Updated whenever grossprofit is updated (winning close or liquidation).
grossloss_percentThe gross loss of the strategy, as a percentage of the initial capital.
Updated whenever grossloss is updated (losing close or liquidation).
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, as a percentage of the trade’s cost basis.
Recomputed on each recorded close (including partial closes and liquidations).
avg_losing_trade_percentThe average loss of losing trades, as a percentage of the trade’s cost basis.
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, as a percentage of the trade’s cost basis.
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 provide access to the OHLCV data of the current candle.

Note on series and indexing

  • Direct access (for example close) returns 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.