Reference
Strategy
Guides and navigation are localized. Built-in reference descriptions and code examples are maintained in English.
| Name / Signature | Description | Returns |
|---|---|---|
| alerta.strategy.entrystrategy.entry(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, disable_alert) | Enters a market position (long or short) for strategy backtesting. Must run inside a strategy script header. | void |
| alerta.strategy.exitstrategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, oca_name, comment, comment_profit, comment_loss, comment_trailing, alert_message, alert_profit, alert_loss, alert_trailing, disable_alert) | Exits a specific entry by ID with take-profit / stop-loss / trailing legs. `profit`/`loss` are TICK offsets from the entry price; `limit`/`stop` are absolute prices. `from_entry` scopes the exit (and its qty/qty_percent) to trades opened by that entry id. Per-leg comments label the trade by whichever leg fired. | void |
| alerta.strategy.closestrategy.close(id, comment, qty, qty_percent, alert_message, immediately, disable_alert) | Closes what the entry with this id opened, at market price, at the next bar's open (`immediately=true`: at the signal bar's close). With the default close_entries_rule (FIFO) that quantity is taken from the oldest open trades first, so the list of trades can show an earlier entry closed by this order; with close_entries_rule = "ANY" the entry's own trades are closed. When the entry has no open trade the call does nothing — it is not kept for a later position. Must run inside a strategy script header. | void |
| alerta.strategy.orderstrategy.order(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, disable_alert) | Places a market, limit, or stop order regardless of the current position. Does not automatically reverse positions like strategy.entry. | void |
| alerta.strategy.equitystrategy.equity | Returns the current equity (initial capital + realized profit + open profit) for the strategy at the current bar. | series float |
| alerta.strategy.netprofit_percentstrategy.netprofit_percent | Realized net profit expressed as a percentage of the initial capital. Companion percent variants also available: strategy.openprofit_percent, strategy.grossprofit_percent, strategy.grossloss_percent, strategy.max_drawdown_percent, strategy.max_runup_percent. | series float |
| alerta.strategy.avg_tradestrategy.avg_trade | Average profit/loss per closed trade. Companions: strategy.avg_trade_percent (per-trade % of entry notional), strategy.avg_winning_trade(_percent), strategy.avg_losing_trade(_percent). | series float |
| alerta.strategy.margin_liquidation_pricestrategy.margin_liquidation_price | Price at which a margin call would liquidate the position. AlertaScript does not simulate leverage/margin, so this returns na — matching Pine's value when margin requirements are 100%. | series float (na) |
| alerta.strategy.position_sizestrategy.position_size | Returns the size of the current open position. Positive for long positions, negative for short positions, and 0 if neutral. | series float |
| alerta.strategy.openprofitstrategy.openprofit | Returns the unrealized profit/loss of the currently open positions. | series float |
| alerta.strategy.risk.max_drawdownstrategy.risk.max_drawdown(value, type) | Sets the maximum drawdown limit for the strategy. If reached, the strategy stops opening new positions. | void |
| alerta.strategy.risk.max_position_sizestrategy.risk.max_position_size(size) | Caps the quantity of any entry order to the specified size. | void |
| alerta.strategy.risk.allow_entry_instrategy.risk.allow_entry_in(direction) | Restricts strategy entries to a specific direction. | void |
| alerta.strategy.opentradesstrategy.opentrades | Returns the number of currently open trades in the strategy. | int |
| alerta.strategy.closedtradesstrategy.closedtrades | Returns the total number of closed trades in the strategy performance history. | int |
| alerta.strategy.opentrades.entry_pricestrategy.opentrades.entry_price(trade_index) | Returns the entry price for the specified open trade. | float |
| alerta.strategy.closedtrades.profitstrategy.closedtrades.profit(trade_index) | Returns the profit or loss for the specified closed trade. | float |
| alerta.strategy.cancelstrategy.cancel(id) | Cancels pending orders and active exits with the given id. | void |
| alerta.strategy.cancel_allstrategy.cancel_all() | Cancels all pending entries and active exit orders. | void |
| alerta.strategy.close_allstrategy.close_all(comment, alert_message, immediately, disable_alert) | Closes all open positions at market. `immediately=true` fills at the signal bar's close instead of the next bar's open. | void |
| alerta.strategy.risk.max_cons_loss_daysstrategy.risk.max_cons_loss_days(count) | Stops new entries after the configured number of consecutive losing trades. | void |
| alerta.strategy.risk.max_intraday_filled_ordersstrategy.risk.max_intraday_filled_orders(count) | Limits how many fills can occur within the current bar/day approximation. | void |
| alerta.strategy.risk.max_intraday_lossstrategy.risk.max_intraday_loss(value, type) | Stops new entries when current bar/day loss limit is exceeded. | void |
| alerta.strategy.opentrades.profit_percentstrategy.opentrades.profit_percent(trade_index) | Returns mark-to-market profit percent for an open trade. | float |
| alerta.strategy.closedtrades.profit_percentstrategy.closedtrades.profit_percent(trade_index) | Returns realized profit percent for a closed trade. | float |
| alerta.strategy.opentrades.entry_bar_indexstrategy.opentrades.entry_bar_index(trade_index) | Returns the entry bar index of an open trade. | int |
| alerta.strategy.closedtrades.entry_bar_indexstrategy.closedtrades.entry_bar_index(trade_index) | Returns entry bar index for a closed trade. | int |
| alerta.strategy.closedtrades.exit_bar_indexstrategy.closedtrades.exit_bar_index(trade_index) | Returns exit bar index for a closed trade. | int |
| alerta.strategy.opentrades.max_runupstrategy.opentrades.max_runup(trade_index) | Returns max favorable excursion for an open trade. | float |
| alerta.strategy.opentrades.max_drawdownstrategy.opentrades.max_drawdown(trade_index) | Returns max adverse excursion for an open trade. | float |
| alerta.strategy.closedtrades.max_runupstrategy.closedtrades.max_runup(trade_index) | Returns max favorable excursion for a closed trade. | float |
| alerta.strategy.closedtrades.max_drawdownstrategy.closedtrades.max_drawdown(trade_index) | Returns max adverse excursion for a closed trade. | float |
| alerta.strategy.opentrades.entry_idstrategy.opentrades.entry_id(trade_index) | Returns entry id of an open trade. | string |
| alerta.strategy.closedtrades.entry_idstrategy.closedtrades.entry_id(trade_index) | Returns entry id of a closed trade. | string |
| alerta.strategy.closedtrades.exit_idstrategy.closedtrades.exit_id(trade_index) | Returns the id of the order that closed the trade: the strategy.exit id, the id passed to strategy.close, the reversing entry's id, or "close_all". | string |
| alerta.strategy.opentrades.entry_commentstrategy.opentrades.entry_comment(trade_index) | Returns entry comment of an open trade. | string |
| alerta.strategy.opentrades.entry_timestrategy.opentrades.entry_time(trade_index) | Returns entry time of an open trade. | int |
| alerta.strategy.opentrades.sizestrategy.opentrades.size(trade_index) | Returns quantity of an open trade. | float |
| alerta.strategy.opentrades.commissionstrategy.opentrades.commission(trade_index) | Returns accumulated commission of an open trade. | float |
| alerta.strategy.opentrades.profitstrategy.opentrades.profit(trade_index) | Returns current unrealized profit of an open trade. | float |
| alerta.strategy.opentrades.max_runup_percentstrategy.opentrades.max_runup_percent(trade_index) | Returns max runup percent for an open trade. | float |
| alerta.strategy.opentrades.max_drawdown_percentstrategy.opentrades.max_drawdown_percent(trade_index) | Returns max drawdown percent for an open trade. | float |
| alerta.strategy.opentrades.entry_barstrategy.opentrades.entry_bar(trade_index) | Alias of entry bar index for open trades. | int |
| alerta.strategy.closedtrades.entry_pricestrategy.closedtrades.entry_price(trade_index) | Returns entry price of a closed trade. | float |
| alerta.strategy.closedtrades.entry_commentstrategy.closedtrades.entry_comment(trade_index) | Returns entry comment of a closed trade. | string |
| alerta.strategy.closedtrades.entry_timestrategy.closedtrades.entry_time(trade_index) | Returns entry time of a closed trade. | int |
| alerta.strategy.closedtrades.exit_pricestrategy.closedtrades.exit_price(trade_index) | Returns exit price of a closed trade. | float |
| alerta.strategy.closedtrades.exit_commentstrategy.closedtrades.exit_comment(trade_index) | Returns exit comment of a closed trade. | string |
| alerta.strategy.closedtrades.exit_timestrategy.closedtrades.exit_time(trade_index) | Returns exit time of a closed trade. | int |
| alerta.strategy.closedtrades.sizestrategy.closedtrades.size(trade_index) | Returns quantity of a closed trade. | float |
| alerta.strategy.closedtrades.commissionstrategy.closedtrades.commission(trade_index) | Returns paid commission of a closed trade. | float |
| alerta.strategy.closedtrades.max_runup_percentstrategy.closedtrades.max_runup_percent(trade_index) | Returns max runup percent for a closed trade. | float |
| alerta.strategy.closedtrades.max_drawdown_percentstrategy.closedtrades.max_drawdown_percent(trade_index) | Returns max drawdown percent for a closed trade. | float |
| alerta.strategy.closedtrades.entry_barstrategy.closedtrades.entry_bar(trade_index) | Alias of entry bar index for closed trades. | int |
| alerta.strategy.closedtrades.exit_barstrategy.closedtrades.exit_bar(trade_index) | Alias of exit bar index for closed trades. | int |
| alerta.strategy.initial_capitalstrategy.initial_capital | Returns the starting capital defined in the strategy() declaration. | float |
| alerta.strategy.grossprofitstrategy.grossprofit | Returns the total profit from all winning closed trades. | float |
| alerta.strategy.grosslossstrategy.grossloss | Returns the total loss (as a positive number) from all losing closed trades. | float |
| alerta.strategy.wintradesstrategy.wintrades | Returns the number of closed trades that ended with a profit. | int |
| alerta.strategy.losstradesstrategy.losstrades | Returns the number of closed trades that ended with a loss. | int |
| alerta.strategy.eventradesstrategy.eventrades | Returns the number of closed trades that ended at breakeven (no profit, no loss). | int |
| alerta.strategy.max_drawdownstrategy.max_drawdown | Returns the maximum equity drawdown of the backtest, intrabar as in the Strategy Tester: the highest closed-trade equity so far minus the equity at a bar's adverse extreme (the low of a long, the high of a short). | float |
| alerta.strategy.max_runupstrategy.max_runup | Returns the maximum equity run-up of the backtest, intrabar: the equity at a bar's favourable extreme minus the lowest closed-trade equity so far. | float |
| alerta.strategy.account_currencystrategy.account_currency | Returns the account currency of strategy equity and P&L: the strategy() currency, or the symbol's own currency when it is currency.NONE (the default) — e.g. "USDT" on BTCUSDT. | string |
| alerta.strategy.default_entry_qtystrategy.default_entry_qty(fill_price) | Returns the default order quantity that strategy settings imply at a given fill price. | series float |
| alerta.strategy.percent_of_equitystrategy.percent_of_equity → string | Pine v6 default_qty_type: orders sized as a percentage of current strategy equity. | string |
| alerta.strategy.cashstrategy.cash → string | Pine v6 default_qty_type: orders sized in cash (account currency) per fill. | string |
| alerta.strategy.fixedstrategy.fixed → string | Pine v6 default_qty_type: fixed quantity in shares/contracts. | string |
| alerta.strategy.contractsstrategy.contracts → string | Pine v6 default_qty_type: number of contracts. | string |
| alerta.strategy.oca.nonestrategy.oca.none → string | Pine v6 OCA type — order is not part of a One-Cancels-All group. | string |
| alerta.strategy.oca.cancelstrategy.oca.cancel → string | Pine v6 OCA type — when this order fills, every other order in the same OCA group is cancelled. | string |
| alerta.strategy.oca.reducestrategy.oca.reduce → string | Pine v6 OCA type — siblings are qty-reduced (rather than fully cancelled) by the filled amount. | string |
| alerta.strategy.position_entry_namestrategy.position_entry_name → string | Pine v6: ID of the most recent open entry order. | string |
| alerta.strategy.position_size_maxstrategy.position_size_max → float | Pine v6: largest absolute position size held across the backtest. | float |
| alerta.strategy.max_contracts_held_allstrategy.max_contracts_held_all → float | Pine v6: largest absolute contract count held across the backtest (alias of position_size_max). | float |
| alerta.strategy.max_contracts_held_longstrategy.max_contracts_held_long → float | Pine v6: largest long-side contract count held. | float |
| alerta.strategy.max_contracts_held_shortstrategy.max_contracts_held_short → float | Pine v6: largest short-side contract count held. | float |
| alerta.strategy.position_avg_pricestrategy.position_avg_price → series float | Average entry price of the currently open simulated strategy position. The value follows fills in the strategy simulator. While the strategy has no position it is na, as in Pine. | series float |
| alerta.strategy.netprofitstrategy.netprofit → series float | Cumulative realized profit and loss from closed simulated strategy trades. It does not include the unrealized profit of the currently open position. | series float |
| alerta.strategy.convert_to_accountstrategy.convert_to_account(value) | Converts a value in the symbol's currency to the strategy's account currency. Strategies here keep their money in the symbol's currency, so the value comes back unchanged — exact when both currencies are the same, as on every USDT pair. | series float |
| alerta.strategy.convert_to_symbolstrategy.convert_to_symbol(value) | Converts a value in the strategy's account currency to the symbol's currency — the way to size an order from a cash amount. Strategies here keep their money in the symbol's currency, so the value comes back unchanged — exact when both currencies are the same, as on every USDT pair. | series float |
| alerta.strategy.closedtrades.first_indexstrategy.closedtrades.first_index → int | The trade number of the oldest closed trade the strategy keeps. No closed trade is ever dropped from the list here, so it is always 0. | int |
| alerta.strategy.close_entries_rule.ANYstrategy.close_entries_rule.ANY → const string | Entry matching rule used when closing strategy trades. Use strategy.close_entries_rule.ANY as a value, without parentheses. | const string |
| alerta.strategy.close_entries_rule.FIFOstrategy.close_entries_rule.FIFO → const string | Entry matching rule used when closing strategy trades. Use strategy.close_entries_rule.FIFO as a value, without parentheses. | const string |
| alerta.strategy.commission.cash_per_contractstrategy.commission.cash_per_contract → const string | Commission calculation mode in the strategy declaration. Use strategy.commission.cash_per_contract as a value, without parentheses. | const string |
| alerta.strategy.commission.cash_per_orderstrategy.commission.cash_per_order → const string | Commission calculation mode in the strategy declaration. Use strategy.commission.cash_per_order as a value, without parentheses. | const string |
| alerta.strategy.commission.percentstrategy.commission.percent → const string | Commission calculation mode in the strategy declaration. Use strategy.commission.percent as a value, without parentheses. | const string |
| alerta.strategy.direction.allstrategy.direction.all → const string | Direction accepted by the strategy risk configuration. Use strategy.direction.all as a value, without parentheses. | const string |
| alerta.strategy.direction.longstrategy.direction.long → const string | Direction accepted by the strategy risk configuration. Use strategy.direction.long as a value, without parentheses. | const string |
| alerta.strategy.direction.shortstrategy.direction.short → const string | Direction accepted by the strategy risk configuration. Use strategy.direction.short as a value, without parentheses. | const string |
| alerta.strategy.longstrategy.long → const string | Strategy order direction or quantity mode. Use strategy.long as a value, without parentheses. | const string |
| alerta.strategy.shortstrategy.short → const string | Strategy order direction or quantity mode. Use strategy.short as a value, without parentheses. | const string |