@363045841yyt/klinechart-core 0.7.3 → 0.7.5-alpha.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/README.md +201 -201
- package/README.zh-CN.md +201 -201
- package/dist/engine/renderers/webgl/candleSurface.js +47 -47
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -2
- package/dist/version.js.map +1 -1
- package/package.json +129 -122
- package/src/__tests__/signal.test.ts +124 -124
- package/src/config/chartSettings.ts +66 -66
- package/src/controllers/__tests__/drawing.test.ts +214 -214
- package/src/controllers/__tests__/indicatorSelector.test.ts +481 -481
- package/src/controllers/__tests__/toolbar.test.ts +225 -225
- package/src/controllers/createChartController.ts +665 -665
- package/src/controllers/createDrawingController.ts +96 -96
- package/src/controllers/createIndicatorSelectorController.ts +307 -307
- package/src/controllers/createToolbarController.ts +146 -146
- package/src/controllers/index.ts +19 -19
- package/src/controllers/types.ts +284 -284
- package/src/engine/__tests__/chart.dpr.test.ts +401 -401
- package/src/engine/__tests__/paneRenderer.resize.test.ts +92 -92
- package/src/engine/chart-store.ts +121 -121
- package/src/engine/chart.d.ts +617 -617
- package/src/engine/chart.ts +2815 -2815
- package/src/engine/controller/__tests__/interaction.dpr.test.ts +259 -259
- package/src/engine/controller/interaction.ts +722 -722
- package/src/engine/controller/markerInteraction.ts +130 -130
- package/src/engine/controller/pinchTracker.ts +82 -82
- package/src/engine/controller/tooltipPosition.ts +48 -48
- package/src/engine/draw/__tests__/pixelAlign.spec.ts +176 -176
- package/src/engine/draw/pixelAlign.ts +259 -259
- package/src/engine/drawing/index.ts +655 -655
- package/src/engine/drawing/interaction.ts +842 -842
- package/src/engine/drawing/plugin.ts +343 -343
- package/src/engine/indicators/__tests__/__fixtures__/golden/atr.json +38 -38
- package/src/engine/indicators/__tests__/__fixtures__/golden/dema.json +14 -14
- package/src/engine/indicators/__tests__/__fixtures__/golden/hma.json +14 -14
- package/src/engine/indicators/__tests__/__fixtures__/golden/index.ts +55 -55
- package/src/engine/indicators/__tests__/__fixtures__/golden/kama.json +14 -14
- package/src/engine/indicators/__tests__/__fixtures__/golden/tema.json +14 -14
- package/src/engine/indicators/__tests__/__fixtures__/golden/wma.json +40 -40
- package/src/engine/indicators/__tests__/__fixtures__/synthetic.ts +65 -65
- package/src/engine/indicators/__tests__/_propertyAssertions.ts +76 -76
- package/src/engine/indicators/__tests__/atr.test.ts +153 -153
- package/src/engine/indicators/__tests__/calculators.test.ts +614 -614
- package/src/engine/indicators/__tests__/cmf-mfi.test.ts +100 -100
- package/src/engine/indicators/__tests__/dema.test.ts +73 -73
- package/src/engine/indicators/__tests__/donchian.test.ts +70 -70
- package/src/engine/indicators/__tests__/hma.test.ts +73 -73
- package/src/engine/indicators/__tests__/ichimoku.test.ts +105 -105
- package/src/engine/indicators/__tests__/kama.test.ts +80 -80
- package/src/engine/indicators/__tests__/keltner.test.ts +65 -65
- package/src/engine/indicators/__tests__/pivot-fib.test.ts +110 -110
- package/src/engine/indicators/__tests__/roc.test.ts +68 -68
- package/src/engine/indicators/__tests__/sar.test.ts +86 -86
- package/src/engine/indicators/__tests__/scheduler.test.ts +831 -831
- package/src/engine/indicators/__tests__/soa.test.ts +533 -533
- package/src/engine/indicators/__tests__/structure.test.ts +110 -110
- package/src/engine/indicators/__tests__/supertrend.test.ts +65 -65
- package/src/engine/indicators/__tests__/tema.test.ts +68 -68
- package/src/engine/indicators/__tests__/trix.test.ts +70 -70
- package/src/engine/indicators/__tests__/volatility.test.ts +117 -117
- package/src/engine/indicators/__tests__/volume.test.ts +115 -115
- package/src/engine/indicators/__tests__/volumeProfile.test.ts +74 -74
- package/src/engine/indicators/__tests__/vwap.test.ts +69 -69
- package/src/engine/indicators/__tests__/wma.test.ts +112 -112
- package/src/engine/indicators/__tests__/zones.test.ts +95 -95
- package/src/engine/indicators/atrState.ts +27 -27
- package/src/engine/indicators/bollState.ts +51 -51
- package/src/engine/indicators/calculators.ts +2593 -2593
- package/src/engine/indicators/cciState.ts +25 -25
- package/src/engine/indicators/chaikinVolState.ts +32 -32
- package/src/engine/indicators/cmfState.ts +27 -27
- package/src/engine/indicators/demaState.ts +27 -27
- package/src/engine/indicators/donchianState.ts +43 -43
- package/src/engine/indicators/eneState.ts +43 -43
- package/src/engine/indicators/expmaState.ts +43 -43
- package/src/engine/indicators/fastkState.ts +25 -25
- package/src/engine/indicators/fibState.ts +41 -41
- package/src/engine/indicators/hmaState.ts +27 -27
- package/src/engine/indicators/hvState.ts +28 -28
- package/src/engine/indicators/ichimokuState.ts +70 -70
- package/src/engine/indicators/indicator.worker.ts +169 -169
- package/src/engine/indicators/indicatorDefinitionRegistry.ts +62 -62
- package/src/engine/indicators/indicatorMetadata.ts +110 -110
- package/src/engine/indicators/indicatorRegistry.ts +106 -106
- package/src/engine/indicators/indicatorRuntime.ts +1548 -1548
- package/src/engine/indicators/kamaState.ts +34 -34
- package/src/engine/indicators/keltnerState.ts +49 -49
- package/src/engine/indicators/kstState.ts +42 -42
- package/src/engine/indicators/maState.ts +36 -36
- package/src/engine/indicators/macdState.ts +76 -76
- package/src/engine/indicators/mfiState.ts +27 -27
- package/src/engine/indicators/momState.ts +25 -25
- package/src/engine/indicators/obvState.ts +25 -25
- package/src/engine/indicators/parkinsonState.ts +28 -28
- package/src/engine/indicators/pivotState.ts +51 -51
- package/src/engine/indicators/pvtState.ts +25 -25
- package/src/engine/indicators/rocState.ts +27 -27
- package/src/engine/indicators/rsiState.ts +65 -65
- package/src/engine/indicators/sarState.ts +41 -41
- package/src/engine/indicators/scheduler.ts +1205 -1205
- package/src/engine/indicators/soa.ts +352 -352
- package/src/engine/indicators/stateComposer.ts +1262 -1262
- package/src/engine/indicators/stochState.ts +26 -26
- package/src/engine/indicators/structureState.ts +69 -69
- package/src/engine/indicators/supertrendState.ts +37 -37
- package/src/engine/indicators/temaState.ts +27 -27
- package/src/engine/indicators/trixState.ts +35 -35
- package/src/engine/indicators/vmaState.ts +27 -27
- package/src/engine/indicators/volumeProfileState.ts +63 -63
- package/src/engine/indicators/vwapState.ts +29 -29
- package/src/engine/indicators/wmaState.ts +27 -27
- package/src/engine/indicators/wmsrState.ts +25 -25
- package/src/engine/indicators/workerProtocol.ts +613 -613
- package/src/engine/indicators/zonesState.ts +47 -47
- package/src/engine/layout/pane.ts +161 -161
- package/src/engine/marker/registry.ts +265 -265
- package/src/engine/paneRenderer.ts +169 -169
- package/src/engine/renderers/Indicator/atr.ts +237 -237
- package/src/engine/renderers/Indicator/boll.ts +317 -317
- package/src/engine/renderers/Indicator/cci.ts +275 -275
- package/src/engine/renderers/Indicator/chaikinVol.ts +138 -138
- package/src/engine/renderers/Indicator/cmf.ts +137 -137
- package/src/engine/renderers/Indicator/dema.ts +136 -136
- package/src/engine/renderers/Indicator/donchian.ts +137 -137
- package/src/engine/renderers/Indicator/ene.ts +271 -271
- package/src/engine/renderers/Indicator/expma.ts +197 -197
- package/src/engine/renderers/Indicator/fastk.ts +316 -316
- package/src/engine/renderers/Indicator/fib.ts +141 -141
- package/src/engine/renderers/Indicator/hma.ts +136 -136
- package/src/engine/renderers/Indicator/hv.ts +124 -124
- package/src/engine/renderers/Indicator/ichimoku.ts +181 -181
- package/src/engine/renderers/Indicator/index.ts +241 -241
- package/src/engine/renderers/Indicator/indicatorData.ts +650 -650
- package/src/engine/renderers/Indicator/kama.ts +136 -136
- package/src/engine/renderers/Indicator/keltner.ts +137 -137
- package/src/engine/renderers/Indicator/kst.ts +302 -302
- package/src/engine/renderers/Indicator/ma.ts +200 -200
- package/src/engine/renderers/Indicator/macd.ts +477 -477
- package/src/engine/renderers/Indicator/macdLegend.ts +141 -141
- package/src/engine/renderers/Indicator/mainIndicatorLegend.ts +272 -272
- package/src/engine/renderers/Indicator/mfi.ts +142 -142
- package/src/engine/renderers/Indicator/mom.ts +311 -311
- package/src/engine/renderers/Indicator/obv.ts +123 -123
- package/src/engine/renderers/Indicator/parkinson.ts +124 -124
- package/src/engine/renderers/Indicator/pivot.ts +131 -131
- package/src/engine/renderers/Indicator/pvt.ts +123 -123
- package/src/engine/renderers/Indicator/roc.ts +143 -143
- package/src/engine/renderers/Indicator/rsi.ts +390 -390
- package/src/engine/renderers/Indicator/sar.ts +113 -113
- package/src/engine/renderers/Indicator/scale/atr_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/cci_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/fastk_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/indicator_scale.ts +204 -204
- package/src/engine/renderers/Indicator/scale/kst_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/macd_scale.ts +22 -22
- package/src/engine/renderers/Indicator/scale/mom_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/rsi_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/stoch_scale.ts +19 -19
- package/src/engine/renderers/Indicator/scale/volume_scale.ts +26 -26
- package/src/engine/renderers/Indicator/scale/wmsr_scale.ts +19 -19
- package/src/engine/renderers/Indicator/stoch.ts +359 -359
- package/src/engine/renderers/Indicator/structure.ts +126 -126
- package/src/engine/renderers/Indicator/subPaneConfig.ts +265 -265
- package/src/engine/renderers/Indicator/supertrend.ts +115 -115
- package/src/engine/renderers/Indicator/tema.ts +136 -136
- package/src/engine/renderers/Indicator/trix.ts +158 -158
- package/src/engine/renderers/Indicator/vma.ts +124 -124
- package/src/engine/renderers/Indicator/volumeProfile.ts +125 -125
- package/src/engine/renderers/Indicator/vwap.ts +123 -123
- package/src/engine/renderers/Indicator/wma.ts +136 -136
- package/src/engine/renderers/Indicator/wmsr.ts +328 -328
- package/src/engine/renderers/Indicator/zones.ts +104 -104
- package/src/engine/renderers/__tests__/boll.renderer.test.ts +314 -314
- package/src/engine/renderers/__tests__/ene.renderer.test.ts +305 -305
- package/src/engine/renderers/__tests__/expma.renderer.test.ts +279 -279
- package/src/engine/renderers/__tests__/ma.renderer.test.ts +426 -426
- package/src/engine/renderers/__tests__/mainIndicatorLegend.renderer.test.ts +502 -502
- package/src/engine/renderers/__tests__/yAxis.renderer.test.ts +173 -173
- package/src/engine/renderers/candle.ts +459 -459
- package/src/engine/renderers/crosshair.ts +69 -69
- package/src/engine/renderers/customMarkers.ts +162 -162
- package/src/engine/renderers/extremaMarkers.ts +246 -246
- package/src/engine/renderers/gridLines.ts +90 -90
- package/src/engine/renderers/lastPrice.ts +97 -97
- package/src/engine/renderers/paneTitle.ts +136 -136
- package/src/engine/renderers/subVolume.ts +236 -236
- package/src/engine/renderers/timeAxis.ts +121 -121
- package/src/engine/renderers/webgl/candleSurface.ts +955 -955
- package/src/engine/renderers/webgl/sharedWebGLSurface.ts +146 -146
- package/src/engine/renderers/yAxis.ts +105 -105
- package/src/engine/scale/__tests__/logFormula.spec.ts +148 -148
- package/src/engine/scale/logFormula.ts +130 -130
- package/src/engine/scale/price.ts +39 -39
- package/src/engine/scale/priceScale.ts +264 -264
- package/src/engine/subPaneManager.ts +427 -427
- package/src/engine/theme/colors.ts +642 -642
- package/src/engine/theme/fonts.ts +20 -20
- package/src/engine/utils/klineConfig.ts +49 -49
- package/src/engine/utils/tickCount.ts +11 -11
- package/src/engine/utils/tickPosition.ts +214 -214
- package/src/engine/utils/zoom.ts +83 -83
- package/src/engine/viewport/viewport.ts +67 -67
- package/src/index.ts +3 -3
- package/src/plugin/ConfigManager.ts +93 -93
- package/src/plugin/EventBus.ts +77 -77
- package/src/plugin/HookSystem.ts +106 -106
- package/src/plugin/PluginHost.ts +243 -243
- package/src/plugin/PluginRegistry.ts +92 -92
- package/src/plugin/StateStore.ts +73 -73
- package/src/plugin/index.ts +19 -19
- package/src/plugin/rendererPluginManager.ts +368 -368
- package/src/plugin/stateKeys.ts +8 -8
- package/src/plugin/types.ts +526 -526
- package/src/reactivity/index.ts +2 -2
- package/src/reactivity/signal.ts +119 -119
- package/src/semantic/controller.ts +251 -251
- package/src/semantic/drawShape.ts +260 -260
- package/src/semantic/index.ts +28 -28
- package/src/semantic/schema.json +256 -256
- package/src/semantic/types.ts +251 -251
- package/src/semantic/validator.ts +349 -349
- package/src/types/kLine.ts +13 -13
- package/src/types/price.ts +56 -56
- package/src/types/volumePrice.ts +33 -33
- package/src/utils/dateFormat.ts +208 -208
- package/src/utils/kLineDraw/axis.ts +562 -562
- package/src/utils/priceToY.ts +34 -34
- package/src/utils/volumePrice.ts +202 -202
- package/src/version.ts +1 -1
|
@@ -1,1262 +1,1262 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* State Composer
|
|
3
|
-
* 把 Worker/Runtime 返回的 series bundle 组装成与现有兼容的 render states
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
MARenderState,
|
|
8
|
-
} from './maState'
|
|
9
|
-
import type {
|
|
10
|
-
BOLLRenderState,
|
|
11
|
-
} from './bollState'
|
|
12
|
-
import type {
|
|
13
|
-
EXPMARenderState,
|
|
14
|
-
} from './expmaState'
|
|
15
|
-
import type {
|
|
16
|
-
ENERenderState,
|
|
17
|
-
} from './eneState'
|
|
18
|
-
import type {
|
|
19
|
-
RSIRenderState,
|
|
20
|
-
} from './rsiState'
|
|
21
|
-
import { EMPTY_RSI_STATE } from './rsiState'
|
|
22
|
-
import type {
|
|
23
|
-
CCIRenderState,
|
|
24
|
-
} from './cciState'
|
|
25
|
-
import { EMPTY_CCI_STATE } from './cciState'
|
|
26
|
-
import type {
|
|
27
|
-
STOCHRenderState,
|
|
28
|
-
} from './stochState'
|
|
29
|
-
import { EMPTY_STOCH_STATE } from './stochState'
|
|
30
|
-
import type {
|
|
31
|
-
MOMRenderState,
|
|
32
|
-
} from './momState'
|
|
33
|
-
import { EMPTY_MOM_STATE } from './momState'
|
|
34
|
-
import type {
|
|
35
|
-
WMSRRenderState,
|
|
36
|
-
} from './wmsrState'
|
|
37
|
-
import { EMPTY_WMSR_STATE } from './wmsrState'
|
|
38
|
-
import type {
|
|
39
|
-
KSTRenderState,
|
|
40
|
-
} from './kstState'
|
|
41
|
-
import { EMPTY_KST_STATE } from './kstState'
|
|
42
|
-
import type {
|
|
43
|
-
FASTKRenderState,
|
|
44
|
-
} from './fastkState'
|
|
45
|
-
import { EMPTY_FASTK_STATE } from './fastkState'
|
|
46
|
-
import type {
|
|
47
|
-
MACDRenderState,
|
|
48
|
-
} from './macdState'
|
|
49
|
-
import { EMPTY_MACD_STATE } from './macdState'
|
|
50
|
-
import type {
|
|
51
|
-
ATRRenderState,
|
|
52
|
-
} from './atrState'
|
|
53
|
-
import { EMPTY_ATR_STATE } from './atrState'
|
|
54
|
-
import type { WMARenderState } from './wmaState'
|
|
55
|
-
import { EMPTY_WMA_STATE } from './wmaState'
|
|
56
|
-
import type { DEMARenderState } from './demaState'
|
|
57
|
-
import { EMPTY_DEMA_STATE } from './demaState'
|
|
58
|
-
import type { TEMARenderState } from './temaState'
|
|
59
|
-
import { EMPTY_TEMA_STATE } from './temaState'
|
|
60
|
-
import type { HMARenderState } from './hmaState'
|
|
61
|
-
import { EMPTY_HMA_STATE } from './hmaState'
|
|
62
|
-
import type { KAMARenderState } from './kamaState'
|
|
63
|
-
import { EMPTY_KAMA_STATE } from './kamaState'
|
|
64
|
-
import type { SARRenderState } from './sarState'
|
|
65
|
-
import { EMPTY_SAR_STATE } from './sarState'
|
|
66
|
-
import type { SuperTrendRenderState } from './supertrendState'
|
|
67
|
-
import { EMPTY_SUPERTREND_STATE } from './supertrendState'
|
|
68
|
-
import type { KeltnerRenderState } from './keltnerState'
|
|
69
|
-
import { EMPTY_KELTNER_STATE } from './keltnerState'
|
|
70
|
-
import type { DonchianRenderState } from './donchianState'
|
|
71
|
-
import { EMPTY_DONCHIAN_STATE } from './donchianState'
|
|
72
|
-
import type { IchimokuRenderState } from './ichimokuState'
|
|
73
|
-
import { EMPTY_ICHIMOKU_STATE } from './ichimokuState'
|
|
74
|
-
import type { ROCRenderState } from './rocState'
|
|
75
|
-
import { EMPTY_ROC_STATE } from './rocState'
|
|
76
|
-
import type { TRIXRenderState } from './trixState'
|
|
77
|
-
import { EMPTY_TRIX_STATE } from './trixState'
|
|
78
|
-
import type { HVRenderState } from './hvState'
|
|
79
|
-
import { EMPTY_HV_STATE } from './hvState'
|
|
80
|
-
import type { ParkinsonRenderState } from './parkinsonState'
|
|
81
|
-
import { EMPTY_PARKINSON_STATE } from './parkinsonState'
|
|
82
|
-
import type { ChaikinVolRenderState } from './chaikinVolState'
|
|
83
|
-
import { EMPTY_CHAIKIN_VOL_STATE } from './chaikinVolState'
|
|
84
|
-
import type { VMARenderState } from './vmaState'
|
|
85
|
-
import { EMPTY_VMA_STATE } from './vmaState'
|
|
86
|
-
import type { OBVRenderState } from './obvState'
|
|
87
|
-
import { EMPTY_OBV_STATE } from './obvState'
|
|
88
|
-
import type { PVTRenderState } from './pvtState'
|
|
89
|
-
import { EMPTY_PVT_STATE } from './pvtState'
|
|
90
|
-
import type { VWAPRenderState } from './vwapState'
|
|
91
|
-
import { EMPTY_VWAP_STATE } from './vwapState'
|
|
92
|
-
import type { CMFRenderState } from './cmfState'
|
|
93
|
-
import { EMPTY_CMF_STATE } from './cmfState'
|
|
94
|
-
import type { MFIRenderState } from './mfiState'
|
|
95
|
-
import { EMPTY_MFI_STATE } from './mfiState'
|
|
96
|
-
import type { PivotRenderState } from './pivotState'
|
|
97
|
-
import { EMPTY_PIVOT_STATE } from './pivotState'
|
|
98
|
-
import type { FibRenderState } from './fibState'
|
|
99
|
-
import { EMPTY_FIB_STATE } from './fibState'
|
|
100
|
-
import type { StructureRenderState } from './structureState'
|
|
101
|
-
import { EMPTY_STRUCTURE_STATE } from './structureState'
|
|
102
|
-
import type { ZonesRenderState } from './zonesState'
|
|
103
|
-
import { EMPTY_ZONES_STATE } from './zonesState'
|
|
104
|
-
import type { VolumeProfileRenderState } from './volumeProfileState'
|
|
105
|
-
import { EMPTY_VOLUME_PROFILE_STATE } from './volumeProfileState'
|
|
106
|
-
import type { IndicatorSeriesBundle } from './workerProtocol'
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 可见范围
|
|
110
|
-
*/
|
|
111
|
-
interface VisibleRange {
|
|
112
|
-
start: number
|
|
113
|
-
end: number
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
type VisibleSubIndicatorStates = {
|
|
117
|
-
rsi: RSIRenderState
|
|
118
|
-
cci: CCIRenderState
|
|
119
|
-
stoch: STOCHRenderState
|
|
120
|
-
mom: MOMRenderState
|
|
121
|
-
wmsr: WMSRRenderState
|
|
122
|
-
kst: KSTRenderState
|
|
123
|
-
fastk: FASTKRenderState
|
|
124
|
-
macd: MACDRenderState
|
|
125
|
-
atr: ATRRenderState
|
|
126
|
-
wma: WMARenderState
|
|
127
|
-
dema: DEMARenderState
|
|
128
|
-
tema: TEMARenderState
|
|
129
|
-
hma: HMARenderState
|
|
130
|
-
kama: KAMARenderState
|
|
131
|
-
sar: SARRenderState
|
|
132
|
-
supertrend: SuperTrendRenderState
|
|
133
|
-
keltner: KeltnerRenderState
|
|
134
|
-
donchian: DonchianRenderState
|
|
135
|
-
ichimoku: IchimokuRenderState
|
|
136
|
-
roc: ROCRenderState
|
|
137
|
-
trix: TRIXRenderState
|
|
138
|
-
hv: HVRenderState
|
|
139
|
-
parkinson: ParkinsonRenderState
|
|
140
|
-
chaikinVol: ChaikinVolRenderState
|
|
141
|
-
vma: VMARenderState
|
|
142
|
-
obv: OBVRenderState
|
|
143
|
-
pvt: PVTRenderState
|
|
144
|
-
vwap: VWAPRenderState
|
|
145
|
-
cmf: CMFRenderState
|
|
146
|
-
mfi: MFIRenderState
|
|
147
|
-
pivot: PivotRenderState
|
|
148
|
-
fib: FibRenderState
|
|
149
|
-
structure: StructureRenderState
|
|
150
|
-
zones: ZonesRenderState
|
|
151
|
-
volumeProfile: VolumeProfileRenderState
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
type VisibleSubIndicatorMask = {
|
|
155
|
-
rsi?: boolean
|
|
156
|
-
cci?: boolean
|
|
157
|
-
stoch?: boolean
|
|
158
|
-
mom?: boolean
|
|
159
|
-
wmsr?: boolean
|
|
160
|
-
kst?: boolean
|
|
161
|
-
fastk?: boolean
|
|
162
|
-
macd?: boolean
|
|
163
|
-
atr?: boolean
|
|
164
|
-
wma?: boolean
|
|
165
|
-
dema?: boolean
|
|
166
|
-
tema?: boolean
|
|
167
|
-
hma?: boolean
|
|
168
|
-
kama?: boolean
|
|
169
|
-
sar?: boolean
|
|
170
|
-
supertrend?: boolean
|
|
171
|
-
keltner?: boolean
|
|
172
|
-
donchian?: boolean
|
|
173
|
-
ichimoku?: boolean
|
|
174
|
-
roc?: boolean
|
|
175
|
-
trix?: boolean
|
|
176
|
-
hv?: boolean
|
|
177
|
-
parkinson?: boolean
|
|
178
|
-
chaikinVol?: boolean
|
|
179
|
-
vma?: boolean
|
|
180
|
-
obv?: boolean
|
|
181
|
-
pvt?: boolean
|
|
182
|
-
vwap?: boolean
|
|
183
|
-
cmf?: boolean
|
|
184
|
-
mfi?: boolean
|
|
185
|
-
pivot?: boolean
|
|
186
|
-
fib?: boolean
|
|
187
|
-
structure?: boolean
|
|
188
|
-
zones?: boolean
|
|
189
|
-
volumeProfile?: boolean
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
type ComposedRenderStates = VisibleSubIndicatorStates & {
|
|
193
|
-
ma: MARenderState
|
|
194
|
-
boll: BOLLRenderState
|
|
195
|
-
expma: EXPMARenderState
|
|
196
|
-
ene: ENERenderState
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function getLatestMACDPoint(bundle: IndicatorSeriesBundle, visibleRange: VisibleRange) {
|
|
200
|
-
const latestIndex = visibleRange.end - 1
|
|
201
|
-
return latestIndex >= 0 && latestIndex < bundle.macd.series.length
|
|
202
|
-
? bundle.macd.series[latestIndex]
|
|
203
|
-
: null
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function mergeEmptyState<T extends { timestamp: number }>(state: T, timestamp: number, overrides: Partial<T>): T {
|
|
207
|
-
return {
|
|
208
|
-
...state,
|
|
209
|
-
...overrides,
|
|
210
|
-
timestamp,
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* 仅计算副图指标的 visible-only states
|
|
216
|
-
* 用于滚动时的轻量更新,避免重复计算主图指标
|
|
217
|
-
*/
|
|
218
|
-
export function composeVisibleSubIndicatorStates(
|
|
219
|
-
bundle: IndicatorSeriesBundle,
|
|
220
|
-
visibleRange: VisibleRange,
|
|
221
|
-
timestamp: number,
|
|
222
|
-
activeMask: VisibleSubIndicatorMask = {}
|
|
223
|
-
): VisibleSubIndicatorStates {
|
|
224
|
-
const rsiActive = activeMask.rsi ?? true
|
|
225
|
-
const cciActive = activeMask.cci ?? true
|
|
226
|
-
const stochActive = activeMask.stoch ?? true
|
|
227
|
-
const momActive = activeMask.mom ?? true
|
|
228
|
-
const wmsrActive = activeMask.wmsr ?? true
|
|
229
|
-
const kstActive = activeMask.kst ?? true
|
|
230
|
-
const fastkActive = activeMask.fastk ?? true
|
|
231
|
-
const macdActive = activeMask.macd ?? true
|
|
232
|
-
const atrActive = activeMask.atr ?? true
|
|
233
|
-
const wmaActive = activeMask.wma ?? true
|
|
234
|
-
const demaActive = activeMask.dema ?? true
|
|
235
|
-
const temaActive = activeMask.tema ?? true
|
|
236
|
-
const hmaActive = activeMask.hma ?? true
|
|
237
|
-
const kamaActive = activeMask.kama ?? true
|
|
238
|
-
const sarActive = activeMask.sar ?? true
|
|
239
|
-
const supertrendActive = activeMask.supertrend ?? true
|
|
240
|
-
const keltnerActive = activeMask.keltner ?? true
|
|
241
|
-
const donchianActive = activeMask.donchian ?? true
|
|
242
|
-
const ichimokuActive = activeMask.ichimoku ?? true
|
|
243
|
-
const rocActive = activeMask.roc ?? true
|
|
244
|
-
const trixActive = activeMask.trix ?? true
|
|
245
|
-
const hvActive = activeMask.hv ?? true
|
|
246
|
-
const parkinsonActive = activeMask.parkinson ?? true
|
|
247
|
-
const chaikinVolActive = activeMask.chaikinVol ?? true
|
|
248
|
-
const vmaActive = activeMask.vma ?? true
|
|
249
|
-
const obvActive = activeMask.obv ?? true
|
|
250
|
-
const pvtActive = activeMask.pvt ?? true
|
|
251
|
-
const vwapActive = activeMask.vwap ?? true
|
|
252
|
-
const cmfActive = activeMask.cmf ?? true
|
|
253
|
-
const mfiActive = activeMask.mfi ?? true
|
|
254
|
-
const pivotActive = activeMask.pivot ?? true
|
|
255
|
-
const fibActive = activeMask.fib ?? true
|
|
256
|
-
const structureActive = activeMask.structure ?? true
|
|
257
|
-
const zonesActive = activeMask.zones ?? true
|
|
258
|
-
const vpActive = activeMask.volumeProfile ?? true
|
|
259
|
-
|
|
260
|
-
const rsiExtremes = rsiActive ? calcRSIExtremes(bundle.rsi.series, visibleRange) : null
|
|
261
|
-
const cciExtremes = cciActive ? calcCCIExtremes(bundle.cci.series, visibleRange) : null
|
|
262
|
-
const stochExtremes = stochActive ? calcSTOCHExtremes(bundle.stoch.series, visibleRange) : null
|
|
263
|
-
const momExtremes = momActive ? calcMOMExtremes(bundle.mom.series, visibleRange) : null
|
|
264
|
-
const wmsrExtremes = wmsrActive ? calcWMSRExtremes(bundle.wmsr.series, visibleRange) : null
|
|
265
|
-
const kstExtremes = kstActive ? calcKSTExtremes(bundle.kst.series, visibleRange) : null
|
|
266
|
-
const fastkExtremes = fastkActive ? calcFASTKExtremes(bundle.fastk.series, visibleRange) : null
|
|
267
|
-
const macdExtremes = macdActive ? calcMACDExtremes(bundle.macd.series, visibleRange) : null
|
|
268
|
-
const atrExtremes = atrActive ? calcATRExtremes(bundle.atr.series, visibleRange) : null
|
|
269
|
-
const wmaExtremes = wmaActive ? calcSparseExtremes(bundle.wma.series, visibleRange) : null
|
|
270
|
-
const demaExtremes = demaActive ? calcSparseExtremes(bundle.dema.series, visibleRange) : null
|
|
271
|
-
const temaExtremes = temaActive ? calcSparseExtremes(bundle.tema.series, visibleRange) : null
|
|
272
|
-
const hmaExtremes = hmaActive ? calcSparseExtremes(bundle.hma.series, visibleRange) : null
|
|
273
|
-
const kamaExtremes = kamaActive ? calcSparseExtremes(bundle.kama.series, visibleRange) : null
|
|
274
|
-
const sarExtremes = sarActive ? calcSARExtremes(bundle.sar.series, visibleRange) : null
|
|
275
|
-
const supertrendExtremes = supertrendActive ? calcSARExtremes(bundle.supertrend.series, visibleRange) : null
|
|
276
|
-
const keltnerExtremes = keltnerActive ? calcBandExtremes(bundle.keltner.series, visibleRange) : null
|
|
277
|
-
const donchianExtremes = donchianActive ? calcBandExtremes(bundle.donchian.series, visibleRange) : null
|
|
278
|
-
const ichimokuExtremes = ichimokuActive ? calcIchimokuExtremes(bundle.ichimoku.series, visibleRange) : null
|
|
279
|
-
const rocExtremes = rocActive ? calcSparseExtremes(bundle.roc.series, visibleRange) : null
|
|
280
|
-
const trixSeriesExtremes = trixActive ? calcSparseExtremes(bundle.trix.series, visibleRange) : null
|
|
281
|
-
const trixSignalExtremes = trixActive ? calcSparseExtremes(bundle.trix.signalSeries, visibleRange) : null
|
|
282
|
-
const hvExtremes = hvActive ? calcSparseExtremes(bundle.hv.series, visibleRange) : null
|
|
283
|
-
const parkinsonExtremes = parkinsonActive ? calcSparseExtremes(bundle.parkinson.series, visibleRange) : null
|
|
284
|
-
const chaikinVolExtremes = chaikinVolActive ? calcSparseExtremes(bundle.chaikinVol.series, visibleRange) : null
|
|
285
|
-
const vmaExtremes = vmaActive ? calcSparseExtremes(bundle.vma.series, visibleRange) : null
|
|
286
|
-
const obvExtremes = obvActive ? calcSparseExtremes(bundle.obv.series, visibleRange) : null
|
|
287
|
-
const pvtExtremes = pvtActive ? calcSparseExtremes(bundle.pvt.series, visibleRange) : null
|
|
288
|
-
const vwapExtremes = vwapActive ? calcSparseExtremes(bundle.vwap.series, visibleRange) : null
|
|
289
|
-
const cmfExtremes = cmfActive ? calcSparseExtremes(bundle.cmf.series, visibleRange) : null
|
|
290
|
-
const mfiExtremes = mfiActive ? calcSparseExtremes(bundle.mfi.series, visibleRange) : null
|
|
291
|
-
const pivotExtremes = pivotActive ? calcPivotExtremes(bundle.pivot.series, visibleRange) : null
|
|
292
|
-
const fibExtremes = fibActive ? calcFibExtremes(bundle.fib.series, visibleRange) : null
|
|
293
|
-
const latestPoint = macdActive ? getLatestMACDPoint(bundle, visibleRange) : null
|
|
294
|
-
|
|
295
|
-
const macdPadding = macdExtremes ? Math.max(Math.abs(macdExtremes.max), Math.abs(macdExtremes.min)) * 0.1 : 0
|
|
296
|
-
const macdValueMin = macdExtremes && Number.isFinite(macdExtremes.min) ? macdExtremes.min - macdPadding : EMPTY_MACD_STATE.valueMin
|
|
297
|
-
const macdValueMax = macdExtremes && Number.isFinite(macdExtremes.max) ? macdExtremes.max + macdPadding : EMPTY_MACD_STATE.valueMax
|
|
298
|
-
|
|
299
|
-
const cciValueMin = cciExtremes ? Math.min(cciExtremes.min, -150) : EMPTY_CCI_STATE.valueMin
|
|
300
|
-
const cciValueMax = cciExtremes ? Math.max(cciExtremes.max, 150) : EMPTY_CCI_STATE.valueMax
|
|
301
|
-
|
|
302
|
-
const momPadding = momExtremes ? Math.max(Math.abs(momExtremes.max), Math.abs(momExtremes.min)) * 0.1 : 0
|
|
303
|
-
const momValueMin = momExtremes ? momExtremes.min - momPadding : EMPTY_MOM_STATE.valueMin
|
|
304
|
-
const momValueMax = momExtremes ? momExtremes.max + momPadding : EMPTY_MOM_STATE.valueMax
|
|
305
|
-
|
|
306
|
-
const kstRange = kstExtremes ? kstExtremes.max - kstExtremes.min : 0
|
|
307
|
-
const kstPadding = kstRange * 0.1
|
|
308
|
-
const kstValueMin = kstExtremes ? kstExtremes.min - kstPadding : EMPTY_KST_STATE.valueMin
|
|
309
|
-
const kstValueMax = kstExtremes ? kstExtremes.max + kstPadding : EMPTY_KST_STATE.valueMax
|
|
310
|
-
|
|
311
|
-
const atrValueMax = atrExtremes && Number.isFinite(atrExtremes.max)
|
|
312
|
-
? atrExtremes.max * 1.1
|
|
313
|
-
: EMPTY_ATR_STATE.valueMax
|
|
314
|
-
|
|
315
|
-
const maFamilyBounds = (ext: { min: number; max: number } | null, empty: { valueMin: number; valueMax: number }) => {
|
|
316
|
-
if (!ext || !Number.isFinite(ext.min) || !Number.isFinite(ext.max)) {
|
|
317
|
-
return { valueMin: empty.valueMin, valueMax: empty.valueMax }
|
|
318
|
-
}
|
|
319
|
-
const range = ext.max - ext.min
|
|
320
|
-
const padding = range > 0 ? range * 0.05 : Math.max(1, Math.abs(ext.max) * 0.05)
|
|
321
|
-
return { valueMin: ext.min - padding, valueMax: ext.max + padding }
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const wmaBounds = maFamilyBounds(wmaExtremes, EMPTY_WMA_STATE)
|
|
325
|
-
const demaBounds = maFamilyBounds(demaExtremes, EMPTY_DEMA_STATE)
|
|
326
|
-
const temaBounds = maFamilyBounds(temaExtremes, EMPTY_TEMA_STATE)
|
|
327
|
-
const hmaBounds = maFamilyBounds(hmaExtremes, EMPTY_HMA_STATE)
|
|
328
|
-
const kamaBounds = maFamilyBounds(kamaExtremes, EMPTY_KAMA_STATE)
|
|
329
|
-
const sarBounds = maFamilyBounds(sarExtremes, EMPTY_SAR_STATE)
|
|
330
|
-
const supertrendBounds = maFamilyBounds(supertrendExtremes, EMPTY_SUPERTREND_STATE)
|
|
331
|
-
const keltnerBounds = maFamilyBounds(keltnerExtremes, EMPTY_KELTNER_STATE)
|
|
332
|
-
const donchianBounds = maFamilyBounds(donchianExtremes, EMPTY_DONCHIAN_STATE)
|
|
333
|
-
const ichimokuBounds = maFamilyBounds(ichimokuExtremes, EMPTY_ICHIMOKU_STATE)
|
|
334
|
-
const rocBounds = maFamilyBounds(rocExtremes, EMPTY_ROC_STATE)
|
|
335
|
-
const trixCombinedMin = Math.min(
|
|
336
|
-
trixSeriesExtremes?.min ?? Infinity,
|
|
337
|
-
trixSignalExtremes?.min ?? Infinity,
|
|
338
|
-
)
|
|
339
|
-
const trixCombinedMax = Math.max(
|
|
340
|
-
trixSeriesExtremes?.max ?? -Infinity,
|
|
341
|
-
trixSignalExtremes?.max ?? -Infinity,
|
|
342
|
-
)
|
|
343
|
-
const trixBounds = maFamilyBounds(
|
|
344
|
-
Number.isFinite(trixCombinedMin) && Number.isFinite(trixCombinedMax)
|
|
345
|
-
? { min: trixCombinedMin, max: trixCombinedMax }
|
|
346
|
-
: null,
|
|
347
|
-
EMPTY_TRIX_STATE,
|
|
348
|
-
)
|
|
349
|
-
// HV and Parkinson are non-negative volatility series; pad upward only
|
|
350
|
-
const hvValueMax = hvExtremes && Number.isFinite(hvExtremes.max) ? hvExtremes.max * 1.1 : EMPTY_HV_STATE.valueMax
|
|
351
|
-
const parkinsonValueMax = parkinsonExtremes && Number.isFinite(parkinsonExtremes.max)
|
|
352
|
-
? parkinsonExtremes.max * 1.1
|
|
353
|
-
: EMPTY_PARKINSON_STATE.valueMax
|
|
354
|
-
const chaikinVolBounds = maFamilyBounds(chaikinVolExtremes, EMPTY_CHAIKIN_VOL_STATE)
|
|
355
|
-
const vmaValueMax = vmaExtremes && Number.isFinite(vmaExtremes.max) ? vmaExtremes.max * 1.1 : EMPTY_VMA_STATE.valueMax
|
|
356
|
-
const obvBounds = maFamilyBounds(obvExtremes, EMPTY_OBV_STATE)
|
|
357
|
-
const pvtBounds = maFamilyBounds(pvtExtremes, EMPTY_PVT_STATE)
|
|
358
|
-
const vwapBounds = maFamilyBounds(vwapExtremes, EMPTY_VWAP_STATE)
|
|
359
|
-
|
|
360
|
-
return {
|
|
361
|
-
rsi: rsiActive ? {
|
|
362
|
-
timestamp,
|
|
363
|
-
series: bundle.rsi.series,
|
|
364
|
-
enabledPeriods: bundle.rsi.enabledPeriods,
|
|
365
|
-
params: bundle.rsi.params,
|
|
366
|
-
valueMin: 0,
|
|
367
|
-
valueMax: 100,
|
|
368
|
-
visibleMin: rsiExtremes!.min,
|
|
369
|
-
visibleMax: rsiExtremes!.max,
|
|
370
|
-
} : mergeEmptyState(EMPTY_RSI_STATE, timestamp, {
|
|
371
|
-
series: bundle.rsi.series,
|
|
372
|
-
enabledPeriods: bundle.rsi.enabledPeriods,
|
|
373
|
-
params: bundle.rsi.params,
|
|
374
|
-
}),
|
|
375
|
-
cci: cciActive ? {
|
|
376
|
-
timestamp,
|
|
377
|
-
series: bundle.cci.series,
|
|
378
|
-
params: bundle.cci.params,
|
|
379
|
-
valueMin: cciValueMin,
|
|
380
|
-
valueMax: cciValueMax,
|
|
381
|
-
visibleMin: cciExtremes!.min,
|
|
382
|
-
visibleMax: cciExtremes!.max,
|
|
383
|
-
} : mergeEmptyState(EMPTY_CCI_STATE, timestamp, {
|
|
384
|
-
series: bundle.cci.series,
|
|
385
|
-
params: bundle.cci.params,
|
|
386
|
-
}),
|
|
387
|
-
stoch: stochActive ? {
|
|
388
|
-
timestamp,
|
|
389
|
-
series: bundle.stoch.series,
|
|
390
|
-
params: bundle.stoch.params,
|
|
391
|
-
valueMin: 0,
|
|
392
|
-
valueMax: 100,
|
|
393
|
-
visibleMin: stochExtremes!.min,
|
|
394
|
-
visibleMax: stochExtremes!.max,
|
|
395
|
-
} : mergeEmptyState(EMPTY_STOCH_STATE, timestamp, {
|
|
396
|
-
series: bundle.stoch.series,
|
|
397
|
-
params: bundle.stoch.params,
|
|
398
|
-
}),
|
|
399
|
-
mom: momActive ? {
|
|
400
|
-
timestamp,
|
|
401
|
-
series: bundle.mom.series,
|
|
402
|
-
params: bundle.mom.params,
|
|
403
|
-
valueMin: momValueMin,
|
|
404
|
-
valueMax: momValueMax,
|
|
405
|
-
visibleMin: momExtremes!.min,
|
|
406
|
-
visibleMax: momExtremes!.max,
|
|
407
|
-
} : mergeEmptyState(EMPTY_MOM_STATE, timestamp, {
|
|
408
|
-
series: bundle.mom.series,
|
|
409
|
-
params: bundle.mom.params,
|
|
410
|
-
}),
|
|
411
|
-
wmsr: wmsrActive ? {
|
|
412
|
-
timestamp,
|
|
413
|
-
series: bundle.wmsr.series,
|
|
414
|
-
params: bundle.wmsr.params,
|
|
415
|
-
valueMin: -100,
|
|
416
|
-
valueMax: 0,
|
|
417
|
-
visibleMin: wmsrExtremes!.min,
|
|
418
|
-
visibleMax: wmsrExtremes!.max,
|
|
419
|
-
} : mergeEmptyState(EMPTY_WMSR_STATE, timestamp, {
|
|
420
|
-
series: bundle.wmsr.series,
|
|
421
|
-
params: bundle.wmsr.params,
|
|
422
|
-
}),
|
|
423
|
-
kst: kstActive ? {
|
|
424
|
-
timestamp,
|
|
425
|
-
series: bundle.kst.series,
|
|
426
|
-
params: bundle.kst.params,
|
|
427
|
-
valueMin: kstValueMin,
|
|
428
|
-
valueMax: kstValueMax,
|
|
429
|
-
visibleMin: kstExtremes!.min,
|
|
430
|
-
visibleMax: kstExtremes!.max,
|
|
431
|
-
} : mergeEmptyState(EMPTY_KST_STATE, timestamp, {
|
|
432
|
-
series: bundle.kst.series,
|
|
433
|
-
params: bundle.kst.params,
|
|
434
|
-
}),
|
|
435
|
-
fastk: fastkActive ? {
|
|
436
|
-
timestamp,
|
|
437
|
-
series: bundle.fastk.series,
|
|
438
|
-
params: bundle.fastk.params,
|
|
439
|
-
valueMin: 0,
|
|
440
|
-
valueMax: 100,
|
|
441
|
-
visibleMin: fastkExtremes!.min,
|
|
442
|
-
visibleMax: fastkExtremes!.max,
|
|
443
|
-
} : mergeEmptyState(EMPTY_FASTK_STATE, timestamp, {
|
|
444
|
-
series: bundle.fastk.series,
|
|
445
|
-
params: bundle.fastk.params,
|
|
446
|
-
}),
|
|
447
|
-
macd: macdActive ? {
|
|
448
|
-
timestamp,
|
|
449
|
-
series: bundle.macd.series,
|
|
450
|
-
params: bundle.macd.params,
|
|
451
|
-
valueMin: macdValueMin,
|
|
452
|
-
valueMax: macdValueMax,
|
|
453
|
-
visibleMin: macdExtremes!.min,
|
|
454
|
-
visibleMax: macdExtremes!.max,
|
|
455
|
-
latestValues: latestPoint ? {
|
|
456
|
-
dif: latestPoint.dif,
|
|
457
|
-
dea: latestPoint.dea,
|
|
458
|
-
macd: latestPoint.macd,
|
|
459
|
-
} : undefined,
|
|
460
|
-
} : mergeEmptyState(EMPTY_MACD_STATE, timestamp, {
|
|
461
|
-
series: bundle.macd.series,
|
|
462
|
-
params: bundle.macd.params,
|
|
463
|
-
}),
|
|
464
|
-
atr: atrActive ? {
|
|
465
|
-
timestamp,
|
|
466
|
-
series: bundle.atr.series,
|
|
467
|
-
params: bundle.atr.params,
|
|
468
|
-
valueMin: 0,
|
|
469
|
-
valueMax: atrValueMax,
|
|
470
|
-
visibleMin: atrExtremes!.min,
|
|
471
|
-
visibleMax: atrExtremes!.max,
|
|
472
|
-
} : mergeEmptyState(EMPTY_ATR_STATE, timestamp, {
|
|
473
|
-
series: bundle.atr.series,
|
|
474
|
-
params: bundle.atr.params,
|
|
475
|
-
}),
|
|
476
|
-
wma: wmaActive ? {
|
|
477
|
-
timestamp,
|
|
478
|
-
series: bundle.wma.series,
|
|
479
|
-
params: bundle.wma.params,
|
|
480
|
-
valueMin: wmaBounds.valueMin,
|
|
481
|
-
valueMax: wmaBounds.valueMax,
|
|
482
|
-
visibleMin: wmaExtremes!.min,
|
|
483
|
-
visibleMax: wmaExtremes!.max,
|
|
484
|
-
} : mergeEmptyState(EMPTY_WMA_STATE, timestamp, {
|
|
485
|
-
series: bundle.wma.series,
|
|
486
|
-
params: bundle.wma.params,
|
|
487
|
-
}),
|
|
488
|
-
dema: demaActive ? {
|
|
489
|
-
timestamp,
|
|
490
|
-
series: bundle.dema.series,
|
|
491
|
-
params: bundle.dema.params,
|
|
492
|
-
valueMin: demaBounds.valueMin,
|
|
493
|
-
valueMax: demaBounds.valueMax,
|
|
494
|
-
visibleMin: demaExtremes!.min,
|
|
495
|
-
visibleMax: demaExtremes!.max,
|
|
496
|
-
} : mergeEmptyState(EMPTY_DEMA_STATE, timestamp, {
|
|
497
|
-
series: bundle.dema.series,
|
|
498
|
-
params: bundle.dema.params,
|
|
499
|
-
}),
|
|
500
|
-
tema: temaActive ? {
|
|
501
|
-
timestamp,
|
|
502
|
-
series: bundle.tema.series,
|
|
503
|
-
params: bundle.tema.params,
|
|
504
|
-
valueMin: temaBounds.valueMin,
|
|
505
|
-
valueMax: temaBounds.valueMax,
|
|
506
|
-
visibleMin: temaExtremes!.min,
|
|
507
|
-
visibleMax: temaExtremes!.max,
|
|
508
|
-
} : mergeEmptyState(EMPTY_TEMA_STATE, timestamp, {
|
|
509
|
-
series: bundle.tema.series,
|
|
510
|
-
params: bundle.tema.params,
|
|
511
|
-
}),
|
|
512
|
-
hma: hmaActive ? {
|
|
513
|
-
timestamp,
|
|
514
|
-
series: bundle.hma.series,
|
|
515
|
-
params: bundle.hma.params,
|
|
516
|
-
valueMin: hmaBounds.valueMin,
|
|
517
|
-
valueMax: hmaBounds.valueMax,
|
|
518
|
-
visibleMin: hmaExtremes!.min,
|
|
519
|
-
visibleMax: hmaExtremes!.max,
|
|
520
|
-
} : mergeEmptyState(EMPTY_HMA_STATE, timestamp, {
|
|
521
|
-
series: bundle.hma.series,
|
|
522
|
-
params: bundle.hma.params,
|
|
523
|
-
}),
|
|
524
|
-
kama: kamaActive ? {
|
|
525
|
-
timestamp,
|
|
526
|
-
series: bundle.kama.series,
|
|
527
|
-
params: bundle.kama.params,
|
|
528
|
-
valueMin: kamaBounds.valueMin,
|
|
529
|
-
valueMax: kamaBounds.valueMax,
|
|
530
|
-
visibleMin: kamaExtremes!.min,
|
|
531
|
-
visibleMax: kamaExtremes!.max,
|
|
532
|
-
} : mergeEmptyState(EMPTY_KAMA_STATE, timestamp, {
|
|
533
|
-
series: bundle.kama.series,
|
|
534
|
-
params: bundle.kama.params,
|
|
535
|
-
}),
|
|
536
|
-
sar: sarActive ? {
|
|
537
|
-
timestamp,
|
|
538
|
-
series: bundle.sar.series,
|
|
539
|
-
params: bundle.sar.params,
|
|
540
|
-
valueMin: sarBounds.valueMin,
|
|
541
|
-
valueMax: sarBounds.valueMax,
|
|
542
|
-
visibleMin: sarExtremes!.min,
|
|
543
|
-
visibleMax: sarExtremes!.max,
|
|
544
|
-
} : mergeEmptyState(EMPTY_SAR_STATE, timestamp, {
|
|
545
|
-
series: bundle.sar.series,
|
|
546
|
-
params: bundle.sar.params,
|
|
547
|
-
}),
|
|
548
|
-
supertrend: supertrendActive ? {
|
|
549
|
-
timestamp,
|
|
550
|
-
series: bundle.supertrend.series,
|
|
551
|
-
params: bundle.supertrend.params,
|
|
552
|
-
valueMin: supertrendBounds.valueMin,
|
|
553
|
-
valueMax: supertrendBounds.valueMax,
|
|
554
|
-
visibleMin: supertrendExtremes!.min,
|
|
555
|
-
visibleMax: supertrendExtremes!.max,
|
|
556
|
-
} : mergeEmptyState(EMPTY_SUPERTREND_STATE, timestamp, {
|
|
557
|
-
series: bundle.supertrend.series,
|
|
558
|
-
params: bundle.supertrend.params,
|
|
559
|
-
}),
|
|
560
|
-
keltner: keltnerActive ? {
|
|
561
|
-
timestamp,
|
|
562
|
-
series: bundle.keltner.series,
|
|
563
|
-
params: bundle.keltner.params,
|
|
564
|
-
valueMin: keltnerBounds.valueMin,
|
|
565
|
-
valueMax: keltnerBounds.valueMax,
|
|
566
|
-
visibleMin: keltnerExtremes!.min,
|
|
567
|
-
visibleMax: keltnerExtremes!.max,
|
|
568
|
-
} : mergeEmptyState(EMPTY_KELTNER_STATE, timestamp, {
|
|
569
|
-
series: bundle.keltner.series,
|
|
570
|
-
params: bundle.keltner.params,
|
|
571
|
-
}),
|
|
572
|
-
donchian: donchianActive ? {
|
|
573
|
-
timestamp,
|
|
574
|
-
series: bundle.donchian.series,
|
|
575
|
-
params: bundle.donchian.params,
|
|
576
|
-
valueMin: donchianBounds.valueMin,
|
|
577
|
-
valueMax: donchianBounds.valueMax,
|
|
578
|
-
visibleMin: donchianExtremes!.min,
|
|
579
|
-
visibleMax: donchianExtremes!.max,
|
|
580
|
-
} : mergeEmptyState(EMPTY_DONCHIAN_STATE, timestamp, {
|
|
581
|
-
series: bundle.donchian.series,
|
|
582
|
-
params: bundle.donchian.params,
|
|
583
|
-
}),
|
|
584
|
-
ichimoku: ichimokuActive ? {
|
|
585
|
-
timestamp,
|
|
586
|
-
series: bundle.ichimoku.series,
|
|
587
|
-
params: bundle.ichimoku.params,
|
|
588
|
-
valueMin: ichimokuBounds.valueMin,
|
|
589
|
-
valueMax: ichimokuBounds.valueMax,
|
|
590
|
-
visibleMin: ichimokuExtremes!.min,
|
|
591
|
-
visibleMax: ichimokuExtremes!.max,
|
|
592
|
-
} : mergeEmptyState(EMPTY_ICHIMOKU_STATE, timestamp, {
|
|
593
|
-
series: bundle.ichimoku.series,
|
|
594
|
-
params: bundle.ichimoku.params,
|
|
595
|
-
}),
|
|
596
|
-
roc: rocActive ? {
|
|
597
|
-
timestamp,
|
|
598
|
-
series: bundle.roc.series,
|
|
599
|
-
params: bundle.roc.params,
|
|
600
|
-
valueMin: rocBounds.valueMin,
|
|
601
|
-
valueMax: rocBounds.valueMax,
|
|
602
|
-
visibleMin: rocExtremes!.min,
|
|
603
|
-
visibleMax: rocExtremes!.max,
|
|
604
|
-
} : mergeEmptyState(EMPTY_ROC_STATE, timestamp, {
|
|
605
|
-
series: bundle.roc.series,
|
|
606
|
-
params: bundle.roc.params,
|
|
607
|
-
}),
|
|
608
|
-
trix: trixActive ? {
|
|
609
|
-
timestamp,
|
|
610
|
-
series: bundle.trix.series,
|
|
611
|
-
signalSeries: bundle.trix.signalSeries,
|
|
612
|
-
params: bundle.trix.params,
|
|
613
|
-
valueMin: trixBounds.valueMin,
|
|
614
|
-
valueMax: trixBounds.valueMax,
|
|
615
|
-
visibleMin: Math.min(trixSeriesExtremes?.min ?? Infinity, trixSignalExtremes?.min ?? Infinity),
|
|
616
|
-
visibleMax: Math.max(trixSeriesExtremes?.max ?? -Infinity, trixSignalExtremes?.max ?? -Infinity),
|
|
617
|
-
} : mergeEmptyState(EMPTY_TRIX_STATE, timestamp, {
|
|
618
|
-
series: bundle.trix.series,
|
|
619
|
-
signalSeries: bundle.trix.signalSeries,
|
|
620
|
-
params: bundle.trix.params,
|
|
621
|
-
}),
|
|
622
|
-
hv: hvActive ? {
|
|
623
|
-
timestamp,
|
|
624
|
-
series: bundle.hv.series,
|
|
625
|
-
params: bundle.hv.params,
|
|
626
|
-
valueMin: 0,
|
|
627
|
-
valueMax: hvValueMax,
|
|
628
|
-
visibleMin: hvExtremes!.min,
|
|
629
|
-
visibleMax: hvExtremes!.max,
|
|
630
|
-
} : mergeEmptyState(EMPTY_HV_STATE, timestamp, {
|
|
631
|
-
series: bundle.hv.series,
|
|
632
|
-
params: bundle.hv.params,
|
|
633
|
-
}),
|
|
634
|
-
parkinson: parkinsonActive ? {
|
|
635
|
-
timestamp,
|
|
636
|
-
series: bundle.parkinson.series,
|
|
637
|
-
params: bundle.parkinson.params,
|
|
638
|
-
valueMin: 0,
|
|
639
|
-
valueMax: parkinsonValueMax,
|
|
640
|
-
visibleMin: parkinsonExtremes!.min,
|
|
641
|
-
visibleMax: parkinsonExtremes!.max,
|
|
642
|
-
} : mergeEmptyState(EMPTY_PARKINSON_STATE, timestamp, {
|
|
643
|
-
series: bundle.parkinson.series,
|
|
644
|
-
params: bundle.parkinson.params,
|
|
645
|
-
}),
|
|
646
|
-
chaikinVol: chaikinVolActive ? {
|
|
647
|
-
timestamp,
|
|
648
|
-
series: bundle.chaikinVol.series,
|
|
649
|
-
params: bundle.chaikinVol.params,
|
|
650
|
-
valueMin: chaikinVolBounds.valueMin,
|
|
651
|
-
valueMax: chaikinVolBounds.valueMax,
|
|
652
|
-
visibleMin: chaikinVolExtremes!.min,
|
|
653
|
-
visibleMax: chaikinVolExtremes!.max,
|
|
654
|
-
} : mergeEmptyState(EMPTY_CHAIKIN_VOL_STATE, timestamp, {
|
|
655
|
-
series: bundle.chaikinVol.series,
|
|
656
|
-
params: bundle.chaikinVol.params,
|
|
657
|
-
}),
|
|
658
|
-
vma: vmaActive ? {
|
|
659
|
-
timestamp,
|
|
660
|
-
series: bundle.vma.series,
|
|
661
|
-
params: bundle.vma.params,
|
|
662
|
-
valueMin: 0,
|
|
663
|
-
valueMax: vmaValueMax,
|
|
664
|
-
visibleMin: vmaExtremes!.min,
|
|
665
|
-
visibleMax: vmaExtremes!.max,
|
|
666
|
-
} : mergeEmptyState(EMPTY_VMA_STATE, timestamp, {
|
|
667
|
-
series: bundle.vma.series,
|
|
668
|
-
params: bundle.vma.params,
|
|
669
|
-
}),
|
|
670
|
-
obv: obvActive ? {
|
|
671
|
-
timestamp,
|
|
672
|
-
series: bundle.obv.series,
|
|
673
|
-
params: bundle.obv.params,
|
|
674
|
-
valueMin: obvBounds.valueMin,
|
|
675
|
-
valueMax: obvBounds.valueMax,
|
|
676
|
-
visibleMin: obvExtremes!.min,
|
|
677
|
-
visibleMax: obvExtremes!.max,
|
|
678
|
-
} : mergeEmptyState(EMPTY_OBV_STATE, timestamp, {
|
|
679
|
-
series: bundle.obv.series,
|
|
680
|
-
params: bundle.obv.params,
|
|
681
|
-
}),
|
|
682
|
-
pvt: pvtActive ? {
|
|
683
|
-
timestamp,
|
|
684
|
-
series: bundle.pvt.series,
|
|
685
|
-
params: bundle.pvt.params,
|
|
686
|
-
valueMin: pvtBounds.valueMin,
|
|
687
|
-
valueMax: pvtBounds.valueMax,
|
|
688
|
-
visibleMin: pvtExtremes!.min,
|
|
689
|
-
visibleMax: pvtExtremes!.max,
|
|
690
|
-
} : mergeEmptyState(EMPTY_PVT_STATE, timestamp, {
|
|
691
|
-
series: bundle.pvt.series,
|
|
692
|
-
params: bundle.pvt.params,
|
|
693
|
-
}),
|
|
694
|
-
vwap: vwapActive ? {
|
|
695
|
-
timestamp,
|
|
696
|
-
series: bundle.vwap.series,
|
|
697
|
-
params: bundle.vwap.params,
|
|
698
|
-
valueMin: vwapBounds.valueMin,
|
|
699
|
-
valueMax: vwapBounds.valueMax,
|
|
700
|
-
visibleMin: vwapExtremes!.min,
|
|
701
|
-
visibleMax: vwapExtremes!.max,
|
|
702
|
-
} : mergeEmptyState(EMPTY_VWAP_STATE, timestamp, {
|
|
703
|
-
series: bundle.vwap.series,
|
|
704
|
-
params: bundle.vwap.params,
|
|
705
|
-
}),
|
|
706
|
-
cmf: cmfActive ? {
|
|
707
|
-
timestamp,
|
|
708
|
-
series: bundle.cmf.series,
|
|
709
|
-
params: bundle.cmf.params,
|
|
710
|
-
valueMin: -1,
|
|
711
|
-
valueMax: 1,
|
|
712
|
-
visibleMin: cmfExtremes!.min,
|
|
713
|
-
visibleMax: cmfExtremes!.max,
|
|
714
|
-
} : mergeEmptyState(EMPTY_CMF_STATE, timestamp, {
|
|
715
|
-
series: bundle.cmf.series,
|
|
716
|
-
params: bundle.cmf.params,
|
|
717
|
-
}),
|
|
718
|
-
mfi: mfiActive ? {
|
|
719
|
-
timestamp,
|
|
720
|
-
series: bundle.mfi.series,
|
|
721
|
-
params: bundle.mfi.params,
|
|
722
|
-
valueMin: 0,
|
|
723
|
-
valueMax: 100,
|
|
724
|
-
visibleMin: mfiExtremes!.min,
|
|
725
|
-
visibleMax: mfiExtremes!.max,
|
|
726
|
-
} : mergeEmptyState(EMPTY_MFI_STATE, timestamp, {
|
|
727
|
-
series: bundle.mfi.series,
|
|
728
|
-
params: bundle.mfi.params,
|
|
729
|
-
}),
|
|
730
|
-
pivot: pivotActive ? {
|
|
731
|
-
timestamp,
|
|
732
|
-
series: bundle.pivot.series,
|
|
733
|
-
params: bundle.pivot.params,
|
|
734
|
-
valueMin: pivotExtremes!.min,
|
|
735
|
-
valueMax: pivotExtremes!.max,
|
|
736
|
-
visibleMin: pivotExtremes!.min,
|
|
737
|
-
visibleMax: pivotExtremes!.max,
|
|
738
|
-
} : mergeEmptyState(EMPTY_PIVOT_STATE, timestamp, {
|
|
739
|
-
series: bundle.pivot.series,
|
|
740
|
-
params: bundle.pivot.params,
|
|
741
|
-
}),
|
|
742
|
-
fib: fibActive ? {
|
|
743
|
-
timestamp,
|
|
744
|
-
series: bundle.fib.series,
|
|
745
|
-
params: bundle.fib.params,
|
|
746
|
-
valueMin: fibExtremes!.min,
|
|
747
|
-
valueMax: fibExtremes!.max,
|
|
748
|
-
visibleMin: fibExtremes!.min,
|
|
749
|
-
visibleMax: fibExtremes!.max,
|
|
750
|
-
} : mergeEmptyState(EMPTY_FIB_STATE, timestamp, {
|
|
751
|
-
series: bundle.fib.series,
|
|
752
|
-
params: bundle.fib.params,
|
|
753
|
-
}),
|
|
754
|
-
structure: structureActive ? {
|
|
755
|
-
timestamp,
|
|
756
|
-
series: bundle.structure.series,
|
|
757
|
-
params: bundle.structure.params,
|
|
758
|
-
valueMin: 0,
|
|
759
|
-
valueMax: 1,
|
|
760
|
-
visibleMin: 0,
|
|
761
|
-
visibleMax: 1,
|
|
762
|
-
} : mergeEmptyState(EMPTY_STRUCTURE_STATE, timestamp, {
|
|
763
|
-
series: bundle.structure.series,
|
|
764
|
-
params: bundle.structure.params,
|
|
765
|
-
}),
|
|
766
|
-
zones: zonesActive ? {
|
|
767
|
-
timestamp,
|
|
768
|
-
series: bundle.zones.series,
|
|
769
|
-
params: bundle.zones.params,
|
|
770
|
-
valueMin: 0,
|
|
771
|
-
valueMax: 1,
|
|
772
|
-
visibleMin: 0,
|
|
773
|
-
visibleMax: 1,
|
|
774
|
-
} : mergeEmptyState(EMPTY_ZONES_STATE, timestamp, {
|
|
775
|
-
series: bundle.zones.series,
|
|
776
|
-
params: bundle.zones.params,
|
|
777
|
-
}),
|
|
778
|
-
volumeProfile: vpActive ? {
|
|
779
|
-
timestamp,
|
|
780
|
-
series: bundle.volumeProfile.series,
|
|
781
|
-
params: bundle.volumeProfile.params,
|
|
782
|
-
valueMin: bundle.volumeProfile.series.bins[0]?.priceLow ?? 0,
|
|
783
|
-
valueMax: bundle.volumeProfile.series.bins[bundle.volumeProfile.series.bins.length - 1]?.priceHigh ?? 1,
|
|
784
|
-
visibleMin: bundle.volumeProfile.series.val,
|
|
785
|
-
visibleMax: bundle.volumeProfile.series.vah,
|
|
786
|
-
} : mergeEmptyState(EMPTY_VOLUME_PROFILE_STATE, timestamp, {
|
|
787
|
-
series: bundle.volumeProfile.series,
|
|
788
|
-
params: bundle.volumeProfile.params,
|
|
789
|
-
}),
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
/**
|
|
794
|
-
* 从 series bundle 组装所有 render states
|
|
795
|
-
* 同时计算 visibleMin/visibleMax 等派生字段
|
|
796
|
-
*/
|
|
797
|
-
export function composeRenderStates(
|
|
798
|
-
bundle: IndicatorSeriesBundle,
|
|
799
|
-
visibleRange: VisibleRange,
|
|
800
|
-
timestamp: number
|
|
801
|
-
): ComposedRenderStates {
|
|
802
|
-
const maExtremes = calcMAExtremes(bundle.ma.series, visibleRange)
|
|
803
|
-
const bollExtremes = calcBOLLExtremes(bundle.boll.series, visibleRange)
|
|
804
|
-
const expmaExtremes = calcEXPMAExtremes(bundle.expma.series, visibleRange)
|
|
805
|
-
const eneExtremes = calcENEExtremes(bundle.ene.series, visibleRange)
|
|
806
|
-
const subStates = composeVisibleSubIndicatorStates(bundle, visibleRange, timestamp)
|
|
807
|
-
|
|
808
|
-
return {
|
|
809
|
-
ma: {
|
|
810
|
-
timestamp,
|
|
811
|
-
series: bundle.ma.series,
|
|
812
|
-
enabledPeriods: bundle.ma.enabledPeriods,
|
|
813
|
-
visibleMin: maExtremes.min,
|
|
814
|
-
visibleMax: maExtremes.max,
|
|
815
|
-
},
|
|
816
|
-
boll: {
|
|
817
|
-
timestamp,
|
|
818
|
-
series: bundle.boll.series,
|
|
819
|
-
params: bundle.boll.params,
|
|
820
|
-
visibleMin: bollExtremes.min,
|
|
821
|
-
visibleMax: bollExtremes.max,
|
|
822
|
-
},
|
|
823
|
-
expma: {
|
|
824
|
-
timestamp,
|
|
825
|
-
series: bundle.expma.series,
|
|
826
|
-
params: bundle.expma.params,
|
|
827
|
-
visibleMin: expmaExtremes.min,
|
|
828
|
-
visibleMax: expmaExtremes.max,
|
|
829
|
-
},
|
|
830
|
-
ene: {
|
|
831
|
-
timestamp,
|
|
832
|
-
series: bundle.ene.series,
|
|
833
|
-
params: bundle.ene.params,
|
|
834
|
-
visibleMin: eneExtremes.min,
|
|
835
|
-
visibleMax: eneExtremes.max,
|
|
836
|
-
},
|
|
837
|
-
...subStates,
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
// ============================================================================
|
|
842
|
-
// 极值计算辅助函数
|
|
843
|
-
// ============================================================================
|
|
844
|
-
|
|
845
|
-
function calcMAExtremes(series: Record<number, (number | undefined)[]>, range: VisibleRange): { min: number; max: number } {
|
|
846
|
-
const seriesList = Object.values(series)
|
|
847
|
-
if (seriesList.length === 0 || range.start >= seriesList[0]!.length) {
|
|
848
|
-
return { min: Infinity, max: -Infinity }
|
|
849
|
-
}
|
|
850
|
-
let min = Infinity
|
|
851
|
-
let max = -Infinity
|
|
852
|
-
for (const values of seriesList) {
|
|
853
|
-
const end = Math.min(range.end, values.length)
|
|
854
|
-
for (let i = range.start; i < end; i++) {
|
|
855
|
-
const v = values[i]
|
|
856
|
-
if (v !== undefined) {
|
|
857
|
-
min = Math.min(min, v)
|
|
858
|
-
max = Math.max(max, v)
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
return { min, max }
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
interface BOLLPoint { upper: number; middle: number; lower: number }
|
|
866
|
-
function calcBOLLExtremes(series: BOLLPoint[], range: VisibleRange): { min: number; max: number } {
|
|
867
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
868
|
-
return { min: Infinity, max: -Infinity }
|
|
869
|
-
}
|
|
870
|
-
let min = Infinity
|
|
871
|
-
let max = -Infinity
|
|
872
|
-
const end = Math.min(range.end, series.length)
|
|
873
|
-
for (let i = range.start; i < end; i++) {
|
|
874
|
-
const p = series[i]
|
|
875
|
-
if (p) {
|
|
876
|
-
min = Math.min(min, p.upper, p.middle, p.lower)
|
|
877
|
-
max = Math.max(max, p.upper, p.middle, p.lower)
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
return { min, max }
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
interface EXPMAPoint { fast: number; slow: number }
|
|
884
|
-
function calcEXPMAExtremes(series: EXPMAPoint[], range: VisibleRange): { min: number; max: number } {
|
|
885
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
886
|
-
return { min: Infinity, max: -Infinity }
|
|
887
|
-
}
|
|
888
|
-
let min = Infinity
|
|
889
|
-
let max = -Infinity
|
|
890
|
-
const end = Math.min(range.end, series.length)
|
|
891
|
-
for (let i = range.start; i < end; i++) {
|
|
892
|
-
const p = series[i]
|
|
893
|
-
if (p) {
|
|
894
|
-
min = Math.min(min, p.fast, p.slow)
|
|
895
|
-
max = Math.max(max, p.fast, p.slow)
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
return { min, max }
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
interface ENEPoint { upper: number; middle: number; lower: number }
|
|
902
|
-
function calcENEExtremes(series: ENEPoint[], range: VisibleRange): { min: number; max: number } {
|
|
903
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
904
|
-
return { min: Infinity, max: -Infinity }
|
|
905
|
-
}
|
|
906
|
-
let min = Infinity
|
|
907
|
-
let max = -Infinity
|
|
908
|
-
const end = Math.min(range.end, series.length)
|
|
909
|
-
for (let i = range.start; i < end; i++) {
|
|
910
|
-
const p = series[i]
|
|
911
|
-
if (p) {
|
|
912
|
-
min = Math.min(min, p.upper, p.middle, p.lower)
|
|
913
|
-
max = Math.max(max, p.upper, p.middle, p.lower)
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
|
-
return { min, max }
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
function calcRSIExtremes(series: Record<number, (number | undefined)[]>, range: VisibleRange): { min: number; max: number } {
|
|
920
|
-
const seriesList = Object.values(series)
|
|
921
|
-
if (seriesList.length === 0 || range.start >= seriesList[0]!.length) {
|
|
922
|
-
return { min: Infinity, max: -Infinity }
|
|
923
|
-
}
|
|
924
|
-
let min = Infinity
|
|
925
|
-
let max = -Infinity
|
|
926
|
-
for (const values of seriesList) {
|
|
927
|
-
const end = Math.min(range.end, values.length)
|
|
928
|
-
for (let i = range.start; i < end; i++) {
|
|
929
|
-
const v = values[i]
|
|
930
|
-
if (v !== undefined) {
|
|
931
|
-
min = Math.min(min, v)
|
|
932
|
-
max = Math.max(max, v)
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
return { min, max }
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
function calcCCIExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
940
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
941
|
-
return { min: Infinity, max: -Infinity }
|
|
942
|
-
}
|
|
943
|
-
let min = Infinity
|
|
944
|
-
let max = -Infinity
|
|
945
|
-
const end = Math.min(range.end, series.length)
|
|
946
|
-
for (let i = range.start; i < end; i++) {
|
|
947
|
-
const v = series[i]
|
|
948
|
-
if (v !== undefined) {
|
|
949
|
-
min = Math.min(min, v)
|
|
950
|
-
max = Math.max(max, v)
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
return { min, max }
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
interface STOCHPoint { k: number; d: number }
|
|
957
|
-
function calcSTOCHExtremes(series: STOCHPoint[], range: VisibleRange): { min: number; max: number } {
|
|
958
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
959
|
-
return { min: Infinity, max: -Infinity }
|
|
960
|
-
}
|
|
961
|
-
let min = Infinity
|
|
962
|
-
let max = -Infinity
|
|
963
|
-
const end = Math.min(range.end, series.length)
|
|
964
|
-
for (let i = range.start; i < end; i++) {
|
|
965
|
-
const p = series[i]
|
|
966
|
-
if (p) {
|
|
967
|
-
min = Math.min(min, p.k, p.d)
|
|
968
|
-
max = Math.max(max, p.k, p.d)
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return { min, max }
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
function calcMOMExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
975
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
976
|
-
return { min: Infinity, max: -Infinity }
|
|
977
|
-
}
|
|
978
|
-
let min = Infinity
|
|
979
|
-
let max = -Infinity
|
|
980
|
-
const end = Math.min(range.end, series.length)
|
|
981
|
-
for (let i = range.start; i < end; i++) {
|
|
982
|
-
const v = series[i]
|
|
983
|
-
if (v !== undefined) {
|
|
984
|
-
min = Math.min(min, v)
|
|
985
|
-
max = Math.max(max, v)
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
return { min, max }
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
function calcWMSRExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
992
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
993
|
-
return { min: Infinity, max: -Infinity }
|
|
994
|
-
}
|
|
995
|
-
let min = Infinity
|
|
996
|
-
let max = -Infinity
|
|
997
|
-
const end = Math.min(range.end, series.length)
|
|
998
|
-
for (let i = range.start; i < end; i++) {
|
|
999
|
-
const v = series[i]
|
|
1000
|
-
if (v !== undefined) {
|
|
1001
|
-
min = Math.min(min, v)
|
|
1002
|
-
max = Math.max(max, v)
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
return { min, max }
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
interface KSTPoint { kst: number; signal: number }
|
|
1009
|
-
function calcKSTExtremes(series: KSTPoint[], range: VisibleRange): { min: number; max: number } {
|
|
1010
|
-
// 快速检查:空数据直接返回
|
|
1011
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
1012
|
-
return { min: Infinity, max: -Infinity }
|
|
1013
|
-
}
|
|
1014
|
-
let min = Infinity
|
|
1015
|
-
let max = -Infinity
|
|
1016
|
-
const end = Math.min(range.end, series.length)
|
|
1017
|
-
for (let i = range.start; i < end; i++) {
|
|
1018
|
-
const p = series[i]
|
|
1019
|
-
if (p) {
|
|
1020
|
-
min = Math.min(min, p.kst, p.signal)
|
|
1021
|
-
max = Math.max(max, p.kst, p.signal)
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
return { min, max }
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
function calcFASTKExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1028
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
1029
|
-
return { min: Infinity, max: -Infinity }
|
|
1030
|
-
}
|
|
1031
|
-
let min = Infinity
|
|
1032
|
-
let max = -Infinity
|
|
1033
|
-
const end = Math.min(range.end, series.length)
|
|
1034
|
-
for (let i = range.start; i < end; i++) {
|
|
1035
|
-
const v = series[i]
|
|
1036
|
-
if (v !== undefined) {
|
|
1037
|
-
min = Math.min(min, v)
|
|
1038
|
-
max = Math.max(max, v)
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
return { min, max }
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
interface MACDPoint { dif: number; dea: number; macd: number }
|
|
1045
|
-
function calcMACDExtremes(series: MACDPoint[], range: VisibleRange): { min: number; max: number } {
|
|
1046
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
1047
|
-
return { min: Infinity, max: -Infinity }
|
|
1048
|
-
}
|
|
1049
|
-
let min = Infinity
|
|
1050
|
-
let max = -Infinity
|
|
1051
|
-
const end = Math.min(range.end, series.length)
|
|
1052
|
-
for (let i = range.start; i < end; i++) {
|
|
1053
|
-
const p = series[i]
|
|
1054
|
-
if (p) {
|
|
1055
|
-
min = Math.min(min, p.dif, p.dea, p.macd)
|
|
1056
|
-
max = Math.max(max, p.dif, p.dea, p.macd)
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
return { min, max }
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
function calcATRExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1063
|
-
return calcSparseExtremes(series, range)
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
interface PivotPointShape {
|
|
1067
|
-
pp: number
|
|
1068
|
-
r1: number
|
|
1069
|
-
r2: number
|
|
1070
|
-
r3: number
|
|
1071
|
-
s1: number
|
|
1072
|
-
s2: number
|
|
1073
|
-
s3: number
|
|
1074
|
-
}
|
|
1075
|
-
function calcPivotExtremes(series: (PivotPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1076
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
1077
|
-
return { min: Infinity, max: -Infinity }
|
|
1078
|
-
}
|
|
1079
|
-
let min = Infinity
|
|
1080
|
-
let max = -Infinity
|
|
1081
|
-
const end = Math.min(range.end, series.length)
|
|
1082
|
-
for (let i = range.start; i < end; i++) {
|
|
1083
|
-
const p = series[i]
|
|
1084
|
-
if (!p) continue
|
|
1085
|
-
for (const v of [p.pp, p.r1, p.r2, p.r3, p.s1, p.s2, p.s3]) {
|
|
1086
|
-
if (v < min) min = v
|
|
1087
|
-
if (v > max) max = v
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
return { min, max }
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
interface FibPointShape {
|
|
1094
|
-
high: number
|
|
1095
|
-
low: number
|
|
1096
|
-
level236: number
|
|
1097
|
-
level382: number
|
|
1098
|
-
level500: number
|
|
1099
|
-
level618: number
|
|
1100
|
-
level786: number
|
|
1101
|
-
}
|
|
1102
|
-
function calcFibExtremes(series: (FibPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1103
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
1104
|
-
return { min: Infinity, max: -Infinity }
|
|
1105
|
-
}
|
|
1106
|
-
let min = Infinity
|
|
1107
|
-
let max = -Infinity
|
|
1108
|
-
const end = Math.min(range.end, series.length)
|
|
1109
|
-
for (let i = range.start; i < end; i++) {
|
|
1110
|
-
const p = series[i]
|
|
1111
|
-
if (!p) continue
|
|
1112
|
-
if (p.low < min) min = p.low
|
|
1113
|
-
if (p.high > max) max = p.high
|
|
1114
|
-
}
|
|
1115
|
-
return { min, max }
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
interface IchimokuPointShape {
|
|
1119
|
-
tenkan?: number
|
|
1120
|
-
kijun?: number
|
|
1121
|
-
spanA?: number
|
|
1122
|
-
spanB?: number
|
|
1123
|
-
chikou?: number
|
|
1124
|
-
}
|
|
1125
|
-
function calcIchimokuExtremes(series: (IchimokuPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1126
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
1127
|
-
return { min: Infinity, max: -Infinity }
|
|
1128
|
-
}
|
|
1129
|
-
let min = Infinity
|
|
1130
|
-
let max = -Infinity
|
|
1131
|
-
const end = Math.min(range.end, series.length)
|
|
1132
|
-
for (let i = range.start; i < end; i++) {
|
|
1133
|
-
const p = series[i]
|
|
1134
|
-
if (!p) continue
|
|
1135
|
-
for (const field of [p.tenkan, p.kijun, p.spanA, p.spanB, p.chikou]) {
|
|
1136
|
-
if (field !== undefined) {
|
|
1137
|
-
if (field < min) min = field
|
|
1138
|
-
if (field > max) max = field
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
return { min, max }
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
interface BandPointShape { upper: number; middle: number; lower: number }
|
|
1146
|
-
function calcBandExtremes(series: (BandPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1147
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
1148
|
-
return { min: Infinity, max: -Infinity }
|
|
1149
|
-
}
|
|
1150
|
-
let min = Infinity
|
|
1151
|
-
let max = -Infinity
|
|
1152
|
-
const end = Math.min(range.end, series.length)
|
|
1153
|
-
for (let i = range.start; i < end; i++) {
|
|
1154
|
-
const p = series[i]
|
|
1155
|
-
if (p) {
|
|
1156
|
-
min = Math.min(min, p.lower)
|
|
1157
|
-
max = Math.max(max, p.upper)
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
return { min, max }
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
interface SARPointShape { value: number; trend: 'up' | 'down' }
|
|
1164
|
-
function calcSARExtremes(series: (SARPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1165
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
1166
|
-
return { min: Infinity, max: -Infinity }
|
|
1167
|
-
}
|
|
1168
|
-
let min = Infinity
|
|
1169
|
-
let max = -Infinity
|
|
1170
|
-
const end = Math.min(range.end, series.length)
|
|
1171
|
-
for (let i = range.start; i < end; i++) {
|
|
1172
|
-
const p = series[i]
|
|
1173
|
-
if (p) {
|
|
1174
|
-
min = Math.min(min, p.value)
|
|
1175
|
-
max = Math.max(max, p.value)
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
return { min, max }
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
function calcSparseExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1182
|
-
if (series.length === 0 || range.start >= series.length) {
|
|
1183
|
-
return { min: Infinity, max: -Infinity }
|
|
1184
|
-
}
|
|
1185
|
-
let min = Infinity
|
|
1186
|
-
let max = -Infinity
|
|
1187
|
-
const end = Math.min(range.end, series.length)
|
|
1188
|
-
for (let i = range.start; i < end; i++) {
|
|
1189
|
-
const v = series[i]
|
|
1190
|
-
if (v !== undefined) {
|
|
1191
|
-
min = Math.min(min, v)
|
|
1192
|
-
max = Math.max(max, v)
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
return { min, max }
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
|
-
/**
|
|
1199
|
-
* 计算主图指标价格范围
|
|
1200
|
-
* 用于 Chart.draw() 中的 pane.updateRange
|
|
1201
|
-
*/
|
|
1202
|
-
export function computeMainIndicatorPriceRange(
|
|
1203
|
-
bundle: IndicatorSeriesBundle,
|
|
1204
|
-
visibleRange: VisibleRange,
|
|
1205
|
-
activeMainIndicators: Set<string>
|
|
1206
|
-
): { min: number; max: number } | null {
|
|
1207
|
-
let min = Infinity
|
|
1208
|
-
let max = -Infinity
|
|
1209
|
-
const { start, end } = visibleRange
|
|
1210
|
-
|
|
1211
|
-
// MA
|
|
1212
|
-
if (activeMainIndicators.has('ma') && Object.keys(bundle.ma.series).length > 0) {
|
|
1213
|
-
for (const values of Object.values(bundle.ma.series)) {
|
|
1214
|
-
for (let i = start; i < end && i < values.length; i++) {
|
|
1215
|
-
const v = values[i]
|
|
1216
|
-
if (v !== undefined) {
|
|
1217
|
-
min = Math.min(min, v)
|
|
1218
|
-
max = Math.max(max, v)
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
// BOLL
|
|
1225
|
-
if (activeMainIndicators.has('boll') && bundle.boll.series.length > 0) {
|
|
1226
|
-
for (let i = start; i < end && i < bundle.boll.series.length; i++) {
|
|
1227
|
-
const p = bundle.boll.series[i]
|
|
1228
|
-
if (p) {
|
|
1229
|
-
min = Math.min(min, p.upper, p.middle, p.lower)
|
|
1230
|
-
max = Math.max(max, p.upper, p.middle, p.lower)
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
// EXPMA
|
|
1236
|
-
if (activeMainIndicators.has('expma') && bundle.expma.series.length > 0) {
|
|
1237
|
-
for (let i = start; i < end && i < bundle.expma.series.length; i++) {
|
|
1238
|
-
const p = bundle.expma.series[i]
|
|
1239
|
-
if (p) {
|
|
1240
|
-
min = Math.min(min, p.fast, p.slow)
|
|
1241
|
-
max = Math.max(max, p.fast, p.slow)
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
// ENE
|
|
1247
|
-
if (activeMainIndicators.has('ene') && bundle.ene.series.length > 0) {
|
|
1248
|
-
for (let i = start; i < end && i < bundle.ene.series.length; i++) {
|
|
1249
|
-
const p = bundle.ene.series[i]
|
|
1250
|
-
if (p) {
|
|
1251
|
-
min = Math.min(min, p.upper, p.middle, p.lower)
|
|
1252
|
-
max = Math.max(max, p.upper, p.middle, p.lower)
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
if (!Number.isFinite(min) || !Number.isFinite(max)) {
|
|
1258
|
-
return null
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
return { min, max }
|
|
1262
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* State Composer
|
|
3
|
+
* 把 Worker/Runtime 返回的 series bundle 组装成与现有兼容的 render states
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
MARenderState,
|
|
8
|
+
} from './maState'
|
|
9
|
+
import type {
|
|
10
|
+
BOLLRenderState,
|
|
11
|
+
} from './bollState'
|
|
12
|
+
import type {
|
|
13
|
+
EXPMARenderState,
|
|
14
|
+
} from './expmaState'
|
|
15
|
+
import type {
|
|
16
|
+
ENERenderState,
|
|
17
|
+
} from './eneState'
|
|
18
|
+
import type {
|
|
19
|
+
RSIRenderState,
|
|
20
|
+
} from './rsiState'
|
|
21
|
+
import { EMPTY_RSI_STATE } from './rsiState'
|
|
22
|
+
import type {
|
|
23
|
+
CCIRenderState,
|
|
24
|
+
} from './cciState'
|
|
25
|
+
import { EMPTY_CCI_STATE } from './cciState'
|
|
26
|
+
import type {
|
|
27
|
+
STOCHRenderState,
|
|
28
|
+
} from './stochState'
|
|
29
|
+
import { EMPTY_STOCH_STATE } from './stochState'
|
|
30
|
+
import type {
|
|
31
|
+
MOMRenderState,
|
|
32
|
+
} from './momState'
|
|
33
|
+
import { EMPTY_MOM_STATE } from './momState'
|
|
34
|
+
import type {
|
|
35
|
+
WMSRRenderState,
|
|
36
|
+
} from './wmsrState'
|
|
37
|
+
import { EMPTY_WMSR_STATE } from './wmsrState'
|
|
38
|
+
import type {
|
|
39
|
+
KSTRenderState,
|
|
40
|
+
} from './kstState'
|
|
41
|
+
import { EMPTY_KST_STATE } from './kstState'
|
|
42
|
+
import type {
|
|
43
|
+
FASTKRenderState,
|
|
44
|
+
} from './fastkState'
|
|
45
|
+
import { EMPTY_FASTK_STATE } from './fastkState'
|
|
46
|
+
import type {
|
|
47
|
+
MACDRenderState,
|
|
48
|
+
} from './macdState'
|
|
49
|
+
import { EMPTY_MACD_STATE } from './macdState'
|
|
50
|
+
import type {
|
|
51
|
+
ATRRenderState,
|
|
52
|
+
} from './atrState'
|
|
53
|
+
import { EMPTY_ATR_STATE } from './atrState'
|
|
54
|
+
import type { WMARenderState } from './wmaState'
|
|
55
|
+
import { EMPTY_WMA_STATE } from './wmaState'
|
|
56
|
+
import type { DEMARenderState } from './demaState'
|
|
57
|
+
import { EMPTY_DEMA_STATE } from './demaState'
|
|
58
|
+
import type { TEMARenderState } from './temaState'
|
|
59
|
+
import { EMPTY_TEMA_STATE } from './temaState'
|
|
60
|
+
import type { HMARenderState } from './hmaState'
|
|
61
|
+
import { EMPTY_HMA_STATE } from './hmaState'
|
|
62
|
+
import type { KAMARenderState } from './kamaState'
|
|
63
|
+
import { EMPTY_KAMA_STATE } from './kamaState'
|
|
64
|
+
import type { SARRenderState } from './sarState'
|
|
65
|
+
import { EMPTY_SAR_STATE } from './sarState'
|
|
66
|
+
import type { SuperTrendRenderState } from './supertrendState'
|
|
67
|
+
import { EMPTY_SUPERTREND_STATE } from './supertrendState'
|
|
68
|
+
import type { KeltnerRenderState } from './keltnerState'
|
|
69
|
+
import { EMPTY_KELTNER_STATE } from './keltnerState'
|
|
70
|
+
import type { DonchianRenderState } from './donchianState'
|
|
71
|
+
import { EMPTY_DONCHIAN_STATE } from './donchianState'
|
|
72
|
+
import type { IchimokuRenderState } from './ichimokuState'
|
|
73
|
+
import { EMPTY_ICHIMOKU_STATE } from './ichimokuState'
|
|
74
|
+
import type { ROCRenderState } from './rocState'
|
|
75
|
+
import { EMPTY_ROC_STATE } from './rocState'
|
|
76
|
+
import type { TRIXRenderState } from './trixState'
|
|
77
|
+
import { EMPTY_TRIX_STATE } from './trixState'
|
|
78
|
+
import type { HVRenderState } from './hvState'
|
|
79
|
+
import { EMPTY_HV_STATE } from './hvState'
|
|
80
|
+
import type { ParkinsonRenderState } from './parkinsonState'
|
|
81
|
+
import { EMPTY_PARKINSON_STATE } from './parkinsonState'
|
|
82
|
+
import type { ChaikinVolRenderState } from './chaikinVolState'
|
|
83
|
+
import { EMPTY_CHAIKIN_VOL_STATE } from './chaikinVolState'
|
|
84
|
+
import type { VMARenderState } from './vmaState'
|
|
85
|
+
import { EMPTY_VMA_STATE } from './vmaState'
|
|
86
|
+
import type { OBVRenderState } from './obvState'
|
|
87
|
+
import { EMPTY_OBV_STATE } from './obvState'
|
|
88
|
+
import type { PVTRenderState } from './pvtState'
|
|
89
|
+
import { EMPTY_PVT_STATE } from './pvtState'
|
|
90
|
+
import type { VWAPRenderState } from './vwapState'
|
|
91
|
+
import { EMPTY_VWAP_STATE } from './vwapState'
|
|
92
|
+
import type { CMFRenderState } from './cmfState'
|
|
93
|
+
import { EMPTY_CMF_STATE } from './cmfState'
|
|
94
|
+
import type { MFIRenderState } from './mfiState'
|
|
95
|
+
import { EMPTY_MFI_STATE } from './mfiState'
|
|
96
|
+
import type { PivotRenderState } from './pivotState'
|
|
97
|
+
import { EMPTY_PIVOT_STATE } from './pivotState'
|
|
98
|
+
import type { FibRenderState } from './fibState'
|
|
99
|
+
import { EMPTY_FIB_STATE } from './fibState'
|
|
100
|
+
import type { StructureRenderState } from './structureState'
|
|
101
|
+
import { EMPTY_STRUCTURE_STATE } from './structureState'
|
|
102
|
+
import type { ZonesRenderState } from './zonesState'
|
|
103
|
+
import { EMPTY_ZONES_STATE } from './zonesState'
|
|
104
|
+
import type { VolumeProfileRenderState } from './volumeProfileState'
|
|
105
|
+
import { EMPTY_VOLUME_PROFILE_STATE } from './volumeProfileState'
|
|
106
|
+
import type { IndicatorSeriesBundle } from './workerProtocol'
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 可见范围
|
|
110
|
+
*/
|
|
111
|
+
interface VisibleRange {
|
|
112
|
+
start: number
|
|
113
|
+
end: number
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type VisibleSubIndicatorStates = {
|
|
117
|
+
rsi: RSIRenderState
|
|
118
|
+
cci: CCIRenderState
|
|
119
|
+
stoch: STOCHRenderState
|
|
120
|
+
mom: MOMRenderState
|
|
121
|
+
wmsr: WMSRRenderState
|
|
122
|
+
kst: KSTRenderState
|
|
123
|
+
fastk: FASTKRenderState
|
|
124
|
+
macd: MACDRenderState
|
|
125
|
+
atr: ATRRenderState
|
|
126
|
+
wma: WMARenderState
|
|
127
|
+
dema: DEMARenderState
|
|
128
|
+
tema: TEMARenderState
|
|
129
|
+
hma: HMARenderState
|
|
130
|
+
kama: KAMARenderState
|
|
131
|
+
sar: SARRenderState
|
|
132
|
+
supertrend: SuperTrendRenderState
|
|
133
|
+
keltner: KeltnerRenderState
|
|
134
|
+
donchian: DonchianRenderState
|
|
135
|
+
ichimoku: IchimokuRenderState
|
|
136
|
+
roc: ROCRenderState
|
|
137
|
+
trix: TRIXRenderState
|
|
138
|
+
hv: HVRenderState
|
|
139
|
+
parkinson: ParkinsonRenderState
|
|
140
|
+
chaikinVol: ChaikinVolRenderState
|
|
141
|
+
vma: VMARenderState
|
|
142
|
+
obv: OBVRenderState
|
|
143
|
+
pvt: PVTRenderState
|
|
144
|
+
vwap: VWAPRenderState
|
|
145
|
+
cmf: CMFRenderState
|
|
146
|
+
mfi: MFIRenderState
|
|
147
|
+
pivot: PivotRenderState
|
|
148
|
+
fib: FibRenderState
|
|
149
|
+
structure: StructureRenderState
|
|
150
|
+
zones: ZonesRenderState
|
|
151
|
+
volumeProfile: VolumeProfileRenderState
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type VisibleSubIndicatorMask = {
|
|
155
|
+
rsi?: boolean
|
|
156
|
+
cci?: boolean
|
|
157
|
+
stoch?: boolean
|
|
158
|
+
mom?: boolean
|
|
159
|
+
wmsr?: boolean
|
|
160
|
+
kst?: boolean
|
|
161
|
+
fastk?: boolean
|
|
162
|
+
macd?: boolean
|
|
163
|
+
atr?: boolean
|
|
164
|
+
wma?: boolean
|
|
165
|
+
dema?: boolean
|
|
166
|
+
tema?: boolean
|
|
167
|
+
hma?: boolean
|
|
168
|
+
kama?: boolean
|
|
169
|
+
sar?: boolean
|
|
170
|
+
supertrend?: boolean
|
|
171
|
+
keltner?: boolean
|
|
172
|
+
donchian?: boolean
|
|
173
|
+
ichimoku?: boolean
|
|
174
|
+
roc?: boolean
|
|
175
|
+
trix?: boolean
|
|
176
|
+
hv?: boolean
|
|
177
|
+
parkinson?: boolean
|
|
178
|
+
chaikinVol?: boolean
|
|
179
|
+
vma?: boolean
|
|
180
|
+
obv?: boolean
|
|
181
|
+
pvt?: boolean
|
|
182
|
+
vwap?: boolean
|
|
183
|
+
cmf?: boolean
|
|
184
|
+
mfi?: boolean
|
|
185
|
+
pivot?: boolean
|
|
186
|
+
fib?: boolean
|
|
187
|
+
structure?: boolean
|
|
188
|
+
zones?: boolean
|
|
189
|
+
volumeProfile?: boolean
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
type ComposedRenderStates = VisibleSubIndicatorStates & {
|
|
193
|
+
ma: MARenderState
|
|
194
|
+
boll: BOLLRenderState
|
|
195
|
+
expma: EXPMARenderState
|
|
196
|
+
ene: ENERenderState
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function getLatestMACDPoint(bundle: IndicatorSeriesBundle, visibleRange: VisibleRange) {
|
|
200
|
+
const latestIndex = visibleRange.end - 1
|
|
201
|
+
return latestIndex >= 0 && latestIndex < bundle.macd.series.length
|
|
202
|
+
? bundle.macd.series[latestIndex]
|
|
203
|
+
: null
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function mergeEmptyState<T extends { timestamp: number }>(state: T, timestamp: number, overrides: Partial<T>): T {
|
|
207
|
+
return {
|
|
208
|
+
...state,
|
|
209
|
+
...overrides,
|
|
210
|
+
timestamp,
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 仅计算副图指标的 visible-only states
|
|
216
|
+
* 用于滚动时的轻量更新,避免重复计算主图指标
|
|
217
|
+
*/
|
|
218
|
+
export function composeVisibleSubIndicatorStates(
|
|
219
|
+
bundle: IndicatorSeriesBundle,
|
|
220
|
+
visibleRange: VisibleRange,
|
|
221
|
+
timestamp: number,
|
|
222
|
+
activeMask: VisibleSubIndicatorMask = {}
|
|
223
|
+
): VisibleSubIndicatorStates {
|
|
224
|
+
const rsiActive = activeMask.rsi ?? true
|
|
225
|
+
const cciActive = activeMask.cci ?? true
|
|
226
|
+
const stochActive = activeMask.stoch ?? true
|
|
227
|
+
const momActive = activeMask.mom ?? true
|
|
228
|
+
const wmsrActive = activeMask.wmsr ?? true
|
|
229
|
+
const kstActive = activeMask.kst ?? true
|
|
230
|
+
const fastkActive = activeMask.fastk ?? true
|
|
231
|
+
const macdActive = activeMask.macd ?? true
|
|
232
|
+
const atrActive = activeMask.atr ?? true
|
|
233
|
+
const wmaActive = activeMask.wma ?? true
|
|
234
|
+
const demaActive = activeMask.dema ?? true
|
|
235
|
+
const temaActive = activeMask.tema ?? true
|
|
236
|
+
const hmaActive = activeMask.hma ?? true
|
|
237
|
+
const kamaActive = activeMask.kama ?? true
|
|
238
|
+
const sarActive = activeMask.sar ?? true
|
|
239
|
+
const supertrendActive = activeMask.supertrend ?? true
|
|
240
|
+
const keltnerActive = activeMask.keltner ?? true
|
|
241
|
+
const donchianActive = activeMask.donchian ?? true
|
|
242
|
+
const ichimokuActive = activeMask.ichimoku ?? true
|
|
243
|
+
const rocActive = activeMask.roc ?? true
|
|
244
|
+
const trixActive = activeMask.trix ?? true
|
|
245
|
+
const hvActive = activeMask.hv ?? true
|
|
246
|
+
const parkinsonActive = activeMask.parkinson ?? true
|
|
247
|
+
const chaikinVolActive = activeMask.chaikinVol ?? true
|
|
248
|
+
const vmaActive = activeMask.vma ?? true
|
|
249
|
+
const obvActive = activeMask.obv ?? true
|
|
250
|
+
const pvtActive = activeMask.pvt ?? true
|
|
251
|
+
const vwapActive = activeMask.vwap ?? true
|
|
252
|
+
const cmfActive = activeMask.cmf ?? true
|
|
253
|
+
const mfiActive = activeMask.mfi ?? true
|
|
254
|
+
const pivotActive = activeMask.pivot ?? true
|
|
255
|
+
const fibActive = activeMask.fib ?? true
|
|
256
|
+
const structureActive = activeMask.structure ?? true
|
|
257
|
+
const zonesActive = activeMask.zones ?? true
|
|
258
|
+
const vpActive = activeMask.volumeProfile ?? true
|
|
259
|
+
|
|
260
|
+
const rsiExtremes = rsiActive ? calcRSIExtremes(bundle.rsi.series, visibleRange) : null
|
|
261
|
+
const cciExtremes = cciActive ? calcCCIExtremes(bundle.cci.series, visibleRange) : null
|
|
262
|
+
const stochExtremes = stochActive ? calcSTOCHExtremes(bundle.stoch.series, visibleRange) : null
|
|
263
|
+
const momExtremes = momActive ? calcMOMExtremes(bundle.mom.series, visibleRange) : null
|
|
264
|
+
const wmsrExtremes = wmsrActive ? calcWMSRExtremes(bundle.wmsr.series, visibleRange) : null
|
|
265
|
+
const kstExtremes = kstActive ? calcKSTExtremes(bundle.kst.series, visibleRange) : null
|
|
266
|
+
const fastkExtremes = fastkActive ? calcFASTKExtremes(bundle.fastk.series, visibleRange) : null
|
|
267
|
+
const macdExtremes = macdActive ? calcMACDExtremes(bundle.macd.series, visibleRange) : null
|
|
268
|
+
const atrExtremes = atrActive ? calcATRExtremes(bundle.atr.series, visibleRange) : null
|
|
269
|
+
const wmaExtremes = wmaActive ? calcSparseExtremes(bundle.wma.series, visibleRange) : null
|
|
270
|
+
const demaExtremes = demaActive ? calcSparseExtremes(bundle.dema.series, visibleRange) : null
|
|
271
|
+
const temaExtremes = temaActive ? calcSparseExtremes(bundle.tema.series, visibleRange) : null
|
|
272
|
+
const hmaExtremes = hmaActive ? calcSparseExtremes(bundle.hma.series, visibleRange) : null
|
|
273
|
+
const kamaExtremes = kamaActive ? calcSparseExtremes(bundle.kama.series, visibleRange) : null
|
|
274
|
+
const sarExtremes = sarActive ? calcSARExtremes(bundle.sar.series, visibleRange) : null
|
|
275
|
+
const supertrendExtremes = supertrendActive ? calcSARExtremes(bundle.supertrend.series, visibleRange) : null
|
|
276
|
+
const keltnerExtremes = keltnerActive ? calcBandExtremes(bundle.keltner.series, visibleRange) : null
|
|
277
|
+
const donchianExtremes = donchianActive ? calcBandExtremes(bundle.donchian.series, visibleRange) : null
|
|
278
|
+
const ichimokuExtremes = ichimokuActive ? calcIchimokuExtremes(bundle.ichimoku.series, visibleRange) : null
|
|
279
|
+
const rocExtremes = rocActive ? calcSparseExtremes(bundle.roc.series, visibleRange) : null
|
|
280
|
+
const trixSeriesExtremes = trixActive ? calcSparseExtremes(bundle.trix.series, visibleRange) : null
|
|
281
|
+
const trixSignalExtremes = trixActive ? calcSparseExtremes(bundle.trix.signalSeries, visibleRange) : null
|
|
282
|
+
const hvExtremes = hvActive ? calcSparseExtremes(bundle.hv.series, visibleRange) : null
|
|
283
|
+
const parkinsonExtremes = parkinsonActive ? calcSparseExtremes(bundle.parkinson.series, visibleRange) : null
|
|
284
|
+
const chaikinVolExtremes = chaikinVolActive ? calcSparseExtremes(bundle.chaikinVol.series, visibleRange) : null
|
|
285
|
+
const vmaExtremes = vmaActive ? calcSparseExtremes(bundle.vma.series, visibleRange) : null
|
|
286
|
+
const obvExtremes = obvActive ? calcSparseExtremes(bundle.obv.series, visibleRange) : null
|
|
287
|
+
const pvtExtremes = pvtActive ? calcSparseExtremes(bundle.pvt.series, visibleRange) : null
|
|
288
|
+
const vwapExtremes = vwapActive ? calcSparseExtremes(bundle.vwap.series, visibleRange) : null
|
|
289
|
+
const cmfExtremes = cmfActive ? calcSparseExtremes(bundle.cmf.series, visibleRange) : null
|
|
290
|
+
const mfiExtremes = mfiActive ? calcSparseExtremes(bundle.mfi.series, visibleRange) : null
|
|
291
|
+
const pivotExtremes = pivotActive ? calcPivotExtremes(bundle.pivot.series, visibleRange) : null
|
|
292
|
+
const fibExtremes = fibActive ? calcFibExtremes(bundle.fib.series, visibleRange) : null
|
|
293
|
+
const latestPoint = macdActive ? getLatestMACDPoint(bundle, visibleRange) : null
|
|
294
|
+
|
|
295
|
+
const macdPadding = macdExtremes ? Math.max(Math.abs(macdExtremes.max), Math.abs(macdExtremes.min)) * 0.1 : 0
|
|
296
|
+
const macdValueMin = macdExtremes && Number.isFinite(macdExtremes.min) ? macdExtremes.min - macdPadding : EMPTY_MACD_STATE.valueMin
|
|
297
|
+
const macdValueMax = macdExtremes && Number.isFinite(macdExtremes.max) ? macdExtremes.max + macdPadding : EMPTY_MACD_STATE.valueMax
|
|
298
|
+
|
|
299
|
+
const cciValueMin = cciExtremes ? Math.min(cciExtremes.min, -150) : EMPTY_CCI_STATE.valueMin
|
|
300
|
+
const cciValueMax = cciExtremes ? Math.max(cciExtremes.max, 150) : EMPTY_CCI_STATE.valueMax
|
|
301
|
+
|
|
302
|
+
const momPadding = momExtremes ? Math.max(Math.abs(momExtremes.max), Math.abs(momExtremes.min)) * 0.1 : 0
|
|
303
|
+
const momValueMin = momExtremes ? momExtremes.min - momPadding : EMPTY_MOM_STATE.valueMin
|
|
304
|
+
const momValueMax = momExtremes ? momExtremes.max + momPadding : EMPTY_MOM_STATE.valueMax
|
|
305
|
+
|
|
306
|
+
const kstRange = kstExtremes ? kstExtremes.max - kstExtremes.min : 0
|
|
307
|
+
const kstPadding = kstRange * 0.1
|
|
308
|
+
const kstValueMin = kstExtremes ? kstExtremes.min - kstPadding : EMPTY_KST_STATE.valueMin
|
|
309
|
+
const kstValueMax = kstExtremes ? kstExtremes.max + kstPadding : EMPTY_KST_STATE.valueMax
|
|
310
|
+
|
|
311
|
+
const atrValueMax = atrExtremes && Number.isFinite(atrExtremes.max)
|
|
312
|
+
? atrExtremes.max * 1.1
|
|
313
|
+
: EMPTY_ATR_STATE.valueMax
|
|
314
|
+
|
|
315
|
+
const maFamilyBounds = (ext: { min: number; max: number } | null, empty: { valueMin: number; valueMax: number }) => {
|
|
316
|
+
if (!ext || !Number.isFinite(ext.min) || !Number.isFinite(ext.max)) {
|
|
317
|
+
return { valueMin: empty.valueMin, valueMax: empty.valueMax }
|
|
318
|
+
}
|
|
319
|
+
const range = ext.max - ext.min
|
|
320
|
+
const padding = range > 0 ? range * 0.05 : Math.max(1, Math.abs(ext.max) * 0.05)
|
|
321
|
+
return { valueMin: ext.min - padding, valueMax: ext.max + padding }
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const wmaBounds = maFamilyBounds(wmaExtremes, EMPTY_WMA_STATE)
|
|
325
|
+
const demaBounds = maFamilyBounds(demaExtremes, EMPTY_DEMA_STATE)
|
|
326
|
+
const temaBounds = maFamilyBounds(temaExtremes, EMPTY_TEMA_STATE)
|
|
327
|
+
const hmaBounds = maFamilyBounds(hmaExtremes, EMPTY_HMA_STATE)
|
|
328
|
+
const kamaBounds = maFamilyBounds(kamaExtremes, EMPTY_KAMA_STATE)
|
|
329
|
+
const sarBounds = maFamilyBounds(sarExtremes, EMPTY_SAR_STATE)
|
|
330
|
+
const supertrendBounds = maFamilyBounds(supertrendExtremes, EMPTY_SUPERTREND_STATE)
|
|
331
|
+
const keltnerBounds = maFamilyBounds(keltnerExtremes, EMPTY_KELTNER_STATE)
|
|
332
|
+
const donchianBounds = maFamilyBounds(donchianExtremes, EMPTY_DONCHIAN_STATE)
|
|
333
|
+
const ichimokuBounds = maFamilyBounds(ichimokuExtremes, EMPTY_ICHIMOKU_STATE)
|
|
334
|
+
const rocBounds = maFamilyBounds(rocExtremes, EMPTY_ROC_STATE)
|
|
335
|
+
const trixCombinedMin = Math.min(
|
|
336
|
+
trixSeriesExtremes?.min ?? Infinity,
|
|
337
|
+
trixSignalExtremes?.min ?? Infinity,
|
|
338
|
+
)
|
|
339
|
+
const trixCombinedMax = Math.max(
|
|
340
|
+
trixSeriesExtremes?.max ?? -Infinity,
|
|
341
|
+
trixSignalExtremes?.max ?? -Infinity,
|
|
342
|
+
)
|
|
343
|
+
const trixBounds = maFamilyBounds(
|
|
344
|
+
Number.isFinite(trixCombinedMin) && Number.isFinite(trixCombinedMax)
|
|
345
|
+
? { min: trixCombinedMin, max: trixCombinedMax }
|
|
346
|
+
: null,
|
|
347
|
+
EMPTY_TRIX_STATE,
|
|
348
|
+
)
|
|
349
|
+
// HV and Parkinson are non-negative volatility series; pad upward only
|
|
350
|
+
const hvValueMax = hvExtremes && Number.isFinite(hvExtremes.max) ? hvExtremes.max * 1.1 : EMPTY_HV_STATE.valueMax
|
|
351
|
+
const parkinsonValueMax = parkinsonExtremes && Number.isFinite(parkinsonExtremes.max)
|
|
352
|
+
? parkinsonExtremes.max * 1.1
|
|
353
|
+
: EMPTY_PARKINSON_STATE.valueMax
|
|
354
|
+
const chaikinVolBounds = maFamilyBounds(chaikinVolExtremes, EMPTY_CHAIKIN_VOL_STATE)
|
|
355
|
+
const vmaValueMax = vmaExtremes && Number.isFinite(vmaExtremes.max) ? vmaExtremes.max * 1.1 : EMPTY_VMA_STATE.valueMax
|
|
356
|
+
const obvBounds = maFamilyBounds(obvExtremes, EMPTY_OBV_STATE)
|
|
357
|
+
const pvtBounds = maFamilyBounds(pvtExtremes, EMPTY_PVT_STATE)
|
|
358
|
+
const vwapBounds = maFamilyBounds(vwapExtremes, EMPTY_VWAP_STATE)
|
|
359
|
+
|
|
360
|
+
return {
|
|
361
|
+
rsi: rsiActive ? {
|
|
362
|
+
timestamp,
|
|
363
|
+
series: bundle.rsi.series,
|
|
364
|
+
enabledPeriods: bundle.rsi.enabledPeriods,
|
|
365
|
+
params: bundle.rsi.params,
|
|
366
|
+
valueMin: 0,
|
|
367
|
+
valueMax: 100,
|
|
368
|
+
visibleMin: rsiExtremes!.min,
|
|
369
|
+
visibleMax: rsiExtremes!.max,
|
|
370
|
+
} : mergeEmptyState(EMPTY_RSI_STATE, timestamp, {
|
|
371
|
+
series: bundle.rsi.series,
|
|
372
|
+
enabledPeriods: bundle.rsi.enabledPeriods,
|
|
373
|
+
params: bundle.rsi.params,
|
|
374
|
+
}),
|
|
375
|
+
cci: cciActive ? {
|
|
376
|
+
timestamp,
|
|
377
|
+
series: bundle.cci.series,
|
|
378
|
+
params: bundle.cci.params,
|
|
379
|
+
valueMin: cciValueMin,
|
|
380
|
+
valueMax: cciValueMax,
|
|
381
|
+
visibleMin: cciExtremes!.min,
|
|
382
|
+
visibleMax: cciExtremes!.max,
|
|
383
|
+
} : mergeEmptyState(EMPTY_CCI_STATE, timestamp, {
|
|
384
|
+
series: bundle.cci.series,
|
|
385
|
+
params: bundle.cci.params,
|
|
386
|
+
}),
|
|
387
|
+
stoch: stochActive ? {
|
|
388
|
+
timestamp,
|
|
389
|
+
series: bundle.stoch.series,
|
|
390
|
+
params: bundle.stoch.params,
|
|
391
|
+
valueMin: 0,
|
|
392
|
+
valueMax: 100,
|
|
393
|
+
visibleMin: stochExtremes!.min,
|
|
394
|
+
visibleMax: stochExtremes!.max,
|
|
395
|
+
} : mergeEmptyState(EMPTY_STOCH_STATE, timestamp, {
|
|
396
|
+
series: bundle.stoch.series,
|
|
397
|
+
params: bundle.stoch.params,
|
|
398
|
+
}),
|
|
399
|
+
mom: momActive ? {
|
|
400
|
+
timestamp,
|
|
401
|
+
series: bundle.mom.series,
|
|
402
|
+
params: bundle.mom.params,
|
|
403
|
+
valueMin: momValueMin,
|
|
404
|
+
valueMax: momValueMax,
|
|
405
|
+
visibleMin: momExtremes!.min,
|
|
406
|
+
visibleMax: momExtremes!.max,
|
|
407
|
+
} : mergeEmptyState(EMPTY_MOM_STATE, timestamp, {
|
|
408
|
+
series: bundle.mom.series,
|
|
409
|
+
params: bundle.mom.params,
|
|
410
|
+
}),
|
|
411
|
+
wmsr: wmsrActive ? {
|
|
412
|
+
timestamp,
|
|
413
|
+
series: bundle.wmsr.series,
|
|
414
|
+
params: bundle.wmsr.params,
|
|
415
|
+
valueMin: -100,
|
|
416
|
+
valueMax: 0,
|
|
417
|
+
visibleMin: wmsrExtremes!.min,
|
|
418
|
+
visibleMax: wmsrExtremes!.max,
|
|
419
|
+
} : mergeEmptyState(EMPTY_WMSR_STATE, timestamp, {
|
|
420
|
+
series: bundle.wmsr.series,
|
|
421
|
+
params: bundle.wmsr.params,
|
|
422
|
+
}),
|
|
423
|
+
kst: kstActive ? {
|
|
424
|
+
timestamp,
|
|
425
|
+
series: bundle.kst.series,
|
|
426
|
+
params: bundle.kst.params,
|
|
427
|
+
valueMin: kstValueMin,
|
|
428
|
+
valueMax: kstValueMax,
|
|
429
|
+
visibleMin: kstExtremes!.min,
|
|
430
|
+
visibleMax: kstExtremes!.max,
|
|
431
|
+
} : mergeEmptyState(EMPTY_KST_STATE, timestamp, {
|
|
432
|
+
series: bundle.kst.series,
|
|
433
|
+
params: bundle.kst.params,
|
|
434
|
+
}),
|
|
435
|
+
fastk: fastkActive ? {
|
|
436
|
+
timestamp,
|
|
437
|
+
series: bundle.fastk.series,
|
|
438
|
+
params: bundle.fastk.params,
|
|
439
|
+
valueMin: 0,
|
|
440
|
+
valueMax: 100,
|
|
441
|
+
visibleMin: fastkExtremes!.min,
|
|
442
|
+
visibleMax: fastkExtremes!.max,
|
|
443
|
+
} : mergeEmptyState(EMPTY_FASTK_STATE, timestamp, {
|
|
444
|
+
series: bundle.fastk.series,
|
|
445
|
+
params: bundle.fastk.params,
|
|
446
|
+
}),
|
|
447
|
+
macd: macdActive ? {
|
|
448
|
+
timestamp,
|
|
449
|
+
series: bundle.macd.series,
|
|
450
|
+
params: bundle.macd.params,
|
|
451
|
+
valueMin: macdValueMin,
|
|
452
|
+
valueMax: macdValueMax,
|
|
453
|
+
visibleMin: macdExtremes!.min,
|
|
454
|
+
visibleMax: macdExtremes!.max,
|
|
455
|
+
latestValues: latestPoint ? {
|
|
456
|
+
dif: latestPoint.dif,
|
|
457
|
+
dea: latestPoint.dea,
|
|
458
|
+
macd: latestPoint.macd,
|
|
459
|
+
} : undefined,
|
|
460
|
+
} : mergeEmptyState(EMPTY_MACD_STATE, timestamp, {
|
|
461
|
+
series: bundle.macd.series,
|
|
462
|
+
params: bundle.macd.params,
|
|
463
|
+
}),
|
|
464
|
+
atr: atrActive ? {
|
|
465
|
+
timestamp,
|
|
466
|
+
series: bundle.atr.series,
|
|
467
|
+
params: bundle.atr.params,
|
|
468
|
+
valueMin: 0,
|
|
469
|
+
valueMax: atrValueMax,
|
|
470
|
+
visibleMin: atrExtremes!.min,
|
|
471
|
+
visibleMax: atrExtremes!.max,
|
|
472
|
+
} : mergeEmptyState(EMPTY_ATR_STATE, timestamp, {
|
|
473
|
+
series: bundle.atr.series,
|
|
474
|
+
params: bundle.atr.params,
|
|
475
|
+
}),
|
|
476
|
+
wma: wmaActive ? {
|
|
477
|
+
timestamp,
|
|
478
|
+
series: bundle.wma.series,
|
|
479
|
+
params: bundle.wma.params,
|
|
480
|
+
valueMin: wmaBounds.valueMin,
|
|
481
|
+
valueMax: wmaBounds.valueMax,
|
|
482
|
+
visibleMin: wmaExtremes!.min,
|
|
483
|
+
visibleMax: wmaExtremes!.max,
|
|
484
|
+
} : mergeEmptyState(EMPTY_WMA_STATE, timestamp, {
|
|
485
|
+
series: bundle.wma.series,
|
|
486
|
+
params: bundle.wma.params,
|
|
487
|
+
}),
|
|
488
|
+
dema: demaActive ? {
|
|
489
|
+
timestamp,
|
|
490
|
+
series: bundle.dema.series,
|
|
491
|
+
params: bundle.dema.params,
|
|
492
|
+
valueMin: demaBounds.valueMin,
|
|
493
|
+
valueMax: demaBounds.valueMax,
|
|
494
|
+
visibleMin: demaExtremes!.min,
|
|
495
|
+
visibleMax: demaExtremes!.max,
|
|
496
|
+
} : mergeEmptyState(EMPTY_DEMA_STATE, timestamp, {
|
|
497
|
+
series: bundle.dema.series,
|
|
498
|
+
params: bundle.dema.params,
|
|
499
|
+
}),
|
|
500
|
+
tema: temaActive ? {
|
|
501
|
+
timestamp,
|
|
502
|
+
series: bundle.tema.series,
|
|
503
|
+
params: bundle.tema.params,
|
|
504
|
+
valueMin: temaBounds.valueMin,
|
|
505
|
+
valueMax: temaBounds.valueMax,
|
|
506
|
+
visibleMin: temaExtremes!.min,
|
|
507
|
+
visibleMax: temaExtremes!.max,
|
|
508
|
+
} : mergeEmptyState(EMPTY_TEMA_STATE, timestamp, {
|
|
509
|
+
series: bundle.tema.series,
|
|
510
|
+
params: bundle.tema.params,
|
|
511
|
+
}),
|
|
512
|
+
hma: hmaActive ? {
|
|
513
|
+
timestamp,
|
|
514
|
+
series: bundle.hma.series,
|
|
515
|
+
params: bundle.hma.params,
|
|
516
|
+
valueMin: hmaBounds.valueMin,
|
|
517
|
+
valueMax: hmaBounds.valueMax,
|
|
518
|
+
visibleMin: hmaExtremes!.min,
|
|
519
|
+
visibleMax: hmaExtremes!.max,
|
|
520
|
+
} : mergeEmptyState(EMPTY_HMA_STATE, timestamp, {
|
|
521
|
+
series: bundle.hma.series,
|
|
522
|
+
params: bundle.hma.params,
|
|
523
|
+
}),
|
|
524
|
+
kama: kamaActive ? {
|
|
525
|
+
timestamp,
|
|
526
|
+
series: bundle.kama.series,
|
|
527
|
+
params: bundle.kama.params,
|
|
528
|
+
valueMin: kamaBounds.valueMin,
|
|
529
|
+
valueMax: kamaBounds.valueMax,
|
|
530
|
+
visibleMin: kamaExtremes!.min,
|
|
531
|
+
visibleMax: kamaExtremes!.max,
|
|
532
|
+
} : mergeEmptyState(EMPTY_KAMA_STATE, timestamp, {
|
|
533
|
+
series: bundle.kama.series,
|
|
534
|
+
params: bundle.kama.params,
|
|
535
|
+
}),
|
|
536
|
+
sar: sarActive ? {
|
|
537
|
+
timestamp,
|
|
538
|
+
series: bundle.sar.series,
|
|
539
|
+
params: bundle.sar.params,
|
|
540
|
+
valueMin: sarBounds.valueMin,
|
|
541
|
+
valueMax: sarBounds.valueMax,
|
|
542
|
+
visibleMin: sarExtremes!.min,
|
|
543
|
+
visibleMax: sarExtremes!.max,
|
|
544
|
+
} : mergeEmptyState(EMPTY_SAR_STATE, timestamp, {
|
|
545
|
+
series: bundle.sar.series,
|
|
546
|
+
params: bundle.sar.params,
|
|
547
|
+
}),
|
|
548
|
+
supertrend: supertrendActive ? {
|
|
549
|
+
timestamp,
|
|
550
|
+
series: bundle.supertrend.series,
|
|
551
|
+
params: bundle.supertrend.params,
|
|
552
|
+
valueMin: supertrendBounds.valueMin,
|
|
553
|
+
valueMax: supertrendBounds.valueMax,
|
|
554
|
+
visibleMin: supertrendExtremes!.min,
|
|
555
|
+
visibleMax: supertrendExtremes!.max,
|
|
556
|
+
} : mergeEmptyState(EMPTY_SUPERTREND_STATE, timestamp, {
|
|
557
|
+
series: bundle.supertrend.series,
|
|
558
|
+
params: bundle.supertrend.params,
|
|
559
|
+
}),
|
|
560
|
+
keltner: keltnerActive ? {
|
|
561
|
+
timestamp,
|
|
562
|
+
series: bundle.keltner.series,
|
|
563
|
+
params: bundle.keltner.params,
|
|
564
|
+
valueMin: keltnerBounds.valueMin,
|
|
565
|
+
valueMax: keltnerBounds.valueMax,
|
|
566
|
+
visibleMin: keltnerExtremes!.min,
|
|
567
|
+
visibleMax: keltnerExtremes!.max,
|
|
568
|
+
} : mergeEmptyState(EMPTY_KELTNER_STATE, timestamp, {
|
|
569
|
+
series: bundle.keltner.series,
|
|
570
|
+
params: bundle.keltner.params,
|
|
571
|
+
}),
|
|
572
|
+
donchian: donchianActive ? {
|
|
573
|
+
timestamp,
|
|
574
|
+
series: bundle.donchian.series,
|
|
575
|
+
params: bundle.donchian.params,
|
|
576
|
+
valueMin: donchianBounds.valueMin,
|
|
577
|
+
valueMax: donchianBounds.valueMax,
|
|
578
|
+
visibleMin: donchianExtremes!.min,
|
|
579
|
+
visibleMax: donchianExtremes!.max,
|
|
580
|
+
} : mergeEmptyState(EMPTY_DONCHIAN_STATE, timestamp, {
|
|
581
|
+
series: bundle.donchian.series,
|
|
582
|
+
params: bundle.donchian.params,
|
|
583
|
+
}),
|
|
584
|
+
ichimoku: ichimokuActive ? {
|
|
585
|
+
timestamp,
|
|
586
|
+
series: bundle.ichimoku.series,
|
|
587
|
+
params: bundle.ichimoku.params,
|
|
588
|
+
valueMin: ichimokuBounds.valueMin,
|
|
589
|
+
valueMax: ichimokuBounds.valueMax,
|
|
590
|
+
visibleMin: ichimokuExtremes!.min,
|
|
591
|
+
visibleMax: ichimokuExtremes!.max,
|
|
592
|
+
} : mergeEmptyState(EMPTY_ICHIMOKU_STATE, timestamp, {
|
|
593
|
+
series: bundle.ichimoku.series,
|
|
594
|
+
params: bundle.ichimoku.params,
|
|
595
|
+
}),
|
|
596
|
+
roc: rocActive ? {
|
|
597
|
+
timestamp,
|
|
598
|
+
series: bundle.roc.series,
|
|
599
|
+
params: bundle.roc.params,
|
|
600
|
+
valueMin: rocBounds.valueMin,
|
|
601
|
+
valueMax: rocBounds.valueMax,
|
|
602
|
+
visibleMin: rocExtremes!.min,
|
|
603
|
+
visibleMax: rocExtremes!.max,
|
|
604
|
+
} : mergeEmptyState(EMPTY_ROC_STATE, timestamp, {
|
|
605
|
+
series: bundle.roc.series,
|
|
606
|
+
params: bundle.roc.params,
|
|
607
|
+
}),
|
|
608
|
+
trix: trixActive ? {
|
|
609
|
+
timestamp,
|
|
610
|
+
series: bundle.trix.series,
|
|
611
|
+
signalSeries: bundle.trix.signalSeries,
|
|
612
|
+
params: bundle.trix.params,
|
|
613
|
+
valueMin: trixBounds.valueMin,
|
|
614
|
+
valueMax: trixBounds.valueMax,
|
|
615
|
+
visibleMin: Math.min(trixSeriesExtremes?.min ?? Infinity, trixSignalExtremes?.min ?? Infinity),
|
|
616
|
+
visibleMax: Math.max(trixSeriesExtremes?.max ?? -Infinity, trixSignalExtremes?.max ?? -Infinity),
|
|
617
|
+
} : mergeEmptyState(EMPTY_TRIX_STATE, timestamp, {
|
|
618
|
+
series: bundle.trix.series,
|
|
619
|
+
signalSeries: bundle.trix.signalSeries,
|
|
620
|
+
params: bundle.trix.params,
|
|
621
|
+
}),
|
|
622
|
+
hv: hvActive ? {
|
|
623
|
+
timestamp,
|
|
624
|
+
series: bundle.hv.series,
|
|
625
|
+
params: bundle.hv.params,
|
|
626
|
+
valueMin: 0,
|
|
627
|
+
valueMax: hvValueMax,
|
|
628
|
+
visibleMin: hvExtremes!.min,
|
|
629
|
+
visibleMax: hvExtremes!.max,
|
|
630
|
+
} : mergeEmptyState(EMPTY_HV_STATE, timestamp, {
|
|
631
|
+
series: bundle.hv.series,
|
|
632
|
+
params: bundle.hv.params,
|
|
633
|
+
}),
|
|
634
|
+
parkinson: parkinsonActive ? {
|
|
635
|
+
timestamp,
|
|
636
|
+
series: bundle.parkinson.series,
|
|
637
|
+
params: bundle.parkinson.params,
|
|
638
|
+
valueMin: 0,
|
|
639
|
+
valueMax: parkinsonValueMax,
|
|
640
|
+
visibleMin: parkinsonExtremes!.min,
|
|
641
|
+
visibleMax: parkinsonExtremes!.max,
|
|
642
|
+
} : mergeEmptyState(EMPTY_PARKINSON_STATE, timestamp, {
|
|
643
|
+
series: bundle.parkinson.series,
|
|
644
|
+
params: bundle.parkinson.params,
|
|
645
|
+
}),
|
|
646
|
+
chaikinVol: chaikinVolActive ? {
|
|
647
|
+
timestamp,
|
|
648
|
+
series: bundle.chaikinVol.series,
|
|
649
|
+
params: bundle.chaikinVol.params,
|
|
650
|
+
valueMin: chaikinVolBounds.valueMin,
|
|
651
|
+
valueMax: chaikinVolBounds.valueMax,
|
|
652
|
+
visibleMin: chaikinVolExtremes!.min,
|
|
653
|
+
visibleMax: chaikinVolExtremes!.max,
|
|
654
|
+
} : mergeEmptyState(EMPTY_CHAIKIN_VOL_STATE, timestamp, {
|
|
655
|
+
series: bundle.chaikinVol.series,
|
|
656
|
+
params: bundle.chaikinVol.params,
|
|
657
|
+
}),
|
|
658
|
+
vma: vmaActive ? {
|
|
659
|
+
timestamp,
|
|
660
|
+
series: bundle.vma.series,
|
|
661
|
+
params: bundle.vma.params,
|
|
662
|
+
valueMin: 0,
|
|
663
|
+
valueMax: vmaValueMax,
|
|
664
|
+
visibleMin: vmaExtremes!.min,
|
|
665
|
+
visibleMax: vmaExtremes!.max,
|
|
666
|
+
} : mergeEmptyState(EMPTY_VMA_STATE, timestamp, {
|
|
667
|
+
series: bundle.vma.series,
|
|
668
|
+
params: bundle.vma.params,
|
|
669
|
+
}),
|
|
670
|
+
obv: obvActive ? {
|
|
671
|
+
timestamp,
|
|
672
|
+
series: bundle.obv.series,
|
|
673
|
+
params: bundle.obv.params,
|
|
674
|
+
valueMin: obvBounds.valueMin,
|
|
675
|
+
valueMax: obvBounds.valueMax,
|
|
676
|
+
visibleMin: obvExtremes!.min,
|
|
677
|
+
visibleMax: obvExtremes!.max,
|
|
678
|
+
} : mergeEmptyState(EMPTY_OBV_STATE, timestamp, {
|
|
679
|
+
series: bundle.obv.series,
|
|
680
|
+
params: bundle.obv.params,
|
|
681
|
+
}),
|
|
682
|
+
pvt: pvtActive ? {
|
|
683
|
+
timestamp,
|
|
684
|
+
series: bundle.pvt.series,
|
|
685
|
+
params: bundle.pvt.params,
|
|
686
|
+
valueMin: pvtBounds.valueMin,
|
|
687
|
+
valueMax: pvtBounds.valueMax,
|
|
688
|
+
visibleMin: pvtExtremes!.min,
|
|
689
|
+
visibleMax: pvtExtremes!.max,
|
|
690
|
+
} : mergeEmptyState(EMPTY_PVT_STATE, timestamp, {
|
|
691
|
+
series: bundle.pvt.series,
|
|
692
|
+
params: bundle.pvt.params,
|
|
693
|
+
}),
|
|
694
|
+
vwap: vwapActive ? {
|
|
695
|
+
timestamp,
|
|
696
|
+
series: bundle.vwap.series,
|
|
697
|
+
params: bundle.vwap.params,
|
|
698
|
+
valueMin: vwapBounds.valueMin,
|
|
699
|
+
valueMax: vwapBounds.valueMax,
|
|
700
|
+
visibleMin: vwapExtremes!.min,
|
|
701
|
+
visibleMax: vwapExtremes!.max,
|
|
702
|
+
} : mergeEmptyState(EMPTY_VWAP_STATE, timestamp, {
|
|
703
|
+
series: bundle.vwap.series,
|
|
704
|
+
params: bundle.vwap.params,
|
|
705
|
+
}),
|
|
706
|
+
cmf: cmfActive ? {
|
|
707
|
+
timestamp,
|
|
708
|
+
series: bundle.cmf.series,
|
|
709
|
+
params: bundle.cmf.params,
|
|
710
|
+
valueMin: -1,
|
|
711
|
+
valueMax: 1,
|
|
712
|
+
visibleMin: cmfExtremes!.min,
|
|
713
|
+
visibleMax: cmfExtremes!.max,
|
|
714
|
+
} : mergeEmptyState(EMPTY_CMF_STATE, timestamp, {
|
|
715
|
+
series: bundle.cmf.series,
|
|
716
|
+
params: bundle.cmf.params,
|
|
717
|
+
}),
|
|
718
|
+
mfi: mfiActive ? {
|
|
719
|
+
timestamp,
|
|
720
|
+
series: bundle.mfi.series,
|
|
721
|
+
params: bundle.mfi.params,
|
|
722
|
+
valueMin: 0,
|
|
723
|
+
valueMax: 100,
|
|
724
|
+
visibleMin: mfiExtremes!.min,
|
|
725
|
+
visibleMax: mfiExtremes!.max,
|
|
726
|
+
} : mergeEmptyState(EMPTY_MFI_STATE, timestamp, {
|
|
727
|
+
series: bundle.mfi.series,
|
|
728
|
+
params: bundle.mfi.params,
|
|
729
|
+
}),
|
|
730
|
+
pivot: pivotActive ? {
|
|
731
|
+
timestamp,
|
|
732
|
+
series: bundle.pivot.series,
|
|
733
|
+
params: bundle.pivot.params,
|
|
734
|
+
valueMin: pivotExtremes!.min,
|
|
735
|
+
valueMax: pivotExtremes!.max,
|
|
736
|
+
visibleMin: pivotExtremes!.min,
|
|
737
|
+
visibleMax: pivotExtremes!.max,
|
|
738
|
+
} : mergeEmptyState(EMPTY_PIVOT_STATE, timestamp, {
|
|
739
|
+
series: bundle.pivot.series,
|
|
740
|
+
params: bundle.pivot.params,
|
|
741
|
+
}),
|
|
742
|
+
fib: fibActive ? {
|
|
743
|
+
timestamp,
|
|
744
|
+
series: bundle.fib.series,
|
|
745
|
+
params: bundle.fib.params,
|
|
746
|
+
valueMin: fibExtremes!.min,
|
|
747
|
+
valueMax: fibExtremes!.max,
|
|
748
|
+
visibleMin: fibExtremes!.min,
|
|
749
|
+
visibleMax: fibExtremes!.max,
|
|
750
|
+
} : mergeEmptyState(EMPTY_FIB_STATE, timestamp, {
|
|
751
|
+
series: bundle.fib.series,
|
|
752
|
+
params: bundle.fib.params,
|
|
753
|
+
}),
|
|
754
|
+
structure: structureActive ? {
|
|
755
|
+
timestamp,
|
|
756
|
+
series: bundle.structure.series,
|
|
757
|
+
params: bundle.structure.params,
|
|
758
|
+
valueMin: 0,
|
|
759
|
+
valueMax: 1,
|
|
760
|
+
visibleMin: 0,
|
|
761
|
+
visibleMax: 1,
|
|
762
|
+
} : mergeEmptyState(EMPTY_STRUCTURE_STATE, timestamp, {
|
|
763
|
+
series: bundle.structure.series,
|
|
764
|
+
params: bundle.structure.params,
|
|
765
|
+
}),
|
|
766
|
+
zones: zonesActive ? {
|
|
767
|
+
timestamp,
|
|
768
|
+
series: bundle.zones.series,
|
|
769
|
+
params: bundle.zones.params,
|
|
770
|
+
valueMin: 0,
|
|
771
|
+
valueMax: 1,
|
|
772
|
+
visibleMin: 0,
|
|
773
|
+
visibleMax: 1,
|
|
774
|
+
} : mergeEmptyState(EMPTY_ZONES_STATE, timestamp, {
|
|
775
|
+
series: bundle.zones.series,
|
|
776
|
+
params: bundle.zones.params,
|
|
777
|
+
}),
|
|
778
|
+
volumeProfile: vpActive ? {
|
|
779
|
+
timestamp,
|
|
780
|
+
series: bundle.volumeProfile.series,
|
|
781
|
+
params: bundle.volumeProfile.params,
|
|
782
|
+
valueMin: bundle.volumeProfile.series.bins[0]?.priceLow ?? 0,
|
|
783
|
+
valueMax: bundle.volumeProfile.series.bins[bundle.volumeProfile.series.bins.length - 1]?.priceHigh ?? 1,
|
|
784
|
+
visibleMin: bundle.volumeProfile.series.val,
|
|
785
|
+
visibleMax: bundle.volumeProfile.series.vah,
|
|
786
|
+
} : mergeEmptyState(EMPTY_VOLUME_PROFILE_STATE, timestamp, {
|
|
787
|
+
series: bundle.volumeProfile.series,
|
|
788
|
+
params: bundle.volumeProfile.params,
|
|
789
|
+
}),
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* 从 series bundle 组装所有 render states
|
|
795
|
+
* 同时计算 visibleMin/visibleMax 等派生字段
|
|
796
|
+
*/
|
|
797
|
+
export function composeRenderStates(
|
|
798
|
+
bundle: IndicatorSeriesBundle,
|
|
799
|
+
visibleRange: VisibleRange,
|
|
800
|
+
timestamp: number
|
|
801
|
+
): ComposedRenderStates {
|
|
802
|
+
const maExtremes = calcMAExtremes(bundle.ma.series, visibleRange)
|
|
803
|
+
const bollExtremes = calcBOLLExtremes(bundle.boll.series, visibleRange)
|
|
804
|
+
const expmaExtremes = calcEXPMAExtremes(bundle.expma.series, visibleRange)
|
|
805
|
+
const eneExtremes = calcENEExtremes(bundle.ene.series, visibleRange)
|
|
806
|
+
const subStates = composeVisibleSubIndicatorStates(bundle, visibleRange, timestamp)
|
|
807
|
+
|
|
808
|
+
return {
|
|
809
|
+
ma: {
|
|
810
|
+
timestamp,
|
|
811
|
+
series: bundle.ma.series,
|
|
812
|
+
enabledPeriods: bundle.ma.enabledPeriods,
|
|
813
|
+
visibleMin: maExtremes.min,
|
|
814
|
+
visibleMax: maExtremes.max,
|
|
815
|
+
},
|
|
816
|
+
boll: {
|
|
817
|
+
timestamp,
|
|
818
|
+
series: bundle.boll.series,
|
|
819
|
+
params: bundle.boll.params,
|
|
820
|
+
visibleMin: bollExtremes.min,
|
|
821
|
+
visibleMax: bollExtremes.max,
|
|
822
|
+
},
|
|
823
|
+
expma: {
|
|
824
|
+
timestamp,
|
|
825
|
+
series: bundle.expma.series,
|
|
826
|
+
params: bundle.expma.params,
|
|
827
|
+
visibleMin: expmaExtremes.min,
|
|
828
|
+
visibleMax: expmaExtremes.max,
|
|
829
|
+
},
|
|
830
|
+
ene: {
|
|
831
|
+
timestamp,
|
|
832
|
+
series: bundle.ene.series,
|
|
833
|
+
params: bundle.ene.params,
|
|
834
|
+
visibleMin: eneExtremes.min,
|
|
835
|
+
visibleMax: eneExtremes.max,
|
|
836
|
+
},
|
|
837
|
+
...subStates,
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
// ============================================================================
|
|
842
|
+
// 极值计算辅助函数
|
|
843
|
+
// ============================================================================
|
|
844
|
+
|
|
845
|
+
function calcMAExtremes(series: Record<number, (number | undefined)[]>, range: VisibleRange): { min: number; max: number } {
|
|
846
|
+
const seriesList = Object.values(series)
|
|
847
|
+
if (seriesList.length === 0 || range.start >= seriesList[0]!.length) {
|
|
848
|
+
return { min: Infinity, max: -Infinity }
|
|
849
|
+
}
|
|
850
|
+
let min = Infinity
|
|
851
|
+
let max = -Infinity
|
|
852
|
+
for (const values of seriesList) {
|
|
853
|
+
const end = Math.min(range.end, values.length)
|
|
854
|
+
for (let i = range.start; i < end; i++) {
|
|
855
|
+
const v = values[i]
|
|
856
|
+
if (v !== undefined) {
|
|
857
|
+
min = Math.min(min, v)
|
|
858
|
+
max = Math.max(max, v)
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return { min, max }
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
interface BOLLPoint { upper: number; middle: number; lower: number }
|
|
866
|
+
function calcBOLLExtremes(series: BOLLPoint[], range: VisibleRange): { min: number; max: number } {
|
|
867
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
868
|
+
return { min: Infinity, max: -Infinity }
|
|
869
|
+
}
|
|
870
|
+
let min = Infinity
|
|
871
|
+
let max = -Infinity
|
|
872
|
+
const end = Math.min(range.end, series.length)
|
|
873
|
+
for (let i = range.start; i < end; i++) {
|
|
874
|
+
const p = series[i]
|
|
875
|
+
if (p) {
|
|
876
|
+
min = Math.min(min, p.upper, p.middle, p.lower)
|
|
877
|
+
max = Math.max(max, p.upper, p.middle, p.lower)
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return { min, max }
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
interface EXPMAPoint { fast: number; slow: number }
|
|
884
|
+
function calcEXPMAExtremes(series: EXPMAPoint[], range: VisibleRange): { min: number; max: number } {
|
|
885
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
886
|
+
return { min: Infinity, max: -Infinity }
|
|
887
|
+
}
|
|
888
|
+
let min = Infinity
|
|
889
|
+
let max = -Infinity
|
|
890
|
+
const end = Math.min(range.end, series.length)
|
|
891
|
+
for (let i = range.start; i < end; i++) {
|
|
892
|
+
const p = series[i]
|
|
893
|
+
if (p) {
|
|
894
|
+
min = Math.min(min, p.fast, p.slow)
|
|
895
|
+
max = Math.max(max, p.fast, p.slow)
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return { min, max }
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
interface ENEPoint { upper: number; middle: number; lower: number }
|
|
902
|
+
function calcENEExtremes(series: ENEPoint[], range: VisibleRange): { min: number; max: number } {
|
|
903
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
904
|
+
return { min: Infinity, max: -Infinity }
|
|
905
|
+
}
|
|
906
|
+
let min = Infinity
|
|
907
|
+
let max = -Infinity
|
|
908
|
+
const end = Math.min(range.end, series.length)
|
|
909
|
+
for (let i = range.start; i < end; i++) {
|
|
910
|
+
const p = series[i]
|
|
911
|
+
if (p) {
|
|
912
|
+
min = Math.min(min, p.upper, p.middle, p.lower)
|
|
913
|
+
max = Math.max(max, p.upper, p.middle, p.lower)
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return { min, max }
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function calcRSIExtremes(series: Record<number, (number | undefined)[]>, range: VisibleRange): { min: number; max: number } {
|
|
920
|
+
const seriesList = Object.values(series)
|
|
921
|
+
if (seriesList.length === 0 || range.start >= seriesList[0]!.length) {
|
|
922
|
+
return { min: Infinity, max: -Infinity }
|
|
923
|
+
}
|
|
924
|
+
let min = Infinity
|
|
925
|
+
let max = -Infinity
|
|
926
|
+
for (const values of seriesList) {
|
|
927
|
+
const end = Math.min(range.end, values.length)
|
|
928
|
+
for (let i = range.start; i < end; i++) {
|
|
929
|
+
const v = values[i]
|
|
930
|
+
if (v !== undefined) {
|
|
931
|
+
min = Math.min(min, v)
|
|
932
|
+
max = Math.max(max, v)
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return { min, max }
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
function calcCCIExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
940
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
941
|
+
return { min: Infinity, max: -Infinity }
|
|
942
|
+
}
|
|
943
|
+
let min = Infinity
|
|
944
|
+
let max = -Infinity
|
|
945
|
+
const end = Math.min(range.end, series.length)
|
|
946
|
+
for (let i = range.start; i < end; i++) {
|
|
947
|
+
const v = series[i]
|
|
948
|
+
if (v !== undefined) {
|
|
949
|
+
min = Math.min(min, v)
|
|
950
|
+
max = Math.max(max, v)
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
return { min, max }
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
interface STOCHPoint { k: number; d: number }
|
|
957
|
+
function calcSTOCHExtremes(series: STOCHPoint[], range: VisibleRange): { min: number; max: number } {
|
|
958
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
959
|
+
return { min: Infinity, max: -Infinity }
|
|
960
|
+
}
|
|
961
|
+
let min = Infinity
|
|
962
|
+
let max = -Infinity
|
|
963
|
+
const end = Math.min(range.end, series.length)
|
|
964
|
+
for (let i = range.start; i < end; i++) {
|
|
965
|
+
const p = series[i]
|
|
966
|
+
if (p) {
|
|
967
|
+
min = Math.min(min, p.k, p.d)
|
|
968
|
+
max = Math.max(max, p.k, p.d)
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
return { min, max }
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
function calcMOMExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
975
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
976
|
+
return { min: Infinity, max: -Infinity }
|
|
977
|
+
}
|
|
978
|
+
let min = Infinity
|
|
979
|
+
let max = -Infinity
|
|
980
|
+
const end = Math.min(range.end, series.length)
|
|
981
|
+
for (let i = range.start; i < end; i++) {
|
|
982
|
+
const v = series[i]
|
|
983
|
+
if (v !== undefined) {
|
|
984
|
+
min = Math.min(min, v)
|
|
985
|
+
max = Math.max(max, v)
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
return { min, max }
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function calcWMSRExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
992
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
993
|
+
return { min: Infinity, max: -Infinity }
|
|
994
|
+
}
|
|
995
|
+
let min = Infinity
|
|
996
|
+
let max = -Infinity
|
|
997
|
+
const end = Math.min(range.end, series.length)
|
|
998
|
+
for (let i = range.start; i < end; i++) {
|
|
999
|
+
const v = series[i]
|
|
1000
|
+
if (v !== undefined) {
|
|
1001
|
+
min = Math.min(min, v)
|
|
1002
|
+
max = Math.max(max, v)
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return { min, max }
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
interface KSTPoint { kst: number; signal: number }
|
|
1009
|
+
function calcKSTExtremes(series: KSTPoint[], range: VisibleRange): { min: number; max: number } {
|
|
1010
|
+
// 快速检查:空数据直接返回
|
|
1011
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
1012
|
+
return { min: Infinity, max: -Infinity }
|
|
1013
|
+
}
|
|
1014
|
+
let min = Infinity
|
|
1015
|
+
let max = -Infinity
|
|
1016
|
+
const end = Math.min(range.end, series.length)
|
|
1017
|
+
for (let i = range.start; i < end; i++) {
|
|
1018
|
+
const p = series[i]
|
|
1019
|
+
if (p) {
|
|
1020
|
+
min = Math.min(min, p.kst, p.signal)
|
|
1021
|
+
max = Math.max(max, p.kst, p.signal)
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return { min, max }
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
function calcFASTKExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1028
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
1029
|
+
return { min: Infinity, max: -Infinity }
|
|
1030
|
+
}
|
|
1031
|
+
let min = Infinity
|
|
1032
|
+
let max = -Infinity
|
|
1033
|
+
const end = Math.min(range.end, series.length)
|
|
1034
|
+
for (let i = range.start; i < end; i++) {
|
|
1035
|
+
const v = series[i]
|
|
1036
|
+
if (v !== undefined) {
|
|
1037
|
+
min = Math.min(min, v)
|
|
1038
|
+
max = Math.max(max, v)
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return { min, max }
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
interface MACDPoint { dif: number; dea: number; macd: number }
|
|
1045
|
+
function calcMACDExtremes(series: MACDPoint[], range: VisibleRange): { min: number; max: number } {
|
|
1046
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
1047
|
+
return { min: Infinity, max: -Infinity }
|
|
1048
|
+
}
|
|
1049
|
+
let min = Infinity
|
|
1050
|
+
let max = -Infinity
|
|
1051
|
+
const end = Math.min(range.end, series.length)
|
|
1052
|
+
for (let i = range.start; i < end; i++) {
|
|
1053
|
+
const p = series[i]
|
|
1054
|
+
if (p) {
|
|
1055
|
+
min = Math.min(min, p.dif, p.dea, p.macd)
|
|
1056
|
+
max = Math.max(max, p.dif, p.dea, p.macd)
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return { min, max }
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function calcATRExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1063
|
+
return calcSparseExtremes(series, range)
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
interface PivotPointShape {
|
|
1067
|
+
pp: number
|
|
1068
|
+
r1: number
|
|
1069
|
+
r2: number
|
|
1070
|
+
r3: number
|
|
1071
|
+
s1: number
|
|
1072
|
+
s2: number
|
|
1073
|
+
s3: number
|
|
1074
|
+
}
|
|
1075
|
+
function calcPivotExtremes(series: (PivotPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1076
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
1077
|
+
return { min: Infinity, max: -Infinity }
|
|
1078
|
+
}
|
|
1079
|
+
let min = Infinity
|
|
1080
|
+
let max = -Infinity
|
|
1081
|
+
const end = Math.min(range.end, series.length)
|
|
1082
|
+
for (let i = range.start; i < end; i++) {
|
|
1083
|
+
const p = series[i]
|
|
1084
|
+
if (!p) continue
|
|
1085
|
+
for (const v of [p.pp, p.r1, p.r2, p.r3, p.s1, p.s2, p.s3]) {
|
|
1086
|
+
if (v < min) min = v
|
|
1087
|
+
if (v > max) max = v
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
return { min, max }
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
interface FibPointShape {
|
|
1094
|
+
high: number
|
|
1095
|
+
low: number
|
|
1096
|
+
level236: number
|
|
1097
|
+
level382: number
|
|
1098
|
+
level500: number
|
|
1099
|
+
level618: number
|
|
1100
|
+
level786: number
|
|
1101
|
+
}
|
|
1102
|
+
function calcFibExtremes(series: (FibPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1103
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
1104
|
+
return { min: Infinity, max: -Infinity }
|
|
1105
|
+
}
|
|
1106
|
+
let min = Infinity
|
|
1107
|
+
let max = -Infinity
|
|
1108
|
+
const end = Math.min(range.end, series.length)
|
|
1109
|
+
for (let i = range.start; i < end; i++) {
|
|
1110
|
+
const p = series[i]
|
|
1111
|
+
if (!p) continue
|
|
1112
|
+
if (p.low < min) min = p.low
|
|
1113
|
+
if (p.high > max) max = p.high
|
|
1114
|
+
}
|
|
1115
|
+
return { min, max }
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
interface IchimokuPointShape {
|
|
1119
|
+
tenkan?: number
|
|
1120
|
+
kijun?: number
|
|
1121
|
+
spanA?: number
|
|
1122
|
+
spanB?: number
|
|
1123
|
+
chikou?: number
|
|
1124
|
+
}
|
|
1125
|
+
function calcIchimokuExtremes(series: (IchimokuPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1126
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
1127
|
+
return { min: Infinity, max: -Infinity }
|
|
1128
|
+
}
|
|
1129
|
+
let min = Infinity
|
|
1130
|
+
let max = -Infinity
|
|
1131
|
+
const end = Math.min(range.end, series.length)
|
|
1132
|
+
for (let i = range.start; i < end; i++) {
|
|
1133
|
+
const p = series[i]
|
|
1134
|
+
if (!p) continue
|
|
1135
|
+
for (const field of [p.tenkan, p.kijun, p.spanA, p.spanB, p.chikou]) {
|
|
1136
|
+
if (field !== undefined) {
|
|
1137
|
+
if (field < min) min = field
|
|
1138
|
+
if (field > max) max = field
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
return { min, max }
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
interface BandPointShape { upper: number; middle: number; lower: number }
|
|
1146
|
+
function calcBandExtremes(series: (BandPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1147
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
1148
|
+
return { min: Infinity, max: -Infinity }
|
|
1149
|
+
}
|
|
1150
|
+
let min = Infinity
|
|
1151
|
+
let max = -Infinity
|
|
1152
|
+
const end = Math.min(range.end, series.length)
|
|
1153
|
+
for (let i = range.start; i < end; i++) {
|
|
1154
|
+
const p = series[i]
|
|
1155
|
+
if (p) {
|
|
1156
|
+
min = Math.min(min, p.lower)
|
|
1157
|
+
max = Math.max(max, p.upper)
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return { min, max }
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
interface SARPointShape { value: number; trend: 'up' | 'down' }
|
|
1164
|
+
function calcSARExtremes(series: (SARPointShape | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1165
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
1166
|
+
return { min: Infinity, max: -Infinity }
|
|
1167
|
+
}
|
|
1168
|
+
let min = Infinity
|
|
1169
|
+
let max = -Infinity
|
|
1170
|
+
const end = Math.min(range.end, series.length)
|
|
1171
|
+
for (let i = range.start; i < end; i++) {
|
|
1172
|
+
const p = series[i]
|
|
1173
|
+
if (p) {
|
|
1174
|
+
min = Math.min(min, p.value)
|
|
1175
|
+
max = Math.max(max, p.value)
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
return { min, max }
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
function calcSparseExtremes(series: (number | undefined)[], range: VisibleRange): { min: number; max: number } {
|
|
1182
|
+
if (series.length === 0 || range.start >= series.length) {
|
|
1183
|
+
return { min: Infinity, max: -Infinity }
|
|
1184
|
+
}
|
|
1185
|
+
let min = Infinity
|
|
1186
|
+
let max = -Infinity
|
|
1187
|
+
const end = Math.min(range.end, series.length)
|
|
1188
|
+
for (let i = range.start; i < end; i++) {
|
|
1189
|
+
const v = series[i]
|
|
1190
|
+
if (v !== undefined) {
|
|
1191
|
+
min = Math.min(min, v)
|
|
1192
|
+
max = Math.max(max, v)
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return { min, max }
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/**
|
|
1199
|
+
* 计算主图指标价格范围
|
|
1200
|
+
* 用于 Chart.draw() 中的 pane.updateRange
|
|
1201
|
+
*/
|
|
1202
|
+
export function computeMainIndicatorPriceRange(
|
|
1203
|
+
bundle: IndicatorSeriesBundle,
|
|
1204
|
+
visibleRange: VisibleRange,
|
|
1205
|
+
activeMainIndicators: Set<string>
|
|
1206
|
+
): { min: number; max: number } | null {
|
|
1207
|
+
let min = Infinity
|
|
1208
|
+
let max = -Infinity
|
|
1209
|
+
const { start, end } = visibleRange
|
|
1210
|
+
|
|
1211
|
+
// MA
|
|
1212
|
+
if (activeMainIndicators.has('ma') && Object.keys(bundle.ma.series).length > 0) {
|
|
1213
|
+
for (const values of Object.values(bundle.ma.series)) {
|
|
1214
|
+
for (let i = start; i < end && i < values.length; i++) {
|
|
1215
|
+
const v = values[i]
|
|
1216
|
+
if (v !== undefined) {
|
|
1217
|
+
min = Math.min(min, v)
|
|
1218
|
+
max = Math.max(max, v)
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
// BOLL
|
|
1225
|
+
if (activeMainIndicators.has('boll') && bundle.boll.series.length > 0) {
|
|
1226
|
+
for (let i = start; i < end && i < bundle.boll.series.length; i++) {
|
|
1227
|
+
const p = bundle.boll.series[i]
|
|
1228
|
+
if (p) {
|
|
1229
|
+
min = Math.min(min, p.upper, p.middle, p.lower)
|
|
1230
|
+
max = Math.max(max, p.upper, p.middle, p.lower)
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// EXPMA
|
|
1236
|
+
if (activeMainIndicators.has('expma') && bundle.expma.series.length > 0) {
|
|
1237
|
+
for (let i = start; i < end && i < bundle.expma.series.length; i++) {
|
|
1238
|
+
const p = bundle.expma.series[i]
|
|
1239
|
+
if (p) {
|
|
1240
|
+
min = Math.min(min, p.fast, p.slow)
|
|
1241
|
+
max = Math.max(max, p.fast, p.slow)
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// ENE
|
|
1247
|
+
if (activeMainIndicators.has('ene') && bundle.ene.series.length > 0) {
|
|
1248
|
+
for (let i = start; i < end && i < bundle.ene.series.length; i++) {
|
|
1249
|
+
const p = bundle.ene.series[i]
|
|
1250
|
+
if (p) {
|
|
1251
|
+
min = Math.min(min, p.upper, p.middle, p.lower)
|
|
1252
|
+
max = Math.max(max, p.upper, p.middle, p.lower)
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
if (!Number.isFinite(min) || !Number.isFinite(max)) {
|
|
1258
|
+
return null
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
return { min, max }
|
|
1262
|
+
}
|