You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit cced2aa
Browse filesBrowse the repository at this point in the historyBrowse files
Docs: strategy.opentrades.* and strategy.closedtrades.* mapped field by field (R5 gap lane N18, item 3)
pine-to-native.md: the `strategy.opentrades.*` row no longer reads "lane
L2"; it names native_open_lots(mark) / NativeOpenLot and the C pair, and a
new "Open and closed trades" section maps every opentrades builtin
(entry_id, entry_comment, entry_bar_index, entry_time, entry_price, size,
commission, profit, max_runup, max_drawdown, the percent forms, and
position_entry_name) onto the row's fields, states the conventions (fee-net
P&L as the marked-equity term; gross excursions with the mark folded; the
caller's mark), and maps the closedtrades counterparts onto the existing
closed-trade accessors (closed_trade_count / closed_trade, the report rows,
pf_trade_t and the strategy_closed_trade_* C reads), including how a closed
row's commission and excursions derive from the lot. The stale
`trade_count()`/`get_trade(i)` anchors past engine.hpp's end are replaced by
the live ones.
native-engine.md: the book section describes the lot-by-lot snapshot beside
physical_position(); the C section counts 21 symbols and names the two new
reads.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 6a775b1a2ff72408cf192c1e76c260b0ce617c9c)
|`strategy.closedtrades`, `strategy.closedtrades.*`|`closed_trade_count()`/ `closed_trade(i)`engine.hpp:2395-2396, a `Trade` row; C: `pf_report_t::trades` (`pf_trade_t`) plus `strategy_closed_trade_entry_id` / `_exit_id` / `_exit_comment` / `_close_cause` / `_entry_incarnation` pineforge.h:1029-1089 | Field by field in [Open and closed trades](@ref pine_to_native_map_trades). `report_trade_count()` / `get_report_trade(i)` engine.hpp:2403-2406 span the same rows followed by the range-end rows.|
122
122
|`strategy.netprofit`, equity curve, drawdown | partial — `fill_report` engine.hpp:3161 | The trade list and trade statistics are filled; for a bare native host the **equity curve is empty** (the recorders are protected, engine.hpp:2386-2412) so equity metrics degenerate silently engine_metrics.cpp:168, and a position still open at the end has no range-end row engine_run.cpp:191. **Lane L2**. |
123
-
|`strategy.opentrades.*`|**lane L2**||
123
+
|`strategy.opentrades`, `strategy.opentrades.*`|`native_open_lots(mark)` native_host.hpp:861 → one `NativeOpenLot` native_host.hpp:255 per open physical lot; C: `strategy_native_open_lot_count_v1(s, mark)` / `strategy_native_open_lot_get_v1(s, i, &row)` native_c_api.h:871-879 → `pf_native_open_lot_v1` native_c_api.h:509 | Owning snapshot of the book lot by lot, oldest first, marked at the price you pass (Pine marks at the current `close`; pass the bar's close in `on_native_bar`, the fill price in `on_native_applied`, the print in `on_native_tick`). Observation only: it moves no fill, no hash and no row. Field by field in [Open and closed trades](@ref pine_to_native_map_trades). |
124
+
125
+
### Open and closed trades {#pine_to_native_map_trades}
126
+
127
+
Pine indexes both namespaces by trade number; the native rows carry the
128
+
same facts plus the identity Pine has no word for — the request incarnation
129
+
that opened the lot and the position cycle it belongs to — so a host can
130
+
name a lot in a later `BindOpening` or match it to the closed row it becomes.
131
+
132
+
**Open trades.**`native_open_lots(mark)` native_host.hpp:861 answers one
133
+
`NativeOpenLot` native_host.hpp:255 per open physical lot, in book order
134
+
(`physical_position().lot_count` rows). The C twin is
135
+
`strategy_native_open_lot_count_v1(s, mark)` then
136
+
`strategy_native_open_lot_get_v1(s, i, &row)` native_c_api.h:871-879 into a
137
+
`pf_native_open_lot_v1` native_c_api.h:509, whose two strings borrow the
138
+
snapshot until the next count call. `mark` is the price the three marked
139
+
fields are computed at; Pine's builtins mark at the current `close`.
140
+
141
+
| Pine |`NativeOpenLot` field | Notes |
142
+
| --- | --- | --- |
143
+
|`strategy.opentrades`|`native_open_lots(mark).size()`, `physical_position().lot_count`| C: the count `strategy_native_open_lot_count_v1` returns. |
144
+
|`strategy.opentrades.entry_id(i)`|`entry_label`| The opening request's `label`. `entry_incarnation` is the never-reused identity behind it; `cycle` the position cycle (`BindOpening{handle, cycle}`). |
145
+
|`strategy.opentrades.entry_comment(i)`|`entry_comment`| The opening request's `comment`. |
146
+
|`strategy.opentrades.entry_bar_index(i)`|`entry_bar_index`| Script-bar index of the opening fill. |
147
+
|`strategy.opentrades.entry_time(i)`|`entry_time_ms`| Effective time of the opening fill, Unix ms. |
148
+
|`strategy.opentrades.entry_price(i)`|`entry_price`| The booked price (slippage and grid already applied). |
149
+
|`strategy.opentrades.size(i)`|`signed_units`| Pine's is unsigned with a separate direction; here `> 0` is long, `< 0` short, and `side` says the same. |
150
+
|`strategy.opentrades.commission(i)`|`entry_commission`| The entry fee still on the lot, account currency. A partial close takes its share of it onto the closed row. |
151
+
|`strategy.opentrades.profit(i)`|`unrealized_pnl`| The move from `entry_price` to `mark` in account currency, **net of `entry_commission`** — the lot's own term of `native_marked_equity(mark)`, so the realized balance plus these rows is the marked equity. Gross is `unrealized_pnl + entry_commission`. |
152
+
|`strategy.opentrades.max_runup(i)`|`favorable_excursion`| Largest move for the lot the kernel has sampled along the delivered path, account currency, gross of fees, `mark` folded in. |
153
+
|`strategy.opentrades.max_drawdown(i)`|`adverse_excursion`| Largest move against the lot, likewise; both are magnitudes `>= 0`. |
154
+
|`strategy.opentrades.max_runup_percent(i)` / `max_drawdown_percent(i)` / `profit_percent(i)`| derive: `value / (entry_price * abs(signed_units) * point_value * account_fx) * 100`| Percent of entry cost; the snapshot carries the facts, not the ratio. |
155
+
|`strategy.position_entry_name`|`native_open_lots(mark).back().entry_label`| The newest lot's label. |
156
+
157
+
A NaN `mark` keeps every booking fact, leaves `unrealized_pnl` NaN and folds
158
+
nothing into the excursions. A host that owns lot excursions
159
+
(`owns_lot_excursions()`) keeps its own sampler, so for that run the two
|`strategy.closedtrades.entry_id(i)` / `entry_comment(i)`|`entry_id`, `entry_comment`| The same strings the lot carried as `entry_label` / `entry_comment`; `entry_incarnation` is the same identity. |
175
+
|`strategy.closedtrades.entry_bar_index(i)` / `entry_time(i)` / `entry_price(i)`|`entry_bar_index`, `entry_time`, `entry_price`| Copied from the lot. |
176
+
|`strategy.closedtrades.exit_id(i)` / `exit_comment(i)`|`exit_id`, `exit_comment`| The closing request's `label` / `comment`; `closed_trade_close_cause(i)` says why (script, bracket, liquidation, risk, range end). |
|`strategy.closedtrades.size(i)`|`qty`, `is_long`| Unsigned, with the direction beside it. A partial close books a row for the closed slice only. |
179
+
|`strategy.closedtrades.commission(i)`|`commission`| Entry share plus exit share, account currency. One cash-per-execution ticket is split by units over every slice of that execution — the closed rows and, for a reversal, the lot it opened. |
180
+
|`strategy.closedtrades.profit(i)`|`pnl`| Net of `commission`. `pnl + commission` is the gross move, which equals the lot's `unrealized_pnl + entry_commission` at a `mark` equal to the exit price, scaled to the closed slice. |
181
+
|`strategy.closedtrades.profit_percent(i)`|`pnl_pct`| Net return on entry cost. |
182
+
|`strategy.closedtrades.max_runup(i)` / `max_drawdown(i)`|`max_runup`, `max_drawdown`| TradingView's net-open-profit basis: the lot's gross favorable excursion less the entry share, floored at zero; the adverse excursion plus the entry share. The open-lot fields are the gross values these are derived from. |
183
+
|`strategy.closedtrades.max_runup_percent(i)` / `max_drawdown_percent(i)`| derive from the two fields over `entry_price * qty * point_value`||
0 commit comments