Strategy

View as Markdown

Account Info

FunctionStatusDescription
strategy.account_currencyAccount currency
strategy.equityAccount equity
strategy.grosslossGross loss
strategy.grossloss_percentGross loss percentage
strategy.grossprofitGross profit
strategy.grossprofit_percentGross profit percentage
strategy.initial_capitalInitial capital
strategy.margin_liquidation_priceMargin liquidation price
strategy.netprofitNet profit
strategy.netprofit_percentNet profit percentage

Trade Statistics

FunctionStatusDescription
strategy.avg_losing_tradeAverage losing trade
strategy.avg_losing_trade_percentAverage losing trade percent
strategy.avg_tradeAverage trade
strategy.avg_trade_percentAverage trade percent
strategy.avg_winning_tradeAverage winning trade
strategy.avg_winning_trade_percentAverage winning trade percent
strategy.closedtradesNumber of closed trades
strategy.eventradesNumber of even trades
strategy.losstradesNumber of losing trades
strategy.opentradesNumber of open trades
strategy.wintradesNumber of winning trades

Closed Trades

FunctionStatusDescription
strategy.closedtrades.first_indexFirst closed trade index
strategy.closedtrades.commission()Get commission
strategy.closedtrades.entry_bar_index()Get entry bar index
strategy.closedtrades.entry_comment()Get entry comment
strategy.closedtrades.entry_id()Get entry ID
strategy.closedtrades.entry_price()Get entry price
strategy.closedtrades.entry_time()Get entry time
strategy.closedtrades.exit_bar_index()Get exit bar index
strategy.closedtrades.exit_comment()Get exit comment
strategy.closedtrades.exit_id()Get exit ID
strategy.closedtrades.exit_price()Get exit price
strategy.closedtrades.exit_time()Get exit time
strategy.closedtrades.max_drawdown()Get max drawdown
strategy.closedtrades.max_drawdown_percent()Get max drawdown percent
strategy.closedtrades.max_runup()Get max runup
strategy.closedtrades.max_runup_percent()Get max runup percent
strategy.closedtrades.profit()Get profit
strategy.closedtrades.profit_percent()Get profit percent
strategy.closedtrades.size()Get size

Drawdown & Runup

FunctionStatusDescription
strategy.max_contracts_held_allMax contracts held (all)
strategy.max_contracts_held_longMax contracts held (long)
strategy.max_contracts_held_shortMax contracts held (short)
strategy.max_drawdownMaximum drawdown
strategy.max_drawdown_percentMaximum drawdown percent
strategy.max_runupMaximum runup
strategy.max_runup_percentMaximum runup percent

Position Info

FunctionStatusDescription
strategy.openprofitOpen profit
strategy.openprofit_percentOpen profit percent
strategy.position_avg_pricePosition average price
strategy.position_entry_namePosition entry name
strategy.position_sizePosition size

Open Trades

FunctionStatusDescription
strategy.opentrades.capital_heldCapital held
strategy.opentrades.commission()Get commission
strategy.opentrades.entry_bar_index()Get entry bar index
strategy.opentrades.entry_comment()Get entry comment
strategy.opentrades.entry_id()Get entry ID
strategy.opentrades.entry_price()Get entry price
strategy.opentrades.entry_time()Get entry time
strategy.opentrades.max_drawdown()Get max drawdown
strategy.opentrades.max_drawdown_percent()Get max drawdown percent
strategy.opentrades.max_runup()Get max runup
strategy.opentrades.max_runup_percent()Get max runup percent
strategy.opentrades.profit()Get profit
strategy.opentrades.profit_percent()Get profit percent
strategy.opentrades.size()Get size

Constants

FunctionStatusDescription
strategy.cashCash constant
strategy.fixedFixed constant
strategy.longLong constant
strategy.percent_of_equityPercent of equity constant
strategy.shortShort constant

Commission

FunctionStatusDescription
strategy.commission.cash_per_contractCash per contract
strategy.commission.cash_per_orderCash per order
strategy.commission.percentCommission percent

Direction

FunctionStatusDescription
strategy.direction.allAll directions
strategy.direction.longLong direction
strategy.direction.shortShort direction

OCA

FunctionStatusDescription
strategy.oca.cancelOCA cancel
strategy.oca.noneOCA none
strategy.oca.reduceOCA reduce

Order Management

FunctionStatusDescription
strategy.cancel()Cancel order
strategy.cancel_all()Cancel all orders

Position Management

FunctionStatusDescription
strategy.close()Close position
strategy.close_all()Close all positions
strategy.entry()Enter position
strategy.exit()Exit position
strategy.order()Place order

Conversion

FunctionStatusDescription
strategy.convert_to_account()Convert to account
strategy.convert_to_symbol()Convert to symbol
strategy.default_entry_qty()Default entry quantity

Risk Management

FunctionStatusDescription
strategy.risk.allow_entry_in()Allow entry in
strategy.risk.max_cons_loss_days()Max consecutive loss days
strategy.risk.max_drawdown()Max drawdown
strategy.risk.max_intraday_filled_orders()Max intraday filled orders
strategy.risk.max_intraday_loss()Max intraday loss
strategy.risk.max_position_size()Max position size

Notes

The entire strategy.* namespace is implemented and matches TV's surface 1:1. Of the 31 TV oracle scripts in Automations/PineTS/pinescripts/strategy/, 12 currently match TradingView to comparator-epsilon (precision 3, eps 0.001001). The remaining 18 produce valid output that diverges from TV in specific numeric fields — these are precision/semantics differences that need iterative refinement:

  • strategy.margin_liquidation_price — PineTS uses a simple "equity hits zero" approximation; TV's broker liquidation formula differs in detail. Affects account_props.pine.
  • strategy.convert_to_account / convert_to_symbol — identity passthrough for same-currency cases. TV may return na when symbol/account currencies differ even nominally (e.g. BTCUSDC's USDC vs USD). Affects conversion.pine.
  • OCA enforcement (cancel/reduce semantics) — order objects carry oca_name / oca_type fields, but the engine does not yet auto-cancel or reduce siblings on fill. Deferred. Affects oca_groups.pine.
  • Commission rounding — per-leg charges may differ from TV by sub-cent rounding in edge cases. Affects commission_slippage.pine and commission_types.pine in the second-decimal place.
  • Per-trade max_drawdown / max_runup — PineTS tracks intra-bar high/low excursions, but TV's accounting includes the entry price's pre-fill open and exit-bar close in subtly different ways for trades that open and close in adjacent bars. Affects closedtrades_full.pine, opentrades_full.pine.

oca_groups.pine is the explicit Phase 7 deferral. All others are iteration items for follow-up work.

On this page