State and variables
LiSA Script DCA strategies can read protected backtest context values and maintain strategy-owned variables. These state features are not part of the current Trading contract.
Reads
get(name) is the read primitive for both protected context values and strategy variables. Missing strategy variables read as 0.
| Read | Meaning |
|---|---|
get('cash') | Available simulated quote cash at this point in the ordered action flow. |
get('spent') | Total simulated quote cash spent by buy actions so far. |
get('btc_value') | BTC position value marked at the current candle close. |
get(name) | Strategy-owned numeric variable. |
Protected context names are read-only. set actions cannot write cash, spent, btc_value, last_buy, or last_buy.*.
Set actions
{
"name": "Advance counter",
"type": "set",
"values": {
"buy_count": "get('buy_count') + 1"
}
} values must be a non-empty object. Each value can be a supported expression.
Last buy context
last_buy.* exposes numeric fill context from the latest buy attempt in the current ordered action flow. It resets each evaluation candle and updates after every buy attempt, including zero-fill attempts.
| Read | Meaning |
|---|---|
get('last_buy.requested_quote') | Quote amount requested. |
get('last_buy.cash_spent') | Filled quote cash. |
get('last_buy.quote_amount') | Net quote amount converted into BTC after fees. |
get('last_buy.btc_bought') | BTC acquired. |
get('last_buy.fee_quote') | Quote fee. |
get('last_buy.execution_price') | Raw simulated execution price. |
get('last_buy.effective_price') | Execution price including slippage. |
get('last_buy.cash_before') / cash_after | Cash before and after the buy attempt. |
get('last_buy.btc_before') / btc_after | BTC position before and after the buy attempt. |
get('last_buy.total_spent_before') / total_spent_after | Total spent before and after the buy attempt. |
get('last_buy.filled') | 1 if any quote cash filled, otherwise 0. |
get('last_buy.full') | 1 if the requested quote filled fully. |
get('last_buy.partial') | 1 if the requested quote filled partially. |
get('last_buy.zero') | 1 if the attempt filled nothing. |
State variable lines can plot strategy variables over time. See Indicators and external series.