openpinescript 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +346 -2
- package/dist/cli.mjs +108686 -0
- package/dist/index.cjs +108670 -0
- package/dist/index.mjs +108624 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/parser/v1/generated/PineV1Lexer.d.ts +66 -0
- package/dist/types/parser/v1/generated/PineV1Parser.d.ts +555 -0
- package/dist/types/parser/v1/generated/PineV1ParserVisitor.d.ts +318 -0
- package/dist/types/parser/v1/index.d.ts +39 -0
- package/dist/types/parser/v2/generated/PineV2Lexer.d.ts +67 -0
- package/dist/types/parser/v2/generated/PineV2Parser.d.ts +568 -0
- package/dist/types/parser/v2/generated/PineV2ParserVisitor.d.ts +325 -0
- package/dist/types/parser/v2/index.d.ts +2 -0
- package/dist/types/parser/v3/generated/PineV3Lexer.d.ts +67 -0
- package/dist/types/parser/v3/generated/PineV3Parser.d.ts +568 -0
- package/dist/types/parser/v3/generated/PineV3ParserVisitor.d.ts +325 -0
- package/dist/types/parser/v3/index.d.ts +2 -0
- package/dist/types/parser/v4/generated/PineV4Lexer.d.ts +86 -0
- package/dist/types/parser/v4/generated/PineV4Parser.d.ts +673 -0
- package/dist/types/parser/v4/generated/PineV4ParserVisitor.d.ts +367 -0
- package/dist/types/parser/v4/index.d.ts +2 -0
- package/dist/types/parser/v5/generated/PineV5Lexer.d.ts +95 -0
- package/dist/types/parser/v5/generated/PineV5Parser.d.ts +964 -0
- package/dist/types/parser/v5/generated/PineV5ParserVisitor.d.ts +521 -0
- package/dist/types/parser/v5/index.d.ts +2 -0
- package/dist/types/parser/v6/generated/PineV6Lexer.d.ts +98 -0
- package/dist/types/parser/v6/generated/PineV6Parser.d.ts +984 -0
- package/dist/types/parser/v6/generated/PineV6ParserVisitor.d.ts +528 -0
- package/dist/types/parser/v6/index.d.ts +2 -0
- package/dist/types/runtime/v1/Series.d.ts +61 -0
- package/dist/types/runtime/v1/broker/Broker.d.ts +325 -0
- package/dist/types/runtime/v1/broker/index.d.ts +158 -0
- package/dist/types/runtime/v1/broker/val.d.ts +28 -0
- package/dist/types/runtime/v1/constDefault.d.ts +11 -0
- package/dist/types/runtime/v1/context.d.ts +1705 -0
- package/dist/types/runtime/v1/footprint.d.ts +32 -0
- package/dist/types/runtime/v1/index.d.ts +7 -0
- package/dist/types/runtime/v1/language-spec.d.ts +12 -0
- package/dist/types/runtime/v1/openTrades.d.ts +12 -0
- package/dist/types/runtime/v1/palette.d.ts +18 -0
- package/dist/types/runtime/v1/session.d.ts +482 -0
- package/dist/types/runtime/v1/sessions.d.ts +31 -0
- package/dist/types/runtime/v1/stateClone.d.ts +19 -0
- package/dist/types/runtime/v1/stdlib/alerts.d.ts +31 -0
- package/dist/types/runtime/v1/stdlib/arrays.d.ts +133 -0
- package/dist/types/runtime/v1/stdlib/barmerge.d.ts +27 -0
- package/dist/types/runtime/v1/stdlib/barstate.d.ts +79 -0
- package/dist/types/runtime/v1/stdlib/cast.d.ts +81 -0
- package/dist/types/runtime/v1/stdlib/chart.d.ts +283 -0
- package/dist/types/runtime/v1/stdlib/color.d.ts +51 -0
- package/dist/types/runtime/v1/stdlib/core.d.ts +162 -0
- package/dist/types/runtime/v1/stdlib/dataset.d.ts +36 -0
- package/dist/types/runtime/v1/stdlib/display.d.ts +50 -0
- package/dist/types/runtime/v1/stdlib/drawings.d.ts +407 -0
- package/dist/types/runtime/v1/stdlib/errors.d.ts +21 -0
- package/dist/types/runtime/v1/stdlib/font.d.ts +20 -0
- package/dist/types/runtime/v1/stdlib/footprint.d.ts +76 -0
- package/dist/types/runtime/v1/stdlib/format.d.ts +57 -0
- package/dist/types/runtime/v1/stdlib/index.d.ts +71 -0
- package/dist/types/runtime/v1/stdlib/input.d.ts +14 -0
- package/dist/types/runtime/v1/stdlib/inputs.d.ts +60 -0
- package/dist/types/runtime/v1/stdlib/late_members.d.ts +97 -0
- package/dist/types/runtime/v1/stdlib/logging.d.ts +31 -0
- package/dist/types/runtime/v1/stdlib/maps.d.ts +55 -0
- package/dist/types/runtime/v1/stdlib/math.d.ts +71 -0
- package/dist/types/runtime/v1/stdlib/matrix.d.ts +201 -0
- package/dist/types/runtime/v1/stdlib/metadata.d.ts +14 -0
- package/dist/types/runtime/v1/stdlib/mtf.d.ts +15 -0
- package/dist/types/runtime/v1/stdlib/renames.d.ts +117 -0
- package/dist/types/runtime/v1/stdlib/renames5.d.ts +113 -0
- package/dist/types/runtime/v1/stdlib/renames6.d.ts +81 -0
- package/dist/types/runtime/v1/stdlib/request.d.ts +207 -0
- package/dist/types/runtime/v1/stdlib/scale.d.ts +19 -0
- package/dist/types/runtime/v1/stdlib/session.d.ts +113 -0
- package/dist/types/runtime/v1/stdlib/sort_field.d.ts +12 -0
- package/dist/types/runtime/v1/stdlib/sources.d.ts +24 -0
- package/dist/types/runtime/v1/stdlib/str.d.ts +117 -0
- package/dist/types/runtime/v1/stdlib/strategy.d.ts +314 -0
- package/dist/types/runtime/v1/stdlib/syminfo.d.ts +209 -0
- package/dist/types/runtime/v1/stdlib/ta.d.ts +409 -0
- package/dist/types/runtime/v1/stdlib/time.d.ts +158 -0
- package/dist/types/runtime/v1/stdlib/trades.d.ts +108 -0
- package/dist/types/runtime/v1/stdlib/ui.d.ts +196 -0
- package/dist/types/runtime/v1/stdlib/v6_members.d.ts +68 -0
- package/dist/types/runtime/v1/timeframes.d.ts +139 -0
- package/dist/types/runtime/v1/zones.d.ts +30 -0
- package/dist/types/transpiler/common/index.d.ts +51 -0
- package/dist/types/transpiler/common/libraries.d.ts +29 -0
- package/dist/types/transpiler/common/parseErrors.d.ts +38 -0
- package/dist/types/transpiler/common/passes/ScopeAnalysis.d.ts +158 -0
- package/dist/types/transpiler/common/passes/TypeRules.d.ts +26 -0
- package/dist/types/transpiler/common/profiles/index.d.ts +96 -0
- package/dist/types/transpiler/common/version.d.ts +40 -0
- package/dist/types/transpiler/v1/ToJsVisitor.d.ts +720 -0
- package/dist/types/transpiler/v2/ToJsVisitor.d.ts +72 -0
- package/dist/types/transpiler/v3/ToJsVisitor.d.ts +87 -0
- package/dist/types/transpiler/v4/ToJsVisitor.d.ts +263 -0
- package/dist/types/transpiler/v5/ToJsVisitor.d.ts +1101 -0
- package/dist/types/transpiler/v6/ToJsVisitor.d.ts +237 -0
- package/dist/types/transpiler/v6/rules.d.ts +94 -0
- package/dist/types/utils/v2/common.d.ts +4 -0
- package/package.json +92 -4
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import type { Context } from "../context.js";
|
|
2
|
+
/**
|
|
3
|
+
* strategy.ts - Backtesting Engine Logic
|
|
4
|
+
*
|
|
5
|
+
* Implements: entry, exit, order, close, cancel, pending order matching,
|
|
6
|
+
* OCA groups (cancel / reduce / none), and strategy.risk.* circuit breakers.
|
|
7
|
+
*/
|
|
8
|
+
export declare const long = "long";
|
|
9
|
+
export declare const short = "short";
|
|
10
|
+
/**
|
|
11
|
+
* strategy.commission.* — how `commission_value` is interpreted.
|
|
12
|
+
*
|
|
13
|
+
* strategy("X", commission_type=strategy.commission.percent,
|
|
14
|
+
* commission_value=0.1)
|
|
15
|
+
*
|
|
16
|
+
* Nested under `strategy`, not a top-level `commission` namespace — that is
|
|
17
|
+
* where Pine puts it, and a top-level constant would leave
|
|
18
|
+
* `strategy.commission.percent` undefined at runtime.
|
|
19
|
+
*/
|
|
20
|
+
export declare const commission: {
|
|
21
|
+
/** A percentage of the position's cash value. */
|
|
22
|
+
percent: string;
|
|
23
|
+
/** A fixed amount per contract/share filled. */
|
|
24
|
+
cash_per_contract: string;
|
|
25
|
+
/** A fixed amount per order, regardless of size. */
|
|
26
|
+
cash_per_order: string;
|
|
27
|
+
};
|
|
28
|
+
export declare const direction: {
|
|
29
|
+
long: string;
|
|
30
|
+
short: string;
|
|
31
|
+
};
|
|
32
|
+
export declare const oca: {
|
|
33
|
+
cancel: string;
|
|
34
|
+
reduce: string;
|
|
35
|
+
none: string;
|
|
36
|
+
};
|
|
37
|
+
export interface PendingExit {
|
|
38
|
+
id: string;
|
|
39
|
+
from_entry: string;
|
|
40
|
+
qty: number;
|
|
41
|
+
qty_percent: number;
|
|
42
|
+
/** Profit target, in PRICE. */
|
|
43
|
+
limit: number;
|
|
44
|
+
/** Stop loss, in PRICE. */
|
|
45
|
+
stop: number;
|
|
46
|
+
/** Profit target, in TICKS from the entry. */
|
|
47
|
+
profit: number;
|
|
48
|
+
/** Stop loss, in TICKS from the entry. */
|
|
49
|
+
loss: number;
|
|
50
|
+
/** Trailing-stop activation level, in PRICE. */
|
|
51
|
+
trail_price: number;
|
|
52
|
+
/** Trailing-stop activation offset, in TICKS from the entry. */
|
|
53
|
+
trail_points: number;
|
|
54
|
+
/** How far behind the extreme the trailing stop follows, in TICKS. */
|
|
55
|
+
trail_offset: number;
|
|
56
|
+
/** The best price seen since the trail armed, or NaN while it has not. */
|
|
57
|
+
trail_peak: number;
|
|
58
|
+
/** The bar this order was first registered on. See `livesYet`. */
|
|
59
|
+
placedBar: number;
|
|
60
|
+
oca_name: string;
|
|
61
|
+
/** `comment`, and the three that replace it by how the exit filled. */
|
|
62
|
+
comment?: string;
|
|
63
|
+
comment_profit?: string;
|
|
64
|
+
comment_loss?: string;
|
|
65
|
+
comment_trailing?: string;
|
|
66
|
+
/**
|
|
67
|
+
* One unit per TRADE the exit applies to (the trades `from_entry` names, or
|
|
68
|
+
* every trade): its own price to measure relative levels from, its own
|
|
69
|
+
* trailing high-water mark, and whether it has filled. A script re-issues the
|
|
70
|
+
* same `strategy.exit` every bar, and the units survive that. A trade filled
|
|
71
|
+
* after the last call has no unit until the next call (or, for an entry
|
|
72
|
+
* that was pending at the call, `arms`).
|
|
73
|
+
*/
|
|
74
|
+
units?: ExitUnit[];
|
|
75
|
+
/** Entry ids that had an order pending when the exit was called, and the bar of that first call. */
|
|
76
|
+
arms?: Record<string, number>;
|
|
77
|
+
}
|
|
78
|
+
/** One trade's share of a `strategy.exit`; see `PendingExit.units`. */
|
|
79
|
+
export interface ExitUnit {
|
|
80
|
+
/** `OpenEntry.uid` of the trade. */
|
|
81
|
+
uid: string;
|
|
82
|
+
/** The trade's entry id: what `from_entry` and the id ledger speak of. */
|
|
83
|
+
id: string;
|
|
84
|
+
/** The trade's fill price: relative levels (`profit`, `loss`, `trail_points`) are measured from it. */
|
|
85
|
+
basis: number;
|
|
86
|
+
/** What the trade opened with: a `qty_percent` is a share of it. */
|
|
87
|
+
opened: number;
|
|
88
|
+
/** The bar the unit was created on; it is live from the next. */
|
|
89
|
+
placedBar: number;
|
|
90
|
+
trail_peak: number;
|
|
91
|
+
filled: boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface PendingEntry {
|
|
94
|
+
id: string;
|
|
95
|
+
dir: string;
|
|
96
|
+
qty: number;
|
|
97
|
+
limit: number;
|
|
98
|
+
stop: number;
|
|
99
|
+
/** The bar this order was first registered on. See `livesYet`. */
|
|
100
|
+
placedBar: number;
|
|
101
|
+
oca_name: string;
|
|
102
|
+
oca_type: string;
|
|
103
|
+
/** Placed by `strategy.order`, which `pyramiding` does not bind. */
|
|
104
|
+
exempt?: boolean;
|
|
105
|
+
}
|
|
106
|
+
export interface RiskState {
|
|
107
|
+
max_intraday_loss: number;
|
|
108
|
+
max_intraday_loss_type: string;
|
|
109
|
+
max_intraday_filled_orders: number;
|
|
110
|
+
max_drawdown: number;
|
|
111
|
+
max_drawdown_type: string;
|
|
112
|
+
max_cons_loss_days: number;
|
|
113
|
+
max_position_size: number;
|
|
114
|
+
allow_entry_in: string;
|
|
115
|
+
start_equity: number;
|
|
116
|
+
peak_equity: number;
|
|
117
|
+
last_day: number;
|
|
118
|
+
daily_filled_orders: number;
|
|
119
|
+
cons_loss_days: number;
|
|
120
|
+
prev_day_equity: number;
|
|
121
|
+
last_settled_day: number;
|
|
122
|
+
is_halted: boolean;
|
|
123
|
+
}
|
|
124
|
+
export declare const risk: {
|
|
125
|
+
max_intraday_loss: (ctx: Context, value: any, type?: string) => void;
|
|
126
|
+
max_intraday_filled_orders: (ctx: Context, count: any) => void;
|
|
127
|
+
max_drawdown: (ctx: Context, value: any, type?: string) => void;
|
|
128
|
+
max_cons_loss_days: (ctx: Context, count: any) => void;
|
|
129
|
+
max_position_size: (ctx: Context, size: any) => void;
|
|
130
|
+
allow_entry_in: (ctx: Context, dir: string) => void;
|
|
131
|
+
};
|
|
132
|
+
export declare function order(ctx: Context, id: string, dir: string, qty?: any, limit?: any, stop?: any, oca_name?: string, oca_type?: string, comment?: string, when?: any, alert_message?: string): void;
|
|
133
|
+
export declare function entry(ctx: Context, id: string, direction: string, qty?: any, limit?: any, stop?: any, oca_name?: string, oca_type?: string, comment?: string, when?: any, alert_message?: string): any;
|
|
134
|
+
export declare function close(ctx: Context, id: string, when?: any, comment?: string, qty?: any, qty_percent?: any, alert_message?: string, immediately?: any, disable_alert?: any): any;
|
|
135
|
+
export declare function close_all(ctx: Context, comment?: string, when?: any, alert_message?: string, immediately?: any, disable_alert?: any): any;
|
|
136
|
+
export declare function cancel(ctx: Context, id: string, when?: any): void;
|
|
137
|
+
export declare function cancel_all(ctx: Context): void;
|
|
138
|
+
export declare function exit(ctx: Context, id: string, from_entry?: string, qty?: any, qty_percent?: any, profit?: any, limit?: any, loss?: any, stop?: any, trail_price?: any, trail_points?: any, trail_offset?: any, oca_name?: string, comment?: string, when?: any, alert_message?: string, comment_profit?: string, comment_loss?: string, comment_trailing?: string): void;
|
|
139
|
+
export declare function processPendingOrders(ctx: Context, high: number, low: number): void;
|
|
140
|
+
export interface MarketOrder {
|
|
141
|
+
kind: "entry" | "close";
|
|
142
|
+
id: string;
|
|
143
|
+
direction?: string;
|
|
144
|
+
qty?: number;
|
|
145
|
+
comment?: string;
|
|
146
|
+
/** For a close: the entry it closes, or absent for the whole position. */
|
|
147
|
+
entry?: string;
|
|
148
|
+
/** For a close: `qty` / `qty_percent`, which limit how much of that entry goes. */
|
|
149
|
+
qty_percent?: number;
|
|
150
|
+
/** For an entry placed by `strategy.order`, which `pyramiding` does not bind. */
|
|
151
|
+
exempt?: boolean;
|
|
152
|
+
/** For an entry: the close of the bar that placed it, which sizes it (see `Broker.sizesAtOrderPrice`). */
|
|
153
|
+
placedClose?: number;
|
|
154
|
+
/** For a close placed with `immediately`: it fills at the close of this bar, once the script has run. */
|
|
155
|
+
atClose?: boolean;
|
|
156
|
+
}
|
|
157
|
+
/** @getter */
|
|
158
|
+
export declare function position_size(ctx: Context): number;
|
|
159
|
+
/** @getter */
|
|
160
|
+
export declare function opentrades(ctx: Context): number;
|
|
161
|
+
/** @getter */
|
|
162
|
+
export declare function max_drawdown(ctx: Context): number;
|
|
163
|
+
/** @getter */
|
|
164
|
+
export declare function max_drawdown_percent(ctx: Context): number;
|
|
165
|
+
/** @getter */
|
|
166
|
+
export declare function max_runup(ctx: Context): number;
|
|
167
|
+
/** @getter */
|
|
168
|
+
export declare function max_runup_percent(ctx: Context): number;
|
|
169
|
+
/**
|
|
170
|
+
* Converts between the strategy's account currency and the symbol's. One
|
|
171
|
+
* currency runs here, so a value converts to itself.
|
|
172
|
+
*/
|
|
173
|
+
export declare function convert_to_symbol(value: any): number;
|
|
174
|
+
export declare function convert_to_account(value: any): number;
|
|
175
|
+
/**
|
|
176
|
+
* `strategy.default_entry_qty(fill_price)` — the quantity a `strategy.entry`
|
|
177
|
+
* with no `qty` would take at that price, by the script's default_qty_type.
|
|
178
|
+
*/
|
|
179
|
+
export declare function default_entry_qty(ctx: Context, fill_price: any): number;
|
|
180
|
+
/**
|
|
181
|
+
* `strategy.margin_liquidation_price` — where the open position would be
|
|
182
|
+
* margin-called: the price at which equity falls to the margin it requires,
|
|
183
|
+
*
|
|
184
|
+
* cash + (price - entry) * size = |size| * price * margin
|
|
185
|
+
*
|
|
186
|
+
* solved for price. `na` when flat, when the side's margin is 0, and for a
|
|
187
|
+
* long at 100% margin, which no price can call. TradingView's log has na on
|
|
188
|
+
* every long and 82588.14 for a 1.209 short entered at 82387.95.
|
|
189
|
+
*
|
|
190
|
+
* @getter
|
|
191
|
+
*/
|
|
192
|
+
export declare function margin_liquidation_price(ctx: Context): number;
|
|
193
|
+
/** @getter */
|
|
194
|
+
export declare function equity(ctx: Context): number;
|
|
195
|
+
/**
|
|
196
|
+
* `strategy.position_avg_price` — the average entry price of the OPEN position.
|
|
197
|
+
*
|
|
198
|
+
* `na` while flat rather than 0: a script that plots it should draw nothing
|
|
199
|
+
* between trades, and zero would draw a line at the bottom of the chart.
|
|
200
|
+
*
|
|
201
|
+
* @getter
|
|
202
|
+
*/
|
|
203
|
+
export declare function position_avg_price(ctx: Context): number;
|
|
204
|
+
/**
|
|
205
|
+
* `strategy.closedtrades` — how many trades have been closed.
|
|
206
|
+
*
|
|
207
|
+
* Also the root of the `strategy.closedtrades.*` accessors, which live in
|
|
208
|
+
* ./trades.ts; see the note there for why the two cannot share a file.
|
|
209
|
+
*
|
|
210
|
+
* @getter
|
|
211
|
+
*/
|
|
212
|
+
export declare function closedtrades(ctx: Context): number;
|
|
213
|
+
/**
|
|
214
|
+
* `strategy.netprofit` — total REALISED profit, in the strategy's currency.
|
|
215
|
+
*
|
|
216
|
+
* Realised only: an open position's paper gain is `strategy.openprofit`, and
|
|
217
|
+
* the two together are what `strategy.equity` reports. Summed from the closed
|
|
218
|
+
* trades rather than tracked incrementally, so it cannot drift from them.
|
|
219
|
+
*
|
|
220
|
+
* @getter
|
|
221
|
+
*/
|
|
222
|
+
export declare function netprofit(ctx: Context): number;
|
|
223
|
+
/**
|
|
224
|
+
* `strategy.openprofit` — the UNREALISED profit of the open position.
|
|
225
|
+
*
|
|
226
|
+
* @getter
|
|
227
|
+
*/
|
|
228
|
+
export declare function openprofit(ctx: Context): number;
|
|
229
|
+
/**
|
|
230
|
+
* `strategy.grossprofit` and `strategy.grossloss` — the two halves of
|
|
231
|
+
* `netprofit`, both reported as POSITIVE numbers.
|
|
232
|
+
*
|
|
233
|
+
* @getter
|
|
234
|
+
*/
|
|
235
|
+
export declare function grossprofit(ctx: Context): number;
|
|
236
|
+
/** @getter */
|
|
237
|
+
export declare function grossloss(ctx: Context): number;
|
|
238
|
+
/**
|
|
239
|
+
* `strategy.initial_capital` — the equity the strategy started with.
|
|
240
|
+
*
|
|
241
|
+
* @getter
|
|
242
|
+
*/
|
|
243
|
+
export declare function initial_capital(ctx: Context): number;
|
|
244
|
+
/**
|
|
245
|
+
* `strategy.wintrades` / `strategy.losstrades` / `strategy.eventrades` — how
|
|
246
|
+
* the closed trades came out.
|
|
247
|
+
*
|
|
248
|
+
* A trade that broke exactly even is neither a win nor a loss, which is why
|
|
249
|
+
* there are three and not two: `wintrades + losstrades` does NOT have to equal
|
|
250
|
+
* `closedtrades`, and a script that assumes it does misreports its win rate.
|
|
251
|
+
*
|
|
252
|
+
* @getter
|
|
253
|
+
*/
|
|
254
|
+
export declare function wintrades(ctx: Context): number;
|
|
255
|
+
/** @getter */
|
|
256
|
+
export declare function losstrades(ctx: Context): number;
|
|
257
|
+
/** @getter */
|
|
258
|
+
export declare function eventrades(ctx: Context): number;
|
|
259
|
+
/**
|
|
260
|
+
* `strategy.avg_winning_trade` / `strategy.avg_losing_trade` — the mean result
|
|
261
|
+
* of the winners and of the losers, both as POSITIVE amounts.
|
|
262
|
+
*
|
|
263
|
+
* `na` when there are none of that kind, not 0: a strategy that has never lost
|
|
264
|
+
* has no average loss, and reporting zero would make a profit factor infinite
|
|
265
|
+
* in one direction and meaningless in the other.
|
|
266
|
+
*
|
|
267
|
+
* @getter
|
|
268
|
+
*/
|
|
269
|
+
export declare function avg_winning_trade(ctx: Context): number;
|
|
270
|
+
/** @getter */
|
|
271
|
+
export declare function avg_losing_trade(ctx: Context): number;
|
|
272
|
+
/**
|
|
273
|
+
* `strategy.avg_trade_percent` — the mean of each closed trade's result as a
|
|
274
|
+
* percentage of what it cost to enter (entry price × size).
|
|
275
|
+
* @getter
|
|
276
|
+
*/
|
|
277
|
+
export declare function avg_trade_percent(ctx: Context): number;
|
|
278
|
+
/**
|
|
279
|
+
* `strategy.openprofit_percent` — the open position's unrealised result as a
|
|
280
|
+
* percentage of the initial capital, as `netprofit_percent` is of realised.
|
|
281
|
+
* @getter
|
|
282
|
+
*/
|
|
283
|
+
export declare function openprofit_percent(ctx: Context): number;
|
|
284
|
+
/** `strategy.avg_trade` — the mean result of ALL closed trades, signed. @getter */
|
|
285
|
+
export declare function avg_trade(ctx: Context): number;
|
|
286
|
+
/**
|
|
287
|
+
* `strategy.netprofit_percent` — realised profit as a percentage of the
|
|
288
|
+
* starting equity.
|
|
289
|
+
*
|
|
290
|
+
* @getter
|
|
291
|
+
*/
|
|
292
|
+
export declare function netprofit_percent(ctx: Context): number;
|
|
293
|
+
/** @getter */
|
|
294
|
+
export declare function grossprofit_percent(ctx: Context): number;
|
|
295
|
+
/** @getter */
|
|
296
|
+
export declare function grossloss_percent(ctx: Context): number;
|
|
297
|
+
/**
|
|
298
|
+
* `strategy.account_currency` — the currency the strategy's results are in.
|
|
299
|
+
*
|
|
300
|
+
* Set by `strategy(..., currency = ...)`, and `currency.NONE` — the empty
|
|
301
|
+
* string — when the script did not ask, which means the symbol's own currency.
|
|
302
|
+
* A script pairs it with `request.currency_rate(syminfo.currency,
|
|
303
|
+
* strategy.account_currency)` to convert position values.
|
|
304
|
+
*
|
|
305
|
+
* @getter
|
|
306
|
+
*/
|
|
307
|
+
export declare function account_currency(ctx: Context): string;
|
|
308
|
+
/** Size orders in contracts/shares — the default. */
|
|
309
|
+
export declare const fixed = "strategy.fixed";
|
|
310
|
+
/** Size orders as an amount of CASH in the strategy's currency. */
|
|
311
|
+
export declare const cash = "strategy.cash";
|
|
312
|
+
/** Size orders as a PERCENTAGE of available equity. */
|
|
313
|
+
export declare const percent_of_equity = "strategy.percent_of_equity";
|
|
314
|
+
export declare const __IS_NAMESPACE__ = true;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `syminfo.*` — what a script can ask about its instrument.
|
|
3
|
+
*
|
|
4
|
+
* The namespace arrived at v4 (§3a of the migration guide), which moved the
|
|
5
|
+
* v1–v3 flat `ticker` and `tickerid` into it. Those two already live in
|
|
6
|
+
* ./chart.ts and ./ui.ts and are aliased by the rename table; this file adds the
|
|
7
|
+
* TEN members that have no earlier spelling.
|
|
8
|
+
*
|
|
9
|
+
* Descriptions are quoted from the manual's Chart information page:
|
|
10
|
+
*
|
|
11
|
+
* basecurrency "a string representing the instrument's base currency if the
|
|
12
|
+
* current symbol refers to a Forex pair, a cryptocurrency
|
|
13
|
+
* pair, or a derivative instrument based on a currency pair"
|
|
14
|
+
* currency "the currency of the instrument's quoted prices, or "NONE"
|
|
15
|
+
* if the dataset's values do not represent currency amounts"
|
|
16
|
+
* description "the description or extended name of the current instrument"
|
|
17
|
+
* mintick "the dataset's minimum tick size, i.e., the smallest
|
|
18
|
+
* increment by which the instrument's recorded prices change"
|
|
19
|
+
* pointvalue "the instrument's point value, which represents a multiplier
|
|
20
|
+
* of the instrument's price for determining the value of a
|
|
21
|
+
* single contract"
|
|
22
|
+
* prefix "the symbol's broker/exchange identifier"
|
|
23
|
+
* root "the instrument's root code if the symbol refers to a futures
|
|
24
|
+
* contract ... Otherwise, it stores the same value as
|
|
25
|
+
* syminfo.ticker"
|
|
26
|
+
* session "the dataset's session setting"
|
|
27
|
+
* timezone "the dataset's exchange time zone in the IANA time zone
|
|
28
|
+
* database format"
|
|
29
|
+
* type "the instrument's type. Possible values include "stock",
|
|
30
|
+
* "futures", "index", "forex", "crypto", "fund", "dr", "cfd",
|
|
31
|
+
* "bond", "warrant", "structured", and "right""
|
|
32
|
+
*
|
|
33
|
+
* ── Why every one of these is a getter over the Context ─────────────────────
|
|
34
|
+
*
|
|
35
|
+
* None is derivable from a bar. A CSV of prices does not record which exchange
|
|
36
|
+
* listed them or what currency they are in, so the HOST declares them — see
|
|
37
|
+
* `Context.provideSymbolInfo`, which also states each default.
|
|
38
|
+
*
|
|
39
|
+
* ── Why the absence of these was worse than an error ────────────────────────
|
|
40
|
+
*
|
|
41
|
+
* `syminfo` is a namespace the engine already had, and the emitter's namespace
|
|
42
|
+
* check asks only whether the ROOT exists — deliberately, since asserting
|
|
43
|
+
* registry completeness would reject a script for a member the engine simply
|
|
44
|
+
* has not got round to. So `syminfo.mintick` compiled, read `undefined`, and
|
|
45
|
+
* arithmetic on it produced `NaN` on every bar with no diagnostic anywhere.
|
|
46
|
+
* Twelve of TradingView's own v5 examples use it.
|
|
47
|
+
*
|
|
48
|
+
* v4+, which this file does not enforce: the registry split in ./index.ts keeps
|
|
49
|
+
* the namespace out of the v1–v3 view.
|
|
50
|
+
*/
|
|
51
|
+
import { Context } from "../context.js";
|
|
52
|
+
export declare const syminfo: {
|
|
53
|
+
/**
|
|
54
|
+
* The dataset's symbol WITHOUT the exchange prefix — "AAPL".
|
|
55
|
+
*
|
|
56
|
+
* v4's spelling of the v1–v3 `ticker` variable, and implemented here rather
|
|
57
|
+
* than aliased to it so that it stays a sibling of `prefix`: the two are one
|
|
58
|
+
* split of one string.
|
|
59
|
+
* @getter
|
|
60
|
+
*/
|
|
61
|
+
ticker: (ctx: Context) => string;
|
|
62
|
+
/**
|
|
63
|
+
* The full ticker identifier — "NASDAQ:AAPL".
|
|
64
|
+
*
|
|
65
|
+
* ── The conflation this ends ────────────────────────────────────────────
|
|
66
|
+
*
|
|
67
|
+
* Pine keeps FUNCTIONS and VARIABLES in separate namespaces, so v1–v4 spell
|
|
68
|
+
* two different things `tickerid`:
|
|
69
|
+
*
|
|
70
|
+
* tickerid the current chart's ticker id (a VARIABLE)
|
|
71
|
+
* tickerid(prefix, ticker) builds one from its parts (a FUNCTION)
|
|
72
|
+
*
|
|
73
|
+
* v4 renamed only the variable — "The `ticker` and `tickerid` variables are
|
|
74
|
+
* renamed to `syminfo.ticker` and `syminfo.tickerid` respectively" — and v5
|
|
75
|
+
* renamed only the function, to `ticker.new`. This engine has one registry
|
|
76
|
+
* key per name, so it had aliased `syminfo.tickerid` to the FUNCTION: 89
|
|
77
|
+
* uses across TradingView's own v5 examples each read a function object
|
|
78
|
+
* instead of a string, silently.
|
|
79
|
+
* @getter
|
|
80
|
+
*/
|
|
81
|
+
tickerid: (ctx: Context) => string;
|
|
82
|
+
/**
|
|
83
|
+
* The instrument's base currency — the LEFT half of a pair.
|
|
84
|
+
* @getter
|
|
85
|
+
*/
|
|
86
|
+
basecurrency: (ctx: Context) => string;
|
|
87
|
+
/**
|
|
88
|
+
* The currency the instrument's prices are quoted in.
|
|
89
|
+
* @getter
|
|
90
|
+
*/
|
|
91
|
+
currency: (ctx: Context) => string;
|
|
92
|
+
/**
|
|
93
|
+
* The instrument's description or extended name.
|
|
94
|
+
* @getter
|
|
95
|
+
*/
|
|
96
|
+
description: (ctx: Context) => string;
|
|
97
|
+
/**
|
|
98
|
+
* The smallest increment by which prices change.
|
|
99
|
+
* @getter
|
|
100
|
+
*/
|
|
101
|
+
mintick: (ctx: Context) => number;
|
|
102
|
+
/**
|
|
103
|
+
* The price multiplier for one contract.
|
|
104
|
+
* @getter
|
|
105
|
+
*/
|
|
106
|
+
pointvalue: (ctx: Context) => number;
|
|
107
|
+
/**
|
|
108
|
+
* The broker/exchange identifier — "NASDAQ" for "NASDAQ:AAPL".
|
|
109
|
+
*
|
|
110
|
+
* DERIVED from the ticker id rather than stored, so the two cannot
|
|
111
|
+
* disagree: they are two readings of one string.
|
|
112
|
+
* @getter
|
|
113
|
+
*/
|
|
114
|
+
prefix: (ctx: Context) => string;
|
|
115
|
+
/**
|
|
116
|
+
* The futures root code, or the plain ticker when the symbol is not one.
|
|
117
|
+
*
|
|
118
|
+
* The fallback is the manual's, not a convenience: "Otherwise, it stores
|
|
119
|
+
* the same value as syminfo.ticker."
|
|
120
|
+
* @getter
|
|
121
|
+
*/
|
|
122
|
+
root: (ctx: Context) => string;
|
|
123
|
+
/**
|
|
124
|
+
* The dataset's session setting — "regular" or "extended".
|
|
125
|
+
* @getter
|
|
126
|
+
*/
|
|
127
|
+
session: (ctx: Context) => string;
|
|
128
|
+
/**
|
|
129
|
+
* The exchange time zone, in IANA format.
|
|
130
|
+
*
|
|
131
|
+
* ⚠ This engine does not SHIFT anything by it. ./time.ts evaluates every
|
|
132
|
+
* calendar value in UTC and states the same divergence: a host that wants
|
|
133
|
+
* agreement supplies bar timestamps already shifted. Reporting the zone
|
|
134
|
+
* while ignoring it would be worse than reporting nothing, so it is said
|
|
135
|
+
* here too.
|
|
136
|
+
* @getter
|
|
137
|
+
*/
|
|
138
|
+
timezone: (ctx: Context) => string;
|
|
139
|
+
/**
|
|
140
|
+
* The instrument's type — "stock", "futures", "crypto", "forex", …
|
|
141
|
+
* @getter
|
|
142
|
+
*/
|
|
143
|
+
type: (ctx: Context) => string;
|
|
144
|
+
/**
|
|
145
|
+
* "The number of minimum price ticks in one point" side of the mintick:
|
|
146
|
+
* `syminfo.mintick = syminfo.minmove / syminfo.pricescale`. With the
|
|
147
|
+
* host stating only the tick, minmove is 1 and pricescale its inverse.
|
|
148
|
+
* @getter
|
|
149
|
+
*/
|
|
150
|
+
pricescale: (ctx: Context) => number;
|
|
151
|
+
/** @getter */
|
|
152
|
+
minmove: (ctx: Context) => number;
|
|
153
|
+
/**
|
|
154
|
+
* Company and contract facts a host may know and this engine does not:
|
|
155
|
+
* empty strings, and `na` for the expiry of a symbol that is not a future.
|
|
156
|
+
* @getter
|
|
157
|
+
*/
|
|
158
|
+
sector: (_ctx: Context) => string;
|
|
159
|
+
/** @getter */
|
|
160
|
+
industry: (_ctx: Context) => string;
|
|
161
|
+
/** @getter */
|
|
162
|
+
country: (_ctx: Context) => string;
|
|
163
|
+
/** @getter */
|
|
164
|
+
expiration_date: (_ctx: Context) => number;
|
|
165
|
+
/**
|
|
166
|
+
* What the symbol's volume counts: "base" (units of the base currency, as
|
|
167
|
+
* a crypto pair's does), "quote", "tick", or "n/a" when unspecified.
|
|
168
|
+
* @getter
|
|
169
|
+
*/
|
|
170
|
+
volumetype: (ctx: Context) => string;
|
|
171
|
+
/**
|
|
172
|
+
* Company fundamentals and analyst figures: data a host may hold and this
|
|
173
|
+
* engine does not, so `na`.
|
|
174
|
+
* @getter
|
|
175
|
+
*/
|
|
176
|
+
shares_outstanding_float: (_ctx: Context) => number;
|
|
177
|
+
/** @getter */
|
|
178
|
+
shares_outstanding_total: (_ctx: Context) => number;
|
|
179
|
+
/** @getter */
|
|
180
|
+
employees: (_ctx: Context) => number;
|
|
181
|
+
/** @getter */
|
|
182
|
+
shareholders: (_ctx: Context) => number;
|
|
183
|
+
/** @getter */
|
|
184
|
+
recommendations_buy: (_ctx: Context) => number;
|
|
185
|
+
/** @getter */
|
|
186
|
+
recommendations_buy_strong: (_ctx: Context) => number;
|
|
187
|
+
/** @getter */
|
|
188
|
+
recommendations_date: (_ctx: Context) => number;
|
|
189
|
+
/** @getter */
|
|
190
|
+
recommendations_hold: (_ctx: Context) => number;
|
|
191
|
+
/** @getter */
|
|
192
|
+
recommendations_sell: (_ctx: Context) => number;
|
|
193
|
+
/** @getter */
|
|
194
|
+
recommendations_sell_strong: (_ctx: Context) => number;
|
|
195
|
+
/** @getter */
|
|
196
|
+
recommendations_total: (_ctx: Context) => number;
|
|
197
|
+
/** @getter */
|
|
198
|
+
target_price_average: (_ctx: Context) => number;
|
|
199
|
+
/** @getter */
|
|
200
|
+
target_price_date: (_ctx: Context) => number;
|
|
201
|
+
/** @getter */
|
|
202
|
+
target_price_estimates: (_ctx: Context) => number;
|
|
203
|
+
/** @getter */
|
|
204
|
+
target_price_high: (_ctx: Context) => number;
|
|
205
|
+
/** @getter */
|
|
206
|
+
target_price_low: (_ctx: Context) => number;
|
|
207
|
+
/** @getter */
|
|
208
|
+
target_price_median: (_ctx: Context) => number;
|
|
209
|
+
};
|