oakscriptjs 0.13.1 → 0.13.2
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/AGENTS.md +48 -0
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +3 -1
- package/skills/oakscript/SKILL.md +162 -0
- package/skills/oakscript/examples/ma-cross-strategy.js +57 -0
- package/skills/oakscript/examples/ma-cross.js +34 -0
- package/skills/oakscript/examples/macd-oscillator.js +29 -0
- package/skills/oakscript/examples/mtf-trend-filter.js +46 -0
- package/skills/oakscript/reference/errors.md +68 -0
- package/skills/oakscript/reference/pine-differences.md +84 -0
- package/skills/oakscript/reference/plotting.md +193 -0
- package/skills/oakscript/reference/script-structure.md +182 -0
- package/skills/oakscript/reference/strategies.md +140 -0
- package/skills/oakscript/reference/timeframes-symbols.md +93 -0
- package/src/index.ts +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Other timeframes and symbols
|
|
2
|
+
|
|
3
|
+
## request.security
|
|
4
|
+
|
|
5
|
+
`request.security(symbol, timeframe, expression, gaps?, lookahead?, ignore_invalid_symbol?)` runs `expression` on
|
|
6
|
+
the bars of `symbol` on `timeframe` and returns its values aligned on the chart bars (a Series).
|
|
7
|
+
|
|
8
|
+
- `symbol`: `""` or `syminfo.tickerid` for the chart symbol, a ticker id (`"NASDAQ:AAPL"`, from
|
|
9
|
+
`input.symbol`) for another one, `ticker.heikinashi(syminfo.tickerid)` for Heikin Ashi bars.
|
|
10
|
+
- `timeframe`: `"1"`, `"5"`, `"60"`, `"240"`, `"D"`, `"W"`, `"M"`, `"2D"`...; `""` is the chart timeframe.
|
|
11
|
+
- `expression`: a **function** that computes the series. Everything it needs on that timeframe is computed
|
|
12
|
+
inside it: `() => ta.ema(close, 20)`. A Series computed outside runs on the chart bars, and the call throws
|
|
13
|
+
"the expression returned a series computed on the chart bars".
|
|
14
|
+
- Return an array for several values (a Pine tuple): `const [h, l] = request.security("", "D", () => [high, low]);`
|
|
15
|
+
- Inputs and plain numbers from outside can be used inside (`() => ta.ema(close, length)`).
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
indicator("Daily levels", { overlay: true });
|
|
19
|
+
const length = input.int(20, "Daily EMA length", { minval: 1 });
|
|
20
|
+
const dailyEma = request.security("", "D", () => ta.ema(close, length));
|
|
21
|
+
const [prevHigh, prevLow] = request.security("", "D", () => [high.offset(1), low.offset(1)]);
|
|
22
|
+
plot(dailyEma, "Daily EMA", { color: color.orange, style: plot.style_stepline });
|
|
23
|
+
plot(prevHigh, "Previous day high", { color: color.green, style: plot.style_linebr });
|
|
24
|
+
plot(prevLow, "Previous day low", { color: color.red, style: plot.style_linebr });
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Lookahead and gaps
|
|
28
|
+
|
|
29
|
+
- `barmerge.lookahead_off` (default): a higher-timeframe value appears on the chart bar that completes its
|
|
30
|
+
period; before that, the bars show the previous period's value. This is the setting without future leak.
|
|
31
|
+
- `barmerge.lookahead_on`: the value of the period appears from its first chart bar. With a series that is not
|
|
32
|
+
offset (`close`, `ta.ema(close, 20)`) this reads the future on history bars: use it only with
|
|
33
|
+
`high.offset(1)`-style expressions (the previous period) or for display.
|
|
34
|
+
- `barmerge.gaps_on`: the value only on the bar where it appears, NaN elsewhere (use `plot.style_linebr`).
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
indicator("Weekly open", { overlay: true });
|
|
38
|
+
const weekOpen = request.security("", "W", () => open, barmerge.gaps_off, barmerge.lookahead_on);
|
|
39
|
+
plot(weekOpen, "Week open", { color: color.purple, style: plot.style_stepline });
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Other symbols
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
indicator("Relative strength", { overlay: false });
|
|
46
|
+
const other = input.symbol("NASDAQ:AAPL", "Compare with");
|
|
47
|
+
const otherClose = request.security(other, "", () => close);
|
|
48
|
+
const ratio = close.div(otherClose);
|
|
49
|
+
plot(ratio, "Ratio", { color: color.blue });
|
|
50
|
+
plot(ta.sma(ratio, 50), "Ratio SMA", { color: color.orange });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The library fetches nothing: the host gives the bars of the other symbol. An app loads them when the script asks
|
|
54
|
+
(the first run reports what it needs, the app loads it and runs again); in your own `executeScript` call, pass
|
|
55
|
+
`bars(symbol, timeframe)` and `symbolInfo(symbol)` in the chart context and catch `MissingSymbolDataError`
|
|
56
|
+
(`error.requests` lists the `{ symbol, timeframe }` to load). A symbol with no bars stops the script with
|
|
57
|
+
"Invalid symbol: X" (or gives NaN with `ignore_invalid_symbol = true`).
|
|
58
|
+
|
|
59
|
+
The values are merged by time: with lookahead off a chart bar shows the last bar of the other symbol that closed
|
|
60
|
+
at or before its own close.
|
|
61
|
+
|
|
62
|
+
### Lower timeframes
|
|
63
|
+
|
|
64
|
+
`request.security` on a timeframe below the chart's reads the lower-timeframe bars (given by the host as for
|
|
65
|
+
another symbol) and shows, per chart bar, the value on the last lower bar inside it.
|
|
66
|
+
`request.security_lower_tf(symbol, timeframe, expression)` returns, for each chart bar, an **array of numbers**:
|
|
67
|
+
the values on all the lower bars inside that bar (a plain `number[][]`, not a Series). Read it in a bar loop:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
indicator("Intrabar up volume", { overlay: false });
|
|
71
|
+
const vols = request.security_lower_tf("", "15", () => volume.mul(close.gt(open).iff(1, 0)));
|
|
72
|
+
const upVolume = eachBar((c) => vols[c.i].reduce((sum, v) => sum + v, 0));
|
|
73
|
+
plot(upVolume, "Up volume", { style: plot.style_columns, color: color.teal });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Timeframe values
|
|
77
|
+
|
|
78
|
+
- `timeframe.period` (`"60"`, `"1D"`...), `timeframe.multiplier`, `timeframe.isintraday`, `timeframe.isdaily`,
|
|
79
|
+
`timeframe.isweekly`, `timeframe.ismonthly`, `timeframe.isdwm`, `timeframe.isminutes`, `timeframe.isseconds`.
|
|
80
|
+
- `timeframe.change("D")`: 1 on the first chart bar of each new period.
|
|
81
|
+
- `timeframe.in_seconds(tf?)`, `timeframe.from_seconds(s)`.
|
|
82
|
+
- `input.timeframe("D", "Timeframe")` lets the user choose; `""` is the chart timeframe.
|
|
83
|
+
- `time("D")`, `time("240", "0930-1600")`: open time of the period of each bar, NaN outside the session.
|
|
84
|
+
|
|
85
|
+
A timeframe below the chart's with `request.security_lower_tf` and a higher one with `request.security` are the
|
|
86
|
+
normal cases; `request.security_lower_tf` on a higher timeframe throws.
|
|
87
|
+
|
|
88
|
+
## What the host must give
|
|
89
|
+
|
|
90
|
+
Session-aware values (`request.security` on another timeframe, `time()`, `timeframe.change`, `session.*`,
|
|
91
|
+
`ta.vwap` on an intraday chart) need the chart timeframe, the exchange time zone and the session. An app gives
|
|
92
|
+
them; a direct `executeScript` call passes `{ timeframe, timezone, session }` in the chart context
|
|
93
|
+
(`session: "24x7"` for a symbol that always trades, `"0930-1600"` for regular stock hours).
|
package/src/index.ts
CHANGED
|
@@ -224,7 +224,7 @@ export type { LightweightSeriesDefinitions } from './runtime/adapters/Lightweigh
|
|
|
224
224
|
export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
|
|
225
225
|
|
|
226
226
|
// Version
|
|
227
|
-
export const VERSION = '0.
|
|
227
|
+
export const VERSION = '0.13.2';
|
|
228
228
|
|
|
229
229
|
/**
|
|
230
230
|
* Library information
|