@pipsend/charts 2.0.1 → 2.2.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/README.md +70 -0
- package/dist/pipsend-charts.development.mjs +244 -3
- package/dist/pipsend-charts.production.mjs +2 -2
- package/dist/pipsend-charts.standalone.development.js +246 -2
- package/dist/pipsend-charts.standalone.development.mjs +244 -3
- package/dist/pipsend-charts.standalone.production.js +2 -2
- package/dist/pipsend-charts.standalone.production.mjs +2 -2
- package/dist/typings.d.ts +97 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* Pipsend Charts v2.0
|
|
3
|
+
* Pipsend Charts v2.2.0
|
|
4
4
|
* Copyright (c) 2026 Pipsend
|
|
5
5
|
* Licensed under MIT License
|
|
6
6
|
* Built on TradingView Lightweight Charts™ (Apache 2.0)
|
|
@@ -15916,6 +15916,85 @@
|
|
|
15916
15916
|
return volumes !== undefined && volumes.size > 0;
|
|
15917
15917
|
}
|
|
15918
15918
|
|
|
15919
|
+
const TRANSPARENT = 'rgba(0, 0, 0, 0)';
|
|
15920
|
+
/**
|
|
15921
|
+
* Take a series off the screen without hiding it.
|
|
15922
|
+
*
|
|
15923
|
+
* `visible: false` takes down everything hung off the series as well: its
|
|
15924
|
+
* price lines, primitives and price-axis label stop rendering. A transform
|
|
15925
|
+
* that only wants the bars themselves out of the way — Heikin Ashi drawing
|
|
15926
|
+
* over its source — needs the series to stay visible to the engine, so its
|
|
15927
|
+
* paint is made transparent instead and the last-value label and price line
|
|
15928
|
+
* are switched off. Custom series have no known colours; those fall back to
|
|
15929
|
+
* `visible: false`.
|
|
15930
|
+
*
|
|
15931
|
+
* @param series - Series to blank out.
|
|
15932
|
+
* @returns Puts back the options the series had when it was blanked.
|
|
15933
|
+
*/
|
|
15934
|
+
function hideSeriesPaint(series) {
|
|
15935
|
+
switch (series.seriesType()) {
|
|
15936
|
+
case 'Candlestick':
|
|
15937
|
+
return blank(series, {
|
|
15938
|
+
upColor: TRANSPARENT,
|
|
15939
|
+
downColor: TRANSPARENT,
|
|
15940
|
+
borderVisible: false,
|
|
15941
|
+
wickVisible: false,
|
|
15942
|
+
});
|
|
15943
|
+
case 'Bar':
|
|
15944
|
+
return blank(series, {
|
|
15945
|
+
upColor: TRANSPARENT,
|
|
15946
|
+
downColor: TRANSPARENT,
|
|
15947
|
+
});
|
|
15948
|
+
case 'Line':
|
|
15949
|
+
return blank(series, {
|
|
15950
|
+
color: TRANSPARENT,
|
|
15951
|
+
crosshairMarkerVisible: false,
|
|
15952
|
+
pointMarkersVisible: false,
|
|
15953
|
+
});
|
|
15954
|
+
case 'Area':
|
|
15955
|
+
return blank(series, {
|
|
15956
|
+
lineColor: TRANSPARENT,
|
|
15957
|
+
topColor: TRANSPARENT,
|
|
15958
|
+
bottomColor: TRANSPARENT,
|
|
15959
|
+
crosshairMarkerVisible: false,
|
|
15960
|
+
pointMarkersVisible: false,
|
|
15961
|
+
});
|
|
15962
|
+
case 'Baseline':
|
|
15963
|
+
return blank(series, {
|
|
15964
|
+
topLineColor: TRANSPARENT,
|
|
15965
|
+
topFillColor1: TRANSPARENT,
|
|
15966
|
+
topFillColor2: TRANSPARENT,
|
|
15967
|
+
bottomLineColor: TRANSPARENT,
|
|
15968
|
+
bottomFillColor1: TRANSPARENT,
|
|
15969
|
+
bottomFillColor2: TRANSPARENT,
|
|
15970
|
+
crosshairMarkerVisible: false,
|
|
15971
|
+
pointMarkersVisible: false,
|
|
15972
|
+
});
|
|
15973
|
+
case 'Histogram':
|
|
15974
|
+
return blank(series, {
|
|
15975
|
+
color: TRANSPARENT,
|
|
15976
|
+
});
|
|
15977
|
+
default:
|
|
15978
|
+
return blank(series, { visible: false });
|
|
15979
|
+
}
|
|
15980
|
+
}
|
|
15981
|
+
function blank(series, paint) {
|
|
15982
|
+
const patch = {
|
|
15983
|
+
...paint,
|
|
15984
|
+
lastValueVisible: false,
|
|
15985
|
+
priceLineVisible: false,
|
|
15986
|
+
};
|
|
15987
|
+
const before = series.options();
|
|
15988
|
+
const snapshot = {};
|
|
15989
|
+
for (const key of Object.keys(patch)) {
|
|
15990
|
+
snapshot[key] = before[key];
|
|
15991
|
+
}
|
|
15992
|
+
series.applyOptions(patch);
|
|
15993
|
+
return () => {
|
|
15994
|
+
series.applyOptions(snapshot);
|
|
15995
|
+
};
|
|
15996
|
+
}
|
|
15997
|
+
|
|
15919
15998
|
/**
|
|
15920
15999
|
* Pins a bounded indicator (RSI, Stochastic…) to a fixed price range.
|
|
15921
16000
|
*
|
|
@@ -17550,6 +17629,168 @@
|
|
|
17550
17629
|
};
|
|
17551
17630
|
}
|
|
17552
17631
|
|
|
17632
|
+
function isOhlc(bar) {
|
|
17633
|
+
return bar !== null
|
|
17634
|
+
&& bar !== undefined
|
|
17635
|
+
&& typeof bar.close === 'number';
|
|
17636
|
+
}
|
|
17637
|
+
/**
|
|
17638
|
+
* Turns raw OHLC bars into Heikin Ashi ones.
|
|
17639
|
+
*
|
|
17640
|
+
* Heikin Ashi is a price transform, not an overlay: each candle averages itself
|
|
17641
|
+
* with the one before it, which drops most of the single-bar noise and leaves
|
|
17642
|
+
* runs of same-coloured bodies while a trend holds.
|
|
17643
|
+
*
|
|
17644
|
+
* ```
|
|
17645
|
+
* close = (O + H + L + C) / 4
|
|
17646
|
+
* open = (previous open + previous close) / 2 // first bar: (O + C) / 2
|
|
17647
|
+
* high = max(H, open, close)
|
|
17648
|
+
* low = min(L, open, close)
|
|
17649
|
+
* ```
|
|
17650
|
+
*
|
|
17651
|
+
* Because every bar folds in the one before it, the result depends on where the
|
|
17652
|
+
* data starts: the same bar computed from a longer history differs slightly.
|
|
17653
|
+
* The difference decays over a few bars, so pass the whole series rather than a
|
|
17654
|
+
* recent window when you can.
|
|
17655
|
+
*
|
|
17656
|
+
* Whitespace items are passed through untouched, and do not advance the
|
|
17657
|
+
* running open/close — a gap in the data is not a bar.
|
|
17658
|
+
*
|
|
17659
|
+
* @param bars - Source bars, ordered oldest to newest.
|
|
17660
|
+
* @returns The transformed bars, one per input item.
|
|
17661
|
+
*/
|
|
17662
|
+
function calculateHeikinAshi(bars) {
|
|
17663
|
+
const result = [];
|
|
17664
|
+
let previousOpen = null;
|
|
17665
|
+
let previousClose = null;
|
|
17666
|
+
for (const bar of bars) {
|
|
17667
|
+
if (!isOhlc(bar)) {
|
|
17668
|
+
if (bar !== null && bar !== undefined) {
|
|
17669
|
+
result.push({ time: bar.time, customValues: bar.customValues });
|
|
17670
|
+
}
|
|
17671
|
+
continue;
|
|
17672
|
+
}
|
|
17673
|
+
const haClose = (bar.open + bar.high + bar.low + bar.close) / 4;
|
|
17674
|
+
const haOpen = previousOpen === null || previousClose === null
|
|
17675
|
+
? (bar.open + bar.close) / 2
|
|
17676
|
+
: (previousOpen + previousClose) / 2;
|
|
17677
|
+
result.push({
|
|
17678
|
+
time: bar.time,
|
|
17679
|
+
open: haOpen,
|
|
17680
|
+
high: Math.max(bar.high, haOpen, haClose),
|
|
17681
|
+
low: Math.min(bar.low, haOpen, haClose),
|
|
17682
|
+
close: haClose,
|
|
17683
|
+
customValues: bar.customValues,
|
|
17684
|
+
});
|
|
17685
|
+
previousOpen = haOpen;
|
|
17686
|
+
previousClose = haClose;
|
|
17687
|
+
}
|
|
17688
|
+
return result;
|
|
17689
|
+
}
|
|
17690
|
+
/**
|
|
17691
|
+
* Draw a source series as Heikin Ashi candles.
|
|
17692
|
+
*
|
|
17693
|
+
* The source series is left in place holding its real prices — it is only
|
|
17694
|
+
* painted transparent — so indicators bound to it keep computing on the true
|
|
17695
|
+
* OHLC, its price lines and primitives stay on screen, and `remove()` puts the
|
|
17696
|
+
* chart back exactly as it was. That makes this usable as a chart-type toggle:
|
|
17697
|
+
*
|
|
17698
|
+
* ```js
|
|
17699
|
+
* const ha = applyHeikinAshi(candleSeries, chart);
|
|
17700
|
+
* // …back to regular candles:
|
|
17701
|
+
* ha.remove();
|
|
17702
|
+
* ```
|
|
17703
|
+
*
|
|
17704
|
+
* @param series - Source OHLC series (a candlestick or bar series).
|
|
17705
|
+
* @param chart - Chart instance.
|
|
17706
|
+
* @param options - Heikin Ashi configuration options.
|
|
17707
|
+
* @returns The Heikin Ashi candlestick series, plus live control over its options.
|
|
17708
|
+
*/
|
|
17709
|
+
function applyHeikinAshi(series, chart, options = {}) {
|
|
17710
|
+
const resolved = {
|
|
17711
|
+
paneIndex: options.paneIndex ?? 0,
|
|
17712
|
+
upColor: options.upColor ?? '#26a69a',
|
|
17713
|
+
downColor: options.downColor ?? '#ef5350',
|
|
17714
|
+
borderVisible: options.borderVisible ?? true,
|
|
17715
|
+
borderUpColor: options.borderUpColor ?? '#26a69a',
|
|
17716
|
+
borderDownColor: options.borderDownColor ?? '#ef5350',
|
|
17717
|
+
wickVisible: options.wickVisible ?? true,
|
|
17718
|
+
wickUpColor: options.wickUpColor ?? '#26a69a',
|
|
17719
|
+
wickDownColor: options.wickDownColor ?? '#ef5350',
|
|
17720
|
+
hideSource: options.hideSource ?? true,
|
|
17721
|
+
};
|
|
17722
|
+
const sourceOptions = series.options();
|
|
17723
|
+
// Same price scale and the same formatting as the source: the candles are a
|
|
17724
|
+
// restatement of that series, not a second instrument, so they must not
|
|
17725
|
+
// autoscale on their own axis or round to a different precision.
|
|
17726
|
+
const haSeries = chart.addSeries(candlestickSeries, {
|
|
17727
|
+
upColor: resolved.upColor,
|
|
17728
|
+
downColor: resolved.downColor,
|
|
17729
|
+
borderVisible: resolved.borderVisible,
|
|
17730
|
+
borderUpColor: resolved.borderUpColor,
|
|
17731
|
+
borderDownColor: resolved.borderDownColor,
|
|
17732
|
+
wickVisible: resolved.wickVisible,
|
|
17733
|
+
wickUpColor: resolved.wickUpColor,
|
|
17734
|
+
wickDownColor: resolved.wickDownColor,
|
|
17735
|
+
priceScaleId: sourceOptions.priceScaleId,
|
|
17736
|
+
priceFormat: sourceOptions.priceFormat,
|
|
17737
|
+
}, resolved.paneIndex);
|
|
17738
|
+
let restoreSourcePaint = null;
|
|
17739
|
+
const blankSource = (blank) => {
|
|
17740
|
+
if (blank && restoreSourcePaint === null) {
|
|
17741
|
+
restoreSourcePaint = hideSeriesPaint(series);
|
|
17742
|
+
}
|
|
17743
|
+
else if (!blank && restoreSourcePaint !== null) {
|
|
17744
|
+
restoreSourcePaint();
|
|
17745
|
+
restoreSourcePaint = null;
|
|
17746
|
+
}
|
|
17747
|
+
};
|
|
17748
|
+
const runtime = bindIndicator({
|
|
17749
|
+
_internal_source: series,
|
|
17750
|
+
_internal_chart: chart,
|
|
17751
|
+
_internal_outputs: [haSeries],
|
|
17752
|
+
_internal_label: 'Heikin Ashi',
|
|
17753
|
+
_internal_options: resolved,
|
|
17754
|
+
// Every option here is a colour or a toggle on the series itself, so a
|
|
17755
|
+
// change never needs the transform run again.
|
|
17756
|
+
_internal_recomputeOn: [],
|
|
17757
|
+
_internal_compute: (data) => [
|
|
17758
|
+
[haSeries, calculateHeikinAshi(data)],
|
|
17759
|
+
],
|
|
17760
|
+
_internal_applyStyle: (current) => {
|
|
17761
|
+
haSeries.applyOptions({
|
|
17762
|
+
upColor: current.upColor,
|
|
17763
|
+
downColor: current.downColor,
|
|
17764
|
+
borderVisible: current.borderVisible,
|
|
17765
|
+
borderUpColor: current.borderUpColor,
|
|
17766
|
+
borderDownColor: current.borderDownColor,
|
|
17767
|
+
wickVisible: current.wickVisible,
|
|
17768
|
+
wickUpColor: current.wickUpColor,
|
|
17769
|
+
wickDownColor: current.wickDownColor,
|
|
17770
|
+
});
|
|
17771
|
+
blankSource(current.hideSource === true);
|
|
17772
|
+
},
|
|
17773
|
+
});
|
|
17774
|
+
const handle = {
|
|
17775
|
+
_internal_series: haSeries,
|
|
17776
|
+
options: runtime.options,
|
|
17777
|
+
applyOptions: runtime.applyOptions,
|
|
17778
|
+
recalculate: runtime.recalculate,
|
|
17779
|
+
remove: () => {
|
|
17780
|
+
runtime.remove();
|
|
17781
|
+
// The source outlives the indicator, so its paint is ours to put
|
|
17782
|
+
// back — otherwise removing a Heikin Ashi overlay leaves a blank chart.
|
|
17783
|
+
try {
|
|
17784
|
+
blankSource(false);
|
|
17785
|
+
}
|
|
17786
|
+
catch (error) {
|
|
17787
|
+
// The series may already be gone if the chart was disposed
|
|
17788
|
+
}
|
|
17789
|
+
},
|
|
17790
|
+
};
|
|
17791
|
+
return handle;
|
|
17792
|
+
}
|
|
17793
|
+
|
|
17553
17794
|
/**
|
|
17554
17795
|
* Apply RSI indicator to a series
|
|
17555
17796
|
* @param series - Source series to calculate RSI from
|
|
@@ -29608,7 +29849,7 @@
|
|
|
29608
29849
|
* Returns the current version as a string. For example `'1.0.0'`.
|
|
29609
29850
|
*/
|
|
29610
29851
|
function version() {
|
|
29611
|
-
return "2.0
|
|
29852
|
+
return "2.2.0";
|
|
29612
29853
|
}
|
|
29613
29854
|
|
|
29614
29855
|
var PipsendChartsModule = /*#__PURE__*/Object.freeze({
|
|
@@ -29665,6 +29906,7 @@
|
|
|
29665
29906
|
applyCCI: applyCCI,
|
|
29666
29907
|
applyDonchianChannels: applyDonchianChannels,
|
|
29667
29908
|
applyEMA: applyEMA,
|
|
29909
|
+
applyHeikinAshi: applyHeikinAshi,
|
|
29668
29910
|
applyIchimoku: applyIchimoku,
|
|
29669
29911
|
applyKeltnerChannels: applyKeltnerChannels,
|
|
29670
29912
|
applyMACD: applyMACD,
|
|
@@ -29680,6 +29922,7 @@
|
|
|
29680
29922
|
applyVolume: applyVolume,
|
|
29681
29923
|
applyWMA: applyWMA,
|
|
29682
29924
|
applyWilliamsR: applyWilliamsR,
|
|
29925
|
+
calculateHeikinAshi: calculateHeikinAshi,
|
|
29683
29926
|
calculatePipConfig: calculatePipConfig,
|
|
29684
29927
|
coordinateFromTime: coordinateFromTime,
|
|
29685
29928
|
createArrowTool: createArrowTool,
|
|
@@ -29716,6 +29959,7 @@
|
|
|
29716
29959
|
customSeriesDefaultOptions: customSeriesDefaultOptions,
|
|
29717
29960
|
defaultHorzScaleBehavior: defaultHorzScaleBehavior,
|
|
29718
29961
|
getPipConfig: getPipConfig,
|
|
29962
|
+
hideSeriesPaint: hideSeriesPaint,
|
|
29719
29963
|
isBusinessDay: isBusinessDay,
|
|
29720
29964
|
isUTCTimestamp: isUTCTimestamp,
|
|
29721
29965
|
setSeriesVolumes: setSeriesVolumes,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* Pipsend Charts v2.0
|
|
3
|
+
* Pipsend Charts v2.2.0
|
|
4
4
|
* Copyright (c) 2026 Pipsend
|
|
5
5
|
* Licensed under MIT License
|
|
6
6
|
* Built on TradingView Lightweight Charts™ (Apache 2.0)
|
|
@@ -15913,6 +15913,85 @@ function hasSeriesVolumes(series) {
|
|
|
15913
15913
|
return volumes !== undefined && volumes.size > 0;
|
|
15914
15914
|
}
|
|
15915
15915
|
|
|
15916
|
+
const TRANSPARENT = 'rgba(0, 0, 0, 0)';
|
|
15917
|
+
/**
|
|
15918
|
+
* Take a series off the screen without hiding it.
|
|
15919
|
+
*
|
|
15920
|
+
* `visible: false` takes down everything hung off the series as well: its
|
|
15921
|
+
* price lines, primitives and price-axis label stop rendering. A transform
|
|
15922
|
+
* that only wants the bars themselves out of the way — Heikin Ashi drawing
|
|
15923
|
+
* over its source — needs the series to stay visible to the engine, so its
|
|
15924
|
+
* paint is made transparent instead and the last-value label and price line
|
|
15925
|
+
* are switched off. Custom series have no known colours; those fall back to
|
|
15926
|
+
* `visible: false`.
|
|
15927
|
+
*
|
|
15928
|
+
* @param series - Series to blank out.
|
|
15929
|
+
* @returns Puts back the options the series had when it was blanked.
|
|
15930
|
+
*/
|
|
15931
|
+
function hideSeriesPaint(series) {
|
|
15932
|
+
switch (series.seriesType()) {
|
|
15933
|
+
case 'Candlestick':
|
|
15934
|
+
return blank(series, {
|
|
15935
|
+
upColor: TRANSPARENT,
|
|
15936
|
+
downColor: TRANSPARENT,
|
|
15937
|
+
borderVisible: false,
|
|
15938
|
+
wickVisible: false,
|
|
15939
|
+
});
|
|
15940
|
+
case 'Bar':
|
|
15941
|
+
return blank(series, {
|
|
15942
|
+
upColor: TRANSPARENT,
|
|
15943
|
+
downColor: TRANSPARENT,
|
|
15944
|
+
});
|
|
15945
|
+
case 'Line':
|
|
15946
|
+
return blank(series, {
|
|
15947
|
+
color: TRANSPARENT,
|
|
15948
|
+
crosshairMarkerVisible: false,
|
|
15949
|
+
pointMarkersVisible: false,
|
|
15950
|
+
});
|
|
15951
|
+
case 'Area':
|
|
15952
|
+
return blank(series, {
|
|
15953
|
+
lineColor: TRANSPARENT,
|
|
15954
|
+
topColor: TRANSPARENT,
|
|
15955
|
+
bottomColor: TRANSPARENT,
|
|
15956
|
+
crosshairMarkerVisible: false,
|
|
15957
|
+
pointMarkersVisible: false,
|
|
15958
|
+
});
|
|
15959
|
+
case 'Baseline':
|
|
15960
|
+
return blank(series, {
|
|
15961
|
+
topLineColor: TRANSPARENT,
|
|
15962
|
+
topFillColor1: TRANSPARENT,
|
|
15963
|
+
topFillColor2: TRANSPARENT,
|
|
15964
|
+
bottomLineColor: TRANSPARENT,
|
|
15965
|
+
bottomFillColor1: TRANSPARENT,
|
|
15966
|
+
bottomFillColor2: TRANSPARENT,
|
|
15967
|
+
crosshairMarkerVisible: false,
|
|
15968
|
+
pointMarkersVisible: false,
|
|
15969
|
+
});
|
|
15970
|
+
case 'Histogram':
|
|
15971
|
+
return blank(series, {
|
|
15972
|
+
color: TRANSPARENT,
|
|
15973
|
+
});
|
|
15974
|
+
default:
|
|
15975
|
+
return blank(series, { visible: false });
|
|
15976
|
+
}
|
|
15977
|
+
}
|
|
15978
|
+
function blank(series, paint) {
|
|
15979
|
+
const patch = {
|
|
15980
|
+
...paint,
|
|
15981
|
+
lastValueVisible: false,
|
|
15982
|
+
priceLineVisible: false,
|
|
15983
|
+
};
|
|
15984
|
+
const before = series.options();
|
|
15985
|
+
const snapshot = {};
|
|
15986
|
+
for (const key of Object.keys(patch)) {
|
|
15987
|
+
snapshot[key] = before[key];
|
|
15988
|
+
}
|
|
15989
|
+
series.applyOptions(patch);
|
|
15990
|
+
return () => {
|
|
15991
|
+
series.applyOptions(snapshot);
|
|
15992
|
+
};
|
|
15993
|
+
}
|
|
15994
|
+
|
|
15916
15995
|
/**
|
|
15917
15996
|
* Pins a bounded indicator (RSI, Stochastic…) to a fixed price range.
|
|
15918
15997
|
*
|
|
@@ -17547,6 +17626,168 @@ function applyPivotPoints(series, chart, options = {}) {
|
|
|
17547
17626
|
};
|
|
17548
17627
|
}
|
|
17549
17628
|
|
|
17629
|
+
function isOhlc(bar) {
|
|
17630
|
+
return bar !== null
|
|
17631
|
+
&& bar !== undefined
|
|
17632
|
+
&& typeof bar.close === 'number';
|
|
17633
|
+
}
|
|
17634
|
+
/**
|
|
17635
|
+
* Turns raw OHLC bars into Heikin Ashi ones.
|
|
17636
|
+
*
|
|
17637
|
+
* Heikin Ashi is a price transform, not an overlay: each candle averages itself
|
|
17638
|
+
* with the one before it, which drops most of the single-bar noise and leaves
|
|
17639
|
+
* runs of same-coloured bodies while a trend holds.
|
|
17640
|
+
*
|
|
17641
|
+
* ```
|
|
17642
|
+
* close = (O + H + L + C) / 4
|
|
17643
|
+
* open = (previous open + previous close) / 2 // first bar: (O + C) / 2
|
|
17644
|
+
* high = max(H, open, close)
|
|
17645
|
+
* low = min(L, open, close)
|
|
17646
|
+
* ```
|
|
17647
|
+
*
|
|
17648
|
+
* Because every bar folds in the one before it, the result depends on where the
|
|
17649
|
+
* data starts: the same bar computed from a longer history differs slightly.
|
|
17650
|
+
* The difference decays over a few bars, so pass the whole series rather than a
|
|
17651
|
+
* recent window when you can.
|
|
17652
|
+
*
|
|
17653
|
+
* Whitespace items are passed through untouched, and do not advance the
|
|
17654
|
+
* running open/close — a gap in the data is not a bar.
|
|
17655
|
+
*
|
|
17656
|
+
* @param bars - Source bars, ordered oldest to newest.
|
|
17657
|
+
* @returns The transformed bars, one per input item.
|
|
17658
|
+
*/
|
|
17659
|
+
function calculateHeikinAshi(bars) {
|
|
17660
|
+
const result = [];
|
|
17661
|
+
let previousOpen = null;
|
|
17662
|
+
let previousClose = null;
|
|
17663
|
+
for (const bar of bars) {
|
|
17664
|
+
if (!isOhlc(bar)) {
|
|
17665
|
+
if (bar !== null && bar !== undefined) {
|
|
17666
|
+
result.push({ time: bar.time, customValues: bar.customValues });
|
|
17667
|
+
}
|
|
17668
|
+
continue;
|
|
17669
|
+
}
|
|
17670
|
+
const haClose = (bar.open + bar.high + bar.low + bar.close) / 4;
|
|
17671
|
+
const haOpen = previousOpen === null || previousClose === null
|
|
17672
|
+
? (bar.open + bar.close) / 2
|
|
17673
|
+
: (previousOpen + previousClose) / 2;
|
|
17674
|
+
result.push({
|
|
17675
|
+
time: bar.time,
|
|
17676
|
+
open: haOpen,
|
|
17677
|
+
high: Math.max(bar.high, haOpen, haClose),
|
|
17678
|
+
low: Math.min(bar.low, haOpen, haClose),
|
|
17679
|
+
close: haClose,
|
|
17680
|
+
customValues: bar.customValues,
|
|
17681
|
+
});
|
|
17682
|
+
previousOpen = haOpen;
|
|
17683
|
+
previousClose = haClose;
|
|
17684
|
+
}
|
|
17685
|
+
return result;
|
|
17686
|
+
}
|
|
17687
|
+
/**
|
|
17688
|
+
* Draw a source series as Heikin Ashi candles.
|
|
17689
|
+
*
|
|
17690
|
+
* The source series is left in place holding its real prices — it is only
|
|
17691
|
+
* painted transparent — so indicators bound to it keep computing on the true
|
|
17692
|
+
* OHLC, its price lines and primitives stay on screen, and `remove()` puts the
|
|
17693
|
+
* chart back exactly as it was. That makes this usable as a chart-type toggle:
|
|
17694
|
+
*
|
|
17695
|
+
* ```js
|
|
17696
|
+
* const ha = applyHeikinAshi(candleSeries, chart);
|
|
17697
|
+
* // …back to regular candles:
|
|
17698
|
+
* ha.remove();
|
|
17699
|
+
* ```
|
|
17700
|
+
*
|
|
17701
|
+
* @param series - Source OHLC series (a candlestick or bar series).
|
|
17702
|
+
* @param chart - Chart instance.
|
|
17703
|
+
* @param options - Heikin Ashi configuration options.
|
|
17704
|
+
* @returns The Heikin Ashi candlestick series, plus live control over its options.
|
|
17705
|
+
*/
|
|
17706
|
+
function applyHeikinAshi(series, chart, options = {}) {
|
|
17707
|
+
const resolved = {
|
|
17708
|
+
paneIndex: options.paneIndex ?? 0,
|
|
17709
|
+
upColor: options.upColor ?? '#26a69a',
|
|
17710
|
+
downColor: options.downColor ?? '#ef5350',
|
|
17711
|
+
borderVisible: options.borderVisible ?? true,
|
|
17712
|
+
borderUpColor: options.borderUpColor ?? '#26a69a',
|
|
17713
|
+
borderDownColor: options.borderDownColor ?? '#ef5350',
|
|
17714
|
+
wickVisible: options.wickVisible ?? true,
|
|
17715
|
+
wickUpColor: options.wickUpColor ?? '#26a69a',
|
|
17716
|
+
wickDownColor: options.wickDownColor ?? '#ef5350',
|
|
17717
|
+
hideSource: options.hideSource ?? true,
|
|
17718
|
+
};
|
|
17719
|
+
const sourceOptions = series.options();
|
|
17720
|
+
// Same price scale and the same formatting as the source: the candles are a
|
|
17721
|
+
// restatement of that series, not a second instrument, so they must not
|
|
17722
|
+
// autoscale on their own axis or round to a different precision.
|
|
17723
|
+
const haSeries = chart.addSeries(candlestickSeries, {
|
|
17724
|
+
upColor: resolved.upColor,
|
|
17725
|
+
downColor: resolved.downColor,
|
|
17726
|
+
borderVisible: resolved.borderVisible,
|
|
17727
|
+
borderUpColor: resolved.borderUpColor,
|
|
17728
|
+
borderDownColor: resolved.borderDownColor,
|
|
17729
|
+
wickVisible: resolved.wickVisible,
|
|
17730
|
+
wickUpColor: resolved.wickUpColor,
|
|
17731
|
+
wickDownColor: resolved.wickDownColor,
|
|
17732
|
+
priceScaleId: sourceOptions.priceScaleId,
|
|
17733
|
+
priceFormat: sourceOptions.priceFormat,
|
|
17734
|
+
}, resolved.paneIndex);
|
|
17735
|
+
let restoreSourcePaint = null;
|
|
17736
|
+
const blankSource = (blank) => {
|
|
17737
|
+
if (blank && restoreSourcePaint === null) {
|
|
17738
|
+
restoreSourcePaint = hideSeriesPaint(series);
|
|
17739
|
+
}
|
|
17740
|
+
else if (!blank && restoreSourcePaint !== null) {
|
|
17741
|
+
restoreSourcePaint();
|
|
17742
|
+
restoreSourcePaint = null;
|
|
17743
|
+
}
|
|
17744
|
+
};
|
|
17745
|
+
const runtime = bindIndicator({
|
|
17746
|
+
_internal_source: series,
|
|
17747
|
+
_internal_chart: chart,
|
|
17748
|
+
_internal_outputs: [haSeries],
|
|
17749
|
+
_internal_label: 'Heikin Ashi',
|
|
17750
|
+
_internal_options: resolved,
|
|
17751
|
+
// Every option here is a colour or a toggle on the series itself, so a
|
|
17752
|
+
// change never needs the transform run again.
|
|
17753
|
+
_internal_recomputeOn: [],
|
|
17754
|
+
_internal_compute: (data) => [
|
|
17755
|
+
[haSeries, calculateHeikinAshi(data)],
|
|
17756
|
+
],
|
|
17757
|
+
_internal_applyStyle: (current) => {
|
|
17758
|
+
haSeries.applyOptions({
|
|
17759
|
+
upColor: current.upColor,
|
|
17760
|
+
downColor: current.downColor,
|
|
17761
|
+
borderVisible: current.borderVisible,
|
|
17762
|
+
borderUpColor: current.borderUpColor,
|
|
17763
|
+
borderDownColor: current.borderDownColor,
|
|
17764
|
+
wickVisible: current.wickVisible,
|
|
17765
|
+
wickUpColor: current.wickUpColor,
|
|
17766
|
+
wickDownColor: current.wickDownColor,
|
|
17767
|
+
});
|
|
17768
|
+
blankSource(current.hideSource === true);
|
|
17769
|
+
},
|
|
17770
|
+
});
|
|
17771
|
+
const handle = {
|
|
17772
|
+
_internal_series: haSeries,
|
|
17773
|
+
options: runtime.options,
|
|
17774
|
+
applyOptions: runtime.applyOptions,
|
|
17775
|
+
recalculate: runtime.recalculate,
|
|
17776
|
+
remove: () => {
|
|
17777
|
+
runtime.remove();
|
|
17778
|
+
// The source outlives the indicator, so its paint is ours to put
|
|
17779
|
+
// back — otherwise removing a Heikin Ashi overlay leaves a blank chart.
|
|
17780
|
+
try {
|
|
17781
|
+
blankSource(false);
|
|
17782
|
+
}
|
|
17783
|
+
catch (error) {
|
|
17784
|
+
// The series may already be gone if the chart was disposed
|
|
17785
|
+
}
|
|
17786
|
+
},
|
|
17787
|
+
};
|
|
17788
|
+
return handle;
|
|
17789
|
+
}
|
|
17790
|
+
|
|
17550
17791
|
/**
|
|
17551
17792
|
* Apply RSI indicator to a series
|
|
17552
17793
|
* @param series - Source series to calculate RSI from
|
|
@@ -29605,7 +29846,7 @@ const customSeriesDefaultOptions = {
|
|
|
29605
29846
|
* Returns the current version as a string. For example `'1.0.0'`.
|
|
29606
29847
|
*/
|
|
29607
29848
|
function version() {
|
|
29608
|
-
return "2.0
|
|
29849
|
+
return "2.2.0";
|
|
29609
29850
|
}
|
|
29610
29851
|
|
|
29611
|
-
export { areaSeries as AreaSeries, ArrowTool, barSeries as BarSeries, baselineSeries as BaselineSeries, BrushTool, candlestickSeries as CandlestickSeries, CircleTool, ColorType, CrossLineTool, CrosshairMode, DEFAULT_SESSIONS, DraggablePriceLine, DrawingToolsManager, EXTENDED_FIBONACCI_RATIOS, FibonacciCalculator, FibonacciExtensionTool, FibonacciFanTool, FibonacciTool, GanttTool, histogramSeries as HistogramSeries, HorizontalLineTool, InteractiveLineManager, LastPriceAnimationMode, lineSeries as LineSeries, LineStyle, LineType, MismatchDirection, ParallelChannelTool, PitchforkTool, PolygonTool, PositionCalculator, PositionMarkersManager, PositionTool, PriceLineSource, PriceScaleMode, RectangleTool, RulerCalculator, RulerTool, STANDARD_FIBONACCI_RATIOS, TextTool, TickMarkType, TrackingModeExitMode, TradingSessionsIndicator, TrendLineTool, VerticalLineTool, VolumeProfileIndicator, applyADX, applyATR, applyBollingerBands, applyCCI, applyDonchianChannels, applyEMA, applyIchimoku, applyKeltnerChannels, applyMACD, applyMFI, applyOBV, applyParabolicSAR, applyPivotPoints, applyRSI, applySMA, applyStochastic, applySuperTrend, applyVWAP, applyVolume, applyWMA, applyWilliamsR, calculatePipConfig, coordinateFromTime, createArrowTool, createBrushTool, createChart, createChartEx, createCircleTool, createCrossLineTool, createFibonacciExtensionTool, createFibonacciFanTool, createFibonacciTool, createGanttTool, createHorizontalLineTool, createImageWatermark, createInteractiveLineManager, createOptionsChart, createParallelChannelTool, createPitchforkTool, createPolygonTool, createPositionMarkers, createPositionTool, createRectangleTool, createRulerTool, createSeriesMarkers, createTextTool, createTextWatermark, createTradingLine, createTradingSessionsIndicator, createTrendLineTool, createUpDownMarkers, createVerticalLineTool, createVolumeProfileIndicator, createYieldCurveChart, customSeriesDefaultOptions, defaultHorzScaleBehavior, getPipConfig, isBusinessDay, isUTCTimestamp, setSeriesVolumes, setVolumeProfileData, timeFromCoordinate, version };
|
|
29852
|
+
export { areaSeries as AreaSeries, ArrowTool, barSeries as BarSeries, baselineSeries as BaselineSeries, BrushTool, candlestickSeries as CandlestickSeries, CircleTool, ColorType, CrossLineTool, CrosshairMode, DEFAULT_SESSIONS, DraggablePriceLine, DrawingToolsManager, EXTENDED_FIBONACCI_RATIOS, FibonacciCalculator, FibonacciExtensionTool, FibonacciFanTool, FibonacciTool, GanttTool, histogramSeries as HistogramSeries, HorizontalLineTool, InteractiveLineManager, LastPriceAnimationMode, lineSeries as LineSeries, LineStyle, LineType, MismatchDirection, ParallelChannelTool, PitchforkTool, PolygonTool, PositionCalculator, PositionMarkersManager, PositionTool, PriceLineSource, PriceScaleMode, RectangleTool, RulerCalculator, RulerTool, STANDARD_FIBONACCI_RATIOS, TextTool, TickMarkType, TrackingModeExitMode, TradingSessionsIndicator, TrendLineTool, VerticalLineTool, VolumeProfileIndicator, applyADX, applyATR, applyBollingerBands, applyCCI, applyDonchianChannels, applyEMA, applyHeikinAshi, applyIchimoku, applyKeltnerChannels, applyMACD, applyMFI, applyOBV, applyParabolicSAR, applyPivotPoints, applyRSI, applySMA, applyStochastic, applySuperTrend, applyVWAP, applyVolume, applyWMA, applyWilliamsR, calculateHeikinAshi, calculatePipConfig, coordinateFromTime, createArrowTool, createBrushTool, createChart, createChartEx, createCircleTool, createCrossLineTool, createFibonacciExtensionTool, createFibonacciFanTool, createFibonacciTool, createGanttTool, createHorizontalLineTool, createImageWatermark, createInteractiveLineManager, createOptionsChart, createParallelChannelTool, createPitchforkTool, createPolygonTool, createPositionMarkers, createPositionTool, createRectangleTool, createRulerTool, createSeriesMarkers, createTextTool, createTextWatermark, createTradingLine, createTradingSessionsIndicator, createTrendLineTool, createUpDownMarkers, createVerticalLineTool, createVolumeProfileIndicator, createYieldCurveChart, customSeriesDefaultOptions, defaultHorzScaleBehavior, getPipConfig, hideSeriesPaint, isBusinessDay, isUTCTimestamp, setSeriesVolumes, setVolumeProfileData, timeFromCoordinate, version };
|