oakscriptjs 0.7.2 → 0.8.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.
@@ -0,0 +1,6 @@
1
+ import type { Source } from '../types';
2
+ export declare function whenCalled<T extends number | boolean>(called: ArrayLike<boolean | number>, fn: (...values: number[][]) => ArrayLike<T>, ...sources: Source[]): Array<T | number>;
3
+ export declare function crossover(): (a: number, b: number) => boolean;
4
+ export declare function crossunder(): (a: number, b: number) => boolean;
5
+ export declare function cross(): (a: number, b: number) => boolean;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/callsite/index.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAWvC,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO,EACnD,MAAM,EAAE,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC,EACnC,EAAE,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAC3C,GAAG,OAAO,EAAE,MAAM,EAAE,GACnB,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,CASnB;AAeD,wBAAgB,SAAS,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAE7D;AAGD,wBAAgB,UAAU,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAE9D;AAGD,wBAAgB,KAAK,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAEzD"}
package/dist/index.cjs CHANGED
@@ -22,6 +22,10 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  BarData: () => BarData,
24
24
  LightweightChartsAdapter: () => LightweightChartsAdapter,
25
+ STRATEGY_CONSTANTS: () => STRATEGY_CONSTANTS,
26
+ STRATEGY_DEFAULTS: () => STRATEGY_DEFAULTS,
27
+ STRATEGY_NUMBER_VARIABLES: () => STRATEGY_NUMBER_VARIABLES,
28
+ STRATEGY_TEXT_VARIABLES: () => STRATEGY_TEXT_VARIABLES,
25
29
  Series: () => Series,
26
30
  SimpleInputAdapter: () => SimpleInputAdapter,
27
31
  VERSION: () => VERSION,
@@ -29,11 +33,13 @@ __export(index_exports, {
29
33
  abs: () => abs,
30
34
  alertcondition: () => alertcondition,
31
35
  array: () => array_exports,
36
+ at: () => at,
32
37
  atr: () => atr2,
33
38
  avg: () => avg,
34
39
  bb: () => bb2,
35
40
  box: () => box_exports,
36
41
  calculateZigZag: () => calculateZigZag,
42
+ callsite: () => callsite_exports,
37
43
  ceil: () => ceil,
38
44
  change: () => change2,
39
45
  chartPoint: () => chartpoint_exports,
@@ -44,9 +50,10 @@ __export(index_exports, {
44
50
  compare: () => compare_exports,
45
51
  cos: () => cos,
46
52
  createPlot: () => createPlot,
47
- crossover: () => crossover2,
48
- crossunder: () => crossunder2,
53
+ crossover: () => crossover3,
54
+ crossunder: () => crossunder3,
49
55
  cum: () => cum2,
56
+ div: () => div,
50
57
  ema: () => ema2,
51
58
  exp: () => exp,
52
59
  fixnan: () => fixnan,
@@ -56,6 +63,7 @@ __export(index_exports, {
56
63
  getHigh: () => getHigh,
57
64
  getLow: () => getLow,
58
65
  getOpen: () => getOpen,
66
+ getSource: () => getSource,
59
67
  getSourceSeries: () => getSourceSeries,
60
68
  hline: () => hline,
61
69
  indicator: () => indicator,
@@ -193,6 +201,40 @@ __export(ta_exports, {
193
201
  wvad: () => wvad,
194
202
  zigzag: () => zigzag
195
203
  });
204
+
205
+ // src/compare/index.ts
206
+ var compare_exports = {};
207
+ __export(compare_exports, {
208
+ EPSILON: () => EPSILON,
209
+ eq: () => eq,
210
+ ge: () => ge,
211
+ gt: () => gt,
212
+ le: () => le,
213
+ lt: () => lt,
214
+ ne: () => ne
215
+ });
216
+ var EPSILON = 1e-10;
217
+ var valid = (a, b2) => !Number.isNaN(a) && !Number.isNaN(b2);
218
+ function eq(a, b2) {
219
+ return valid(a, b2) && Math.abs(a - b2) <= EPSILON;
220
+ }
221
+ function ne(a, b2) {
222
+ return valid(a, b2) && Math.abs(a - b2) > EPSILON;
223
+ }
224
+ function lt(a, b2) {
225
+ return valid(a, b2) && b2 - a > EPSILON;
226
+ }
227
+ function le(a, b2) {
228
+ return valid(a, b2) && a - b2 <= EPSILON;
229
+ }
230
+ function gt(a, b2) {
231
+ return valid(a, b2) && a - b2 > EPSILON;
232
+ }
233
+ function ge(a, b2) {
234
+ return valid(a, b2) && b2 - a <= EPSILON;
235
+ }
236
+
237
+ // src/ta/index.ts
196
238
  function sma(source, length2) {
197
239
  const result = [];
198
240
  const len = Math.floor(length2);
@@ -384,7 +426,7 @@ function tr(handle_na = false, high, low, close) {
384
426
  const result = [];
385
427
  for (let i = 0; i < high.length; i++) {
386
428
  if (i === 0) {
387
- result.push(high[i] - low[i]);
429
+ result.push(handle_na ? high[i] - low[i] : NaN);
388
430
  } else {
389
431
  const prevClose = close[i - 1];
390
432
  if (isNaN(prevClose)) {
@@ -411,7 +453,7 @@ function atr(length2, high, low, close) {
411
453
  "ta.atr() requires high, low, and close series. Either pass them explicitly or use createContext({ chart: { high, low, close } }) for implicit data."
412
454
  );
413
455
  }
414
- const trueRange = tr(false, high, low, close);
456
+ const trueRange = tr(true, high, low, close);
415
457
  return rma(trueRange, length2);
416
458
  }
417
459
  function supertrend(factor, atrPeriod, high, low, close, wicks = false) {
@@ -888,48 +930,26 @@ function mfi(source, length2, volume) {
888
930
  "ta.mfi() requires volume series. Either pass it explicitly or use createContext({ chart: { ..., volume } }) for implicit data."
889
931
  );
890
932
  }
891
- const result = [];
892
- const changes = [NaN];
893
- for (let i = 1; i < source.length; i++) {
894
- changes.push(source[i] - source[i - 1]);
895
- }
896
- const positiveFlow = [];
897
- const negativeFlow = [];
933
+ const upperFlow = [];
934
+ const lowerFlow = [];
898
935
  for (let i = 0; i < source.length; i++) {
899
- if (i === 0 || isNaN(changes[i])) {
900
- positiveFlow.push(0);
901
- negativeFlow.push(0);
902
- } else if (changes[i] > 0) {
903
- positiveFlow.push(volume[i] * source[i]);
904
- negativeFlow.push(0);
905
- } else if (changes[i] < 0) {
906
- positiveFlow.push(0);
907
- negativeFlow.push(volume[i] * source[i]);
908
- } else {
909
- positiveFlow.push(0);
910
- negativeFlow.push(0);
911
- }
912
- }
913
- for (let i = 0; i < source.length; i++) {
914
- if (i < length2) {
915
- result.push(NaN);
916
- } else {
917
- let posSum = 0;
918
- let negSum = 0;
919
- for (let j = 0; j < length2; j++) {
920
- posSum += positiveFlow[i - j];
921
- negSum += negativeFlow[i - j];
922
- }
923
- if (negSum === 0) {
924
- result.push(100);
925
- } else {
926
- const moneyRatio = posSum / negSum;
927
- const mfiValue = 100 - 100 / (1 + moneyRatio);
928
- result.push(mfiValue);
929
- }
930
- }
931
- }
932
- return result;
936
+ const change3 = i === 0 ? NaN : source[i] - source[i - 1];
937
+ const flow = volume[i] * source[i];
938
+ upperFlow.push(le(change3, 0) ? 0 : flow);
939
+ lowerFlow.push(ge(change3, 0) ? 0 : flow);
940
+ }
941
+ const sumAt = (flow, i) => {
942
+ const values2 = lastValues(flow, i, Math.floor(length2));
943
+ return values2 ? values2.reduce((a, b2) => a + b2, 0) : NaN;
944
+ };
945
+ const upper2 = upperFlow.map((_, i) => sumAt(upperFlow, i));
946
+ const lower2 = lowerFlow.map((_, i) => sumAt(lowerFlow, i));
947
+ return upper2.map((u, i) => {
948
+ const l = lower2[i];
949
+ if (Number.isNaN(u) || Number.isNaN(l)) return NaN;
950
+ if (l === 0) return 100;
951
+ return 100 - 100 / (1 + u / l);
952
+ });
933
953
  }
934
954
  function hma(source, length2) {
935
955
  const halfLength = Math.floor(length2 / 2);
@@ -1093,50 +1113,32 @@ function dmi(diLength, adxSmoothing, high, low, close) {
1093
1113
  const len = Math.max(high.length, low.length, close.length);
1094
1114
  const plusDM = [];
1095
1115
  const minusDM = [];
1096
- const trueRangeValues = tr(false, high, low, close);
1097
- for (let i = 0; i < len; i++) {
1098
- if (i === 0) {
1099
- plusDM.push(0);
1100
- minusDM.push(0);
1101
- } else {
1102
- const upMove = high[i] - high[i - 1];
1103
- const downMove = low[i - 1] - low[i];
1104
- let plusDMVal = 0;
1105
- let minusDMVal = 0;
1106
- if (upMove > downMove && upMove > 0) {
1107
- plusDMVal = upMove;
1108
- }
1109
- if (downMove > upMove && downMove > 0) {
1110
- minusDMVal = downMove;
1111
- }
1112
- plusDM.push(plusDMVal);
1113
- minusDM.push(minusDMVal);
1114
- }
1115
- }
1116
- const smoothedPlusDM = rma(plusDM, diLength);
1117
- const smoothedMinusDM = rma(minusDM, diLength);
1118
- const smoothedTR = rma(trueRangeValues, diLength);
1119
- const plusDI = [];
1120
- const minusDI = [];
1121
- for (let i = 0; i < len; i++) {
1122
- if (smoothedTR[i] === 0) {
1123
- plusDI.push(0);
1124
- minusDI.push(0);
1125
- } else {
1126
- plusDI.push(smoothedPlusDM[i] / smoothedTR[i] * 100);
1127
- minusDI.push(smoothedMinusDM[i] / smoothedTR[i] * 100);
1128
- }
1129
- }
1130
- const dx = [];
1131
1116
  for (let i = 0; i < len; i++) {
1132
- const sum4 = plusDI[i] + minusDI[i];
1133
- if (sum4 === 0) {
1134
- dx.push(0);
1135
- } else {
1136
- dx.push(Math.abs(plusDI[i] - minusDI[i]) / sum4 * 100);
1137
- }
1138
- }
1139
- const adx = rma(dx, adxSmoothing);
1117
+ const up = i === 0 ? NaN : high[i] - high[i - 1];
1118
+ const down = i === 0 ? NaN : low[i - 1] - low[i];
1119
+ plusDM.push(Number.isNaN(up) ? NaN : gt(up, down) && gt(up, 0) ? up : 0);
1120
+ minusDM.push(Number.isNaN(down) ? NaN : gt(down, up) && gt(down, 0) ? down : 0);
1121
+ }
1122
+ const trur = rma(tr(false, high, low, close), diLength);
1123
+ const smoothedPlus = rma(plusDM, diLength);
1124
+ const smoothedMinus = rma(minusDM, diLength);
1125
+ const directional = (smoothed) => {
1126
+ let last2 = NaN;
1127
+ return smoothed.map((v, i) => {
1128
+ const t2 = trur[i];
1129
+ const value = t2 === 0 ? NaN : 100 * v / t2;
1130
+ if (!Number.isNaN(value)) last2 = value;
1131
+ return last2;
1132
+ });
1133
+ };
1134
+ const plusDI = directional(smoothedPlus);
1135
+ const minusDI = directional(smoothedMinus);
1136
+ const dx = plusDI.map((plus, i) => {
1137
+ const minus = minusDI[i];
1138
+ const sum4 = plus + minus;
1139
+ return Math.abs(plus - minus) / (eq(sum4, 0) ? 1 : sum4);
1140
+ });
1141
+ const adx = rma(dx, adxSmoothing).map((v) => 100 * v);
1140
1142
  return [plusDI, minusDI, adx];
1141
1143
  }
1142
1144
  function tsi(source, shortLength, longLength) {
@@ -1963,38 +1965,6 @@ __export(math_exports, {
1963
1965
  toradians: () => toradians
1964
1966
  });
1965
1967
 
1966
- // src/compare/index.ts
1967
- var compare_exports = {};
1968
- __export(compare_exports, {
1969
- EPSILON: () => EPSILON,
1970
- eq: () => eq,
1971
- ge: () => ge,
1972
- gt: () => gt,
1973
- le: () => le,
1974
- lt: () => lt,
1975
- ne: () => ne
1976
- });
1977
- var EPSILON = 1e-10;
1978
- var valid = (a, b2) => !Number.isNaN(a) && !Number.isNaN(b2);
1979
- function eq(a, b2) {
1980
- return valid(a, b2) && Math.abs(a - b2) <= EPSILON;
1981
- }
1982
- function ne(a, b2) {
1983
- return valid(a, b2) && Math.abs(a - b2) > EPSILON;
1984
- }
1985
- function lt(a, b2) {
1986
- return valid(a, b2) && b2 - a > EPSILON;
1987
- }
1988
- function le(a, b2) {
1989
- return valid(a, b2) && a - b2 <= EPSILON;
1990
- }
1991
- function gt(a, b2) {
1992
- return valid(a, b2) && a - b2 > EPSILON;
1993
- }
1994
- function ge(a, b2) {
1995
- return valid(a, b2) && b2 - a <= EPSILON;
1996
- }
1997
-
1998
1968
  // src/runtime/series.ts
1999
1969
  var BarData = class _BarData {
2000
1970
  _bars;
@@ -6242,6 +6212,44 @@ var format_none = 0;
6242
6212
  var format_bold = 1;
6243
6213
  var format_italic = 2;
6244
6214
 
6215
+ // src/callsite/index.ts
6216
+ var callsite_exports = {};
6217
+ __export(callsite_exports, {
6218
+ cross: () => cross2,
6219
+ crossover: () => crossover2,
6220
+ crossunder: () => crossunder2,
6221
+ whenCalled: () => whenCalled
6222
+ });
6223
+ function whenCalled(called, fn, ...sources) {
6224
+ const bars = [];
6225
+ for (let i = 0; i < called.length; i++) if (called[i]) bars.push(i);
6226
+ const result = fn(...sources.map((s) => bars.map((i) => s[i] ?? NaN)));
6227
+ const out = new Array(called.length).fill(NaN);
6228
+ bars.forEach((bar, k) => {
6229
+ out[bar] = result[k];
6230
+ });
6231
+ return out;
6232
+ }
6233
+ function twoSeriesSite(test) {
6234
+ let prevA = NaN;
6235
+ let prevB = NaN;
6236
+ return (a, b2) => {
6237
+ const result = test(a, b2, prevA, prevB);
6238
+ prevA = a;
6239
+ prevB = b2;
6240
+ return result;
6241
+ };
6242
+ }
6243
+ function crossover2() {
6244
+ return twoSeriesSite((a, b2, pa, pb) => a > b2 && pa <= pb);
6245
+ }
6246
+ function crossunder2() {
6247
+ return twoSeriesSite((a, b2, pa, pb) => a < b2 && pa >= pb);
6248
+ }
6249
+ function cross2() {
6250
+ return twoSeriesSite((a, b2, pa, pb) => a > b2 && pa <= pb || a < b2 && pa >= pb);
6251
+ }
6252
+
6245
6253
  // src/ta-series.ts
6246
6254
  var ta_series_exports = {};
6247
6255
  __export(ta_series_exports, {
@@ -6256,9 +6264,9 @@ __export(ta_series_exports, {
6256
6264
  cmo: () => cmo2,
6257
6265
  cog: () => cog2,
6258
6266
  correlation: () => correlation2,
6259
- cross: () => cross2,
6260
- crossover: () => crossover2,
6261
- crossunder: () => crossunder2,
6267
+ cross: () => cross3,
6268
+ crossover: () => crossover3,
6269
+ crossunder: () => crossunder3,
6262
6270
  cum: () => cum2,
6263
6271
  dev: () => dev2,
6264
6272
  dmi: () => dmi2,
@@ -6424,7 +6432,7 @@ function stoch2(source, high, low, length2) {
6424
6432
  const result = stoch(sourceValues, highValues, lowValues, length2);
6425
6433
  return Series.fromArray(bars, result);
6426
6434
  }
6427
- function crossover2(source1, source2) {
6435
+ function crossover3(source1, source2) {
6428
6436
  const bars = source1.bars;
6429
6437
  const vals1 = source1.toArray();
6430
6438
  const vals2 = typeof source2 === "number" ? Array(bars.length).fill(source2) : source2.toArray();
@@ -6432,7 +6440,7 @@ function crossover2(source1, source2) {
6432
6440
  const numResult = result.map((b2) => b2 ? 1 : 0);
6433
6441
  return Series.fromArray(bars, numResult);
6434
6442
  }
6435
- function crossunder2(source1, source2) {
6443
+ function crossunder3(source1, source2) {
6436
6444
  const bars = source1.bars;
6437
6445
  const vals1 = source1.toArray();
6438
6446
  const vals2 = typeof source2 === "number" ? Array(bars.length).fill(source2) : source2.toArray();
@@ -6440,7 +6448,7 @@ function crossunder2(source1, source2) {
6440
6448
  const numResult = result.map((b2) => b2 ? 1 : 0);
6441
6449
  return Series.fromArray(bars, numResult);
6442
6450
  }
6443
- function cross2(source1, source2) {
6451
+ function cross3(source1, source2) {
6444
6452
  const bars = source1.bars;
6445
6453
  const vals1 = source1.toArray();
6446
6454
  const vals2 = typeof source2 === "number" ? Array(bars.length).fill(source2) : source2.toArray();
@@ -6759,9 +6767,9 @@ var ta = {
6759
6767
  atr: atr2,
6760
6768
  tr: tr2,
6761
6769
  stoch: stoch2,
6762
- crossover: crossover2,
6763
- crossunder: crossunder2,
6764
- cross: cross2,
6770
+ crossover: crossover3,
6771
+ crossunder: crossunder3,
6772
+ cross: cross3,
6765
6773
  change: change2,
6766
6774
  mom: mom2,
6767
6775
  roc: roc2,
@@ -6837,6 +6845,16 @@ function fixnan(source) {
6837
6845
  return seen ? last2 : v;
6838
6846
  });
6839
6847
  }
6848
+ function at(source, i, offset = 0) {
6849
+ if (offset < 0) {
6850
+ throw new RangeError(`at(): the offset must be >= 0 (got ${offset}); a negative offset reads a later bar.`);
6851
+ }
6852
+ const j = i - offset;
6853
+ return j >= 0 && j < source.length ? source[j] ?? NaN : NaN;
6854
+ }
6855
+ function div(a, b2) {
6856
+ return b2 === 0 ? NaN : a / b2;
6857
+ }
6840
6858
  function ohlcFromBars(bars) {
6841
6859
  return {
6842
6860
  open: bars.map((b2) => b2.open),
@@ -6857,6 +6875,50 @@ function getLow(ohlc) {
6857
6875
  function getOpen(ohlc) {
6858
6876
  return ohlc.open;
6859
6877
  }
6878
+ function getSource(data, source = "close") {
6879
+ const isOHLC = "open" in data && Array.isArray(data.open);
6880
+ if (isOHLC) {
6881
+ const ohlc = data;
6882
+ switch (source) {
6883
+ case "close":
6884
+ return ohlc.close;
6885
+ case "open":
6886
+ return ohlc.open;
6887
+ case "high":
6888
+ return ohlc.high;
6889
+ case "low":
6890
+ return ohlc.low;
6891
+ case "hl2":
6892
+ return ohlc.high.map((h, i) => (h + ohlc.low[i]) / 2);
6893
+ case "hlc3":
6894
+ return ohlc.high.map((h, i) => (h + ohlc.low[i] + ohlc.close[i]) / 3);
6895
+ case "ohlc4":
6896
+ return ohlc.open.map((o, i) => (o + ohlc.high[i] + ohlc.low[i] + ohlc.close[i]) / 4);
6897
+ case "hlcc4":
6898
+ return ohlc.high.map((h, i) => (h + ohlc.low[i] + ohlc.close[i] + ohlc.close[i]) / 4);
6899
+ }
6900
+ } else {
6901
+ const bars = data;
6902
+ switch (source) {
6903
+ case "close":
6904
+ return bars.map((b2) => b2.close);
6905
+ case "open":
6906
+ return bars.map((b2) => b2.open);
6907
+ case "high":
6908
+ return bars.map((b2) => b2.high);
6909
+ case "low":
6910
+ return bars.map((b2) => b2.low);
6911
+ case "hl2":
6912
+ return bars.map((b2) => (b2.high + b2.low) / 2);
6913
+ case "hlc3":
6914
+ return bars.map((b2) => (b2.high + b2.low + b2.close) / 3);
6915
+ case "ohlc4":
6916
+ return bars.map((b2) => (b2.open + b2.high + b2.low + b2.close) / 4);
6917
+ case "hlcc4":
6918
+ return bars.map((b2) => (b2.high + b2.low + b2.close + b2.close) / 4);
6919
+ }
6920
+ }
6921
+ }
6860
6922
  function getSourceSeries(bars, source = "close") {
6861
6923
  const open = new Series(bars, (bar) => bar.open);
6862
6924
  const high = new Series(bars, (bar) => bar.high);
@@ -7656,6 +7718,72 @@ function getSourceData(ohlcv, sourceName) {
7656
7718
  }
7657
7719
  }
7658
7720
 
7721
+ // src/strategy/index.ts
7722
+ var STRATEGY_CONSTANTS = {
7723
+ long: "long",
7724
+ short: "short",
7725
+ fixed: "fixed",
7726
+ cash: "cash",
7727
+ percent_of_equity: "percent_of_equity",
7728
+ commission: { percent: "percent", cash_per_contract: "cash_per_contract", cash_per_order: "cash_per_order" },
7729
+ direction: { all: "all", long: "long", short: "short" },
7730
+ oca: { none: "none", cancel: "cancel", reduce: "reduce" }
7731
+ };
7732
+ var STRATEGY_DEFAULTS = {
7733
+ pyramiding: 0,
7734
+ calc_on_order_fills: false,
7735
+ calc_on_every_tick: false,
7736
+ backtest_fill_limits_assumption: 0,
7737
+ default_qty_type: "fixed",
7738
+ default_qty_value: 1,
7739
+ initial_capital: 1e6,
7740
+ slippage: 0,
7741
+ commission_type: "percent",
7742
+ commission_value: 0,
7743
+ process_orders_on_close: false,
7744
+ close_entries_rule: "FIFO",
7745
+ margin_long: 100,
7746
+ margin_short: 100,
7747
+ calc_bars_count: 0,
7748
+ risk_free_rate: 2,
7749
+ use_bar_magnifier: false,
7750
+ fill_orders_on_standard_ohlc: false
7751
+ };
7752
+ var STRATEGY_NUMBER_VARIABLES = [
7753
+ "position_size",
7754
+ "position_avg_price",
7755
+ "equity",
7756
+ "initial_capital",
7757
+ "netprofit",
7758
+ "netprofit_percent",
7759
+ "openprofit",
7760
+ "openprofit_percent",
7761
+ "grossprofit",
7762
+ "grossprofit_percent",
7763
+ "grossloss",
7764
+ "grossloss_percent",
7765
+ "opentrades",
7766
+ "closedtrades",
7767
+ "wintrades",
7768
+ "losstrades",
7769
+ "eventrades",
7770
+ "avg_trade",
7771
+ "avg_trade_percent",
7772
+ "avg_winning_trade",
7773
+ "avg_winning_trade_percent",
7774
+ "avg_losing_trade",
7775
+ "avg_losing_trade_percent",
7776
+ "max_drawdown",
7777
+ "max_drawdown_percent",
7778
+ "max_runup",
7779
+ "max_runup_percent",
7780
+ "max_contracts_held_all",
7781
+ "max_contracts_held_long",
7782
+ "max_contracts_held_short",
7783
+ "margin_liquidation_price"
7784
+ ];
7785
+ var STRATEGY_TEXT_VARIABLES = ["position_entry_name", "account_currency"];
7786
+
7659
7787
  // src/runtime/adapters/LightweightChartsAdapter.ts
7660
7788
  var LightweightChartsAdapter = class {
7661
7789
  chart;
@@ -7864,7 +7992,7 @@ var SimpleInputAdapter = class {
7864
7992
  };
7865
7993
 
7866
7994
  // src/index.ts
7867
- var VERSION = "0.7.2";
7995
+ var VERSION = "0.8.0";
7868
7996
  var info2 = {
7869
7997
  name: "OakScriptJS",
7870
7998
  version: VERSION,
package/dist/index.d.ts CHANGED
@@ -17,7 +17,8 @@ import * as chartPoint from './chartpoint';
17
17
  import * as polyline from './polyline';
18
18
  import * as text from './text';
19
19
  import * as compare from './compare';
20
- export { taCore, math, array, map, str, color, time, timeframe, matrix, line, box, label, linefill, chartPoint, polyline, text, compare };
20
+ import * as callsite from './callsite';
21
+ export { taCore, math, array, map, str, color, time, timeframe, matrix, line, box, label, linefill, chartPoint, polyline, text, compare, callsite };
21
22
  export { Series, BarData } from './runtime/series';
22
23
  export type { SeriesExtractor } from './runtime/series';
23
24
  import * as ta from './ta-series';
@@ -26,7 +27,7 @@ export type { PlotOptions, HLineOptions, FillOptions, InputMetadata, PlotMetadat
26
27
  export { sma, ema, rsi, macd, bb, stdev, crossover, crossunder, change, tr, atr, cum, vwap } from './ta-series';
27
28
  export { abs, ceil, floor, round, max, min, avg, sum, sqrt, pow, exp, log, sin, cos, tan } from './math';
28
29
  export { rgb, from_hex as color_from_hex, new_color } from './color';
29
- export { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSourceSeries } from './utils';
30
+ export { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSource, getSourceSeries, at, div } from './utils';
30
31
  export * from './lib';
31
32
  export { isNA as na, nz, fixnan } from './utils';
32
33
  export { indicator, type IndicatorMetadataConfig, type InputDefinition, type IndicatorContext, type IndicatorInstance, type IndicatorConstructor, } from './indicator';
@@ -35,9 +36,11 @@ export { plot as plotHelper, createPlot, type Time, type TimeValuePair, type Plo
35
36
  export { setContext, clearContext, getContext, registerCalculate, recalculate, plot, hline, clearPlots, } from './runtime/runtime';
36
37
  export { input_int, input_float, input_bool, input_string, input_source, input_timeframe, input_session, input_time, } from './runtime/inputs';
37
38
  export type { OakScriptContext, ChartAdapter, InputAdapter, SeriesHandle, SeriesOptions, InputConfig, InputOptions, OhlcvData, PlotConfig, HLineConfig, FillConfig, } from './runtime/types';
39
+ export { STRATEGY_CONSTANTS, STRATEGY_DEFAULTS, STRATEGY_NUMBER_VARIABLES, STRATEGY_TEXT_VARIABLES, } from './strategy';
40
+ export type * from './strategy';
38
41
  export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter';
39
42
  export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter';
40
- export declare const VERSION = "0.7.2";
43
+ export declare const VERSION = "0.8.0";
41
44
  export declare const info: {
42
45
  name: string;
43
46
  version: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AAGjC,OAAO,KAAK,MAAM,MAAM,MAAM,CAAC;AAC/B,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC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