dexbot 1.6.7 → 1.6.8
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/CHANGELOG.md +49 -1
- package/README.md +3 -3
- package/analysis/README.md +2 -3
- package/analysis/tradingview/README.md +78 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +4 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
- package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
- package/dist/analysis/tradingview/grid_reset_config.js +235 -0
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
- package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
- package/dist/dexbot.js +22 -6
- package/dist/market_adapter/core/market_adapter_service.js +14 -2
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
- package/dist/market_adapter/inputs/window_cache.js +302 -48
- package/dist/market_adapter/market_adapter.d.ts +8 -1
- package/dist/market_adapter/market_adapter.js +22 -4
- package/dist/modules/account_bots.js +10 -0
- package/dist/modules/account_orders.d.ts +24 -2
- package/dist/modules/account_orders.js +41 -4
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.js +1 -0
- package/dist/modules/constants.d.ts +11 -3
- package/dist/modules/constants.js +116 -37
- package/dist/modules/dexbot_class.d.ts +6 -76
- package/dist/modules/dexbot_class.js +0 -32
- package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
- package/dist/modules/dexbot_cow_runtime.js +4 -87
- package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -1
- package/dist/modules/dexbot_maintenance_runtime.js +59 -11
- package/dist/modules/dexbot_startup_runtime.js +73 -20
- package/dist/modules/dexbot_state_recovery.d.ts +6 -0
- package/dist/modules/dexbot_state_recovery.js +21 -0
- package/dist/modules/order/async_lock.d.ts +8 -0
- package/dist/modules/order/async_lock.js +15 -0
- package/dist/modules/order/genesis_policy.d.ts +162 -0
- package/dist/modules/order/genesis_policy.js +267 -0
- package/dist/modules/order/grid.js +76 -134
- package/dist/modules/order/grid_reconcile.d.ts +9 -0
- package/dist/modules/order/grid_reconcile.js +13 -4
- package/dist/modules/order/grid_reconcile_internal.js +2 -2
- package/dist/modules/order/manager.d.ts +4 -0
- package/dist/modules/order/manager.js +14 -1
- package/dist/modules/order/sync_engine.d.ts +19 -0
- package/dist/modules/order/sync_engine.js +284 -344
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +64 -1
- package/dist/modules/order/utils/order.d.ts +43 -58
- package/dist/modules/order/utils/order.js +220 -197
- package/dist/modules/order/utils/system.js +8 -1
- package/dist/modules/paths.d.ts +1 -0
- package/dist/modules/paths.js +1 -0
- package/dist/modules/version_notice.d.ts +165 -0
- package/dist/modules/version_notice.js +364 -0
- package/dist/pm2.js +9 -0
- package/dist/unlock.js +28 -0
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +3 -2
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +20 -19
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +149 -31
- package/docs/GRID_RECALCULATION.md +12 -0
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +1 -1
- package/modules/README.md +18 -1
- package/package.json +13 -5
- package/scripts/README.md +28 -2
- package/scripts/clear-all.sh +13 -4
- package/scripts/clear-logs.sh +13 -4
- package/scripts/clear-market-adapter.sh +6 -0
- package/scripts/clear-orders.sh +5 -0
- package/scripts/lib/dexbot-paths.sh +108 -0
- package/tests/README.md +11 -3
- package/analysis/account_resolver.ts +0 -161
- package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
- package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
- package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
- package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
- package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
- package/analysis/analyze_dynamic_weight.ts +0 -243
- package/analysis/analyze_kalman.ts +0 -157
- package/analysis/analyze_regime.ts +0 -158
- package/analysis/analyze_regime_windows.ts +0 -470
- package/analysis/analyze_risk_profile.ts +0 -199
- package/analysis/analyze_trade_heatmap.ts +0 -362
- package/analysis/analyze_volatility.ts +0 -182
- package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
- package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
- package/analysis/bot_fitting/shared_utils.ts +0 -52
- package/analysis/bot_key_utils.ts +0 -426
- package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
- package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
- package/analysis/chain_pool.ts +0 -47
- package/analysis/chart_css.ts +0 -62
- package/analysis/chart_ui.ts +0 -105
- package/analysis/chart_utils.ts +0 -210
- package/analysis/fills_source.ts +0 -228
- package/analysis/grid_correction_check.ts +0 -786
- package/analysis/math_utils.ts +0 -53
- package/analysis/price_sources.ts +0 -136
- package/analysis/resolve_bot_accounts.ts +0 -199
- package/analysis/resolve_source.ts +0 -99
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
- package/analysis/trade_profitability.ts +0 -1335
- package/analysis/tradingview/analyze_tradingview.ts +0 -280
- package/analysis/tradingview/h-bts_tradingview.html +0 -1570
- package/analysis/tradingview/t-bts_tradingview.html +0 -1570
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
- package/analysis/trend_detection/hurst_analyzer.ts +0 -7
- package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
- package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
- package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
- package/analysis/trend_detection/package.json +0 -23
- package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
- package/analysis/trend_detection/regime_chart_generator.ts +0 -338
- package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
- package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
- package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
- package/analysis/tsconfig.json +0 -29
- package/claw/tests/package.json +0 -3
- package/claw/tests/test_claw_bridge.ts +0 -570
- package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
- package/claw/tests/test_claw_chain_layer.ts +0 -739
- package/claw/tests/test_claw_data_flow.ts +0 -525
- package/claw/tests/test_claw_domain_logic.ts +0 -471
- package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
- package/claw/tests/test_claw_mcp_transport.ts +0 -243
- package/claw/tests/test_claw_regressions.ts +0 -711
- package/claw/tests/test_claw_skill_generation.ts +0 -103
- package/claw/tests/test_claw_state_store.ts +0 -44
- package/claw/tests/test_dexbot_profiles.ts +0 -654
- package/claw/tests/test_memu_bridge.ts +0 -189
- package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
- package/claw/tests/test_position_health.ts +0 -343
- package/claw/tests/test_position_manager.ts +0 -429
- package/claw/tests/test_position_manager_watch_health.ts +0 -100
- package/claw/tests/test_short_mpa_strategy.ts +0 -232
- package/dist/analysis/account_resolver.d.ts.map +0 -1
- package/dist/analysis/account_resolver.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/chain_pool.d.ts.map +0 -1
- package/dist/analysis/chain_pool.js.map +0 -1
- package/dist/analysis/chart_css.d.ts.map +0 -1
- package/dist/analysis/chart_css.js.map +0 -1
- package/dist/analysis/chart_ui.d.ts.map +0 -1
- package/dist/analysis/chart_ui.js.map +0 -1
- package/dist/analysis/chart_utils.d.ts.map +0 -1
- package/dist/analysis/chart_utils.js.map +0 -1
- package/dist/analysis/fills_source.d.ts.map +0 -1
- package/dist/analysis/fills_source.js.map +0 -1
- package/dist/analysis/grid_correction_check.d.ts.map +0 -1
- package/dist/analysis/grid_correction_check.js.map +0 -1
- package/dist/analysis/math_utils.d.ts.map +0 -1
- package/dist/analysis/math_utils.js.map +0 -1
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/resolve_bot_accounts.js.map +0 -1
- package/dist/analysis/resolve_source.d.ts.map +0 -1
- package/dist/analysis/resolve_source.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
- package/dist/bot.d.ts.map +0 -1
- package/dist/bot.js.map +0 -1
- package/dist/credential-daemon.d.ts.map +0 -1
- package/dist/credential-daemon.js.map +0 -1
- package/dist/dexbot.d.ts.map +0 -1
- package/dist/dexbot.js.map +0 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
- package/dist/market_adapter/ama_signal_runner.js.map +0 -1
- package/dist/market_adapter/candle_utils.d.ts.map +0 -1
- package/dist/market_adapter/candle_utils.js.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
- package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
- package/dist/market_adapter/core/config_normalizers.js.map +0 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_candles.js.map +0 -1
- package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_client.js.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
- package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
- package/dist/market_adapter/inputs/window_cache.js.map +0 -1
- package/dist/market_adapter/interval_utils.d.ts.map +0 -1
- package/dist/market_adapter/interval_utils.js.map +0 -1
- package/dist/market_adapter/log_format.d.ts.map +0 -1
- package/dist/market_adapter/log_format.js.map +0 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_core.js.map +0 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_runner.js.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
- package/dist/market_adapter/market_adapter.d.ts.map +0 -1
- package/dist/market_adapter/market_adapter.js.map +0 -1
- package/dist/market_adapter/test_helpers.d.ts.map +0 -1
- package/dist/market_adapter/test_helpers.js.map +0 -1
- package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
- package/dist/market_adapter/utils/adapter_client.js.map +0 -1
- package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
- package/dist/market_adapter/utils/atomic_write.js.map +0 -1
- package/dist/market_adapter/utils/chain.d.ts.map +0 -1
- package/dist/market_adapter/utils/chain.js.map +0 -1
- package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
- package/dist/market_adapter/utils/data_discovery.js.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
- package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
- package/dist/market_adapter/utils/file_lock.js.map +0 -1
- package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
- package/dist/market_adapter/utils/native_history.js.map +0 -1
- package/dist/modules/account_bots.d.ts.map +0 -1
- package/dist/modules/account_bots.js.map +0 -1
- package/dist/modules/account_orders.d.ts.map +0 -1
- package/dist/modules/account_orders.js.map +0 -1
- package/dist/modules/authority_resolver.d.ts.map +0 -1
- package/dist/modules/authority_resolver.js.map +0 -1
- package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/chain_client.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
- package/dist/modules/bitshares-native/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/index.js.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
- package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
- package/dist/modules/bitshares-native/resolvers.js.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
- package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/index.js.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
- package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/types.js.map +0 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/signing_client.js.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
- package/dist/modules/bitshares-native/transport.js.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
- package/dist/modules/bitshares_client.d.ts.map +0 -1
- package/dist/modules/bitshares_client.js.map +0 -1
- package/dist/modules/bot_defaults.d.ts.map +0 -1
- package/dist/modules/bot_defaults.js.map +0 -1
- package/dist/modules/bot_settings.d.ts.map +0 -1
- package/dist/modules/bot_settings.js.map +0 -1
- package/dist/modules/bots_file_lock.d.ts.map +0 -1
- package/dist/modules/bots_file_lock.js.map +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +0 -1
- package/dist/modules/broadcast_failure.js.map +0 -1
- package/dist/modules/chain_keys.d.ts.map +0 -1
- package/dist/modules/chain_keys.js.map +0 -1
- package/dist/modules/chain_orders.d.ts.map +0 -1
- package/dist/modules/chain_orders.js.map +0 -1
- package/dist/modules/cli_colors.d.ts.map +0 -1
- package/dist/modules/cli_colors.js.map +0 -1
- package/dist/modules/cli_start_onboarding.d.ts.map +0 -1
- package/dist/modules/cli_start_onboarding.js.map +0 -1
- package/dist/modules/cli_start_output.d.ts.map +0 -1
- package/dist/modules/cli_start_output.js.map +0 -1
- package/dist/modules/config.d.ts.map +0 -1
- package/dist/modules/config.js.map +0 -1
- package/dist/modules/constants.d.ts.map +0 -1
- package/dist/modules/constants.js.map +0 -1
- package/dist/modules/cr_planner.d.ts.map +0 -1
- package/dist/modules/cr_planner.js.map +0 -1
- package/dist/modules/credential_policy.d.ts.map +0 -1
- package/dist/modules/credential_policy.js.map +0 -1
- package/dist/modules/credential_runtime.d.ts.map +0 -1
- package/dist/modules/credential_runtime.js.map +0 -1
- package/dist/modules/credential_session_cache.d.ts.map +0 -1
- package/dist/modules/credential_session_cache.js.map +0 -1
- package/dist/modules/credit_pricing.d.ts.map +0 -1
- package/dist/modules/credit_pricing.js.map +0 -1
- package/dist/modules/credit_runtime.d.ts.map +0 -1
- package/dist/modules/credit_runtime.js.map +0 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
- package/dist/modules/crypto/browser_provider.js.map +0 -1
- package/dist/modules/crypto/index.d.ts.map +0 -1
- package/dist/modules/crypto/index.js.map +0 -1
- package/dist/modules/crypto/node_provider.d.ts.map +0 -1
- package/dist/modules/crypto/node_provider.js.map +0 -1
- package/dist/modules/crypto/provider.d.ts.map +0 -1
- package/dist/modules/crypto/provider.js.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
- package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
- package/dist/modules/crypto/pure_scrypt.js.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
- package/dist/modules/crypto/sync.d.ts.map +0 -1
- package/dist/modules/crypto/sync.js.map +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +0 -1
- package/dist/modules/daemon_node_health.js.map +0 -1
- package/dist/modules/dexbot_class.d.ts.map +0 -1
- package/dist/modules/dexbot_class.js.map +0 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_cow_runtime.js.map +0 -1
- package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
- package/dist/modules/dexbot_credential_client.js.map +0 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_fill_runtime.js.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_startup_runtime.js.map +0 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
- package/dist/modules/dexbot_state_recovery.js.map +0 -1
- package/dist/modules/env.d.ts.map +0 -1
- package/dist/modules/env.js.map +0 -1
- package/dist/modules/fund_registry.d.ts.map +0 -1
- package/dist/modules/fund_registry.js.map +0 -1
- package/dist/modules/general_settings.d.ts.map +0 -1
- package/dist/modules/general_settings.js.map +0 -1
- package/dist/modules/graceful_shutdown.d.ts.map +0 -1
- package/dist/modules/graceful_shutdown.js.map +0 -1
- package/dist/modules/grid_price_source.d.ts.map +0 -1
- package/dist/modules/grid_price_source.js.map +0 -1
- package/dist/modules/key_store.d.ts.map +0 -1
- package/dist/modules/key_store.js.map +0 -1
- package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
- package/dist/modules/launcher/adapter_requirement.js.map +0 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
- package/dist/modules/launcher/bot_supervisor.js.map +0 -1
- package/dist/modules/launcher/child_env.d.ts.map +0 -1
- package/dist/modules/launcher/child_env.js.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
- package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/credential_daemon.js.map +0 -1
- package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
- package/dist/modules/launcher/credential_secret.js.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
- package/dist/modules/launcher/headless_password.d.ts.map +0 -1
- package/dist/modules/launcher/headless_password.js.map +0 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
- package/dist/modules/launcher/launch_modes.js.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
- package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
- package/dist/modules/launcher/runtime_entry.js.map +0 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
- package/dist/modules/launcher/status_reporting.js.map +0 -1
- package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
- package/dist/modules/launcher/supervisor_control.js.map +0 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
- package/dist/modules/market_adapter_whitelist.js.map +0 -1
- package/dist/modules/node_connect_policy.d.ts.map +0 -1
- package/dist/modules/node_connect_policy.js.map +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +0 -1
- package/dist/modules/node_failure_ledger.js.map +0 -1
- package/dist/modules/node_health_cache.d.ts.map +0 -1
- package/dist/modules/node_health_cache.js.map +0 -1
- package/dist/modules/node_manager.d.ts.map +0 -1
- package/dist/modules/node_manager.js.map +0 -1
- package/dist/modules/order/accounting.d.ts.map +0 -1
- package/dist/modules/order/accounting.js.map +0 -1
- package/dist/modules/order/async_lock.d.ts.map +0 -1
- package/dist/modules/order/async_lock.js.map +0 -1
- package/dist/modules/order/export.d.ts.map +0 -1
- package/dist/modules/order/export.js.map +0 -1
- package/dist/modules/order/format.d.ts.map +0 -1
- package/dist/modules/order/format.js.map +0 -1
- package/dist/modules/order/grid.d.ts.map +0 -1
- package/dist/modules/order/grid.js.map +0 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile.js.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
- package/dist/modules/order/index.d.ts.map +0 -1
- package/dist/modules/order/index.js.map +0 -1
- package/dist/modules/order/logger.d.ts.map +0 -1
- package/dist/modules/order/logger.js.map +0 -1
- package/dist/modules/order/logger_state.d.ts.map +0 -1
- package/dist/modules/order/logger_state.js.map +0 -1
- package/dist/modules/order/manager.d.ts.map +0 -1
- package/dist/modules/order/manager.js.map +0 -1
- package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
- package/dist/modules/order/processed_fill_store.js.map +0 -1
- package/dist/modules/order/strategy.d.ts.map +0 -1
- package/dist/modules/order/strategy.js.map +0 -1
- package/dist/modules/order/sync_engine.d.ts.map +0 -1
- package/dist/modules/order/sync_engine.js.map +0 -1
- package/dist/modules/order/utils/math.d.ts.map +0 -1
- package/dist/modules/order/utils/math.js.map +0 -1
- package/dist/modules/order/utils/order.d.ts.map +0 -1
- package/dist/modules/order/utils/order.js.map +0 -1
- package/dist/modules/order/utils/slot.d.ts.map +0 -1
- package/dist/modules/order/utils/slot.js.map +0 -1
- package/dist/modules/order/utils/system.d.ts.map +0 -1
- package/dist/modules/order/utils/system.js.map +0 -1
- package/dist/modules/order/utils/timeout.d.ts.map +0 -1
- package/dist/modules/order/utils/timeout.js.map +0 -1
- package/dist/modules/order/utils/validate.d.ts.map +0 -1
- package/dist/modules/order/utils/validate.js.map +0 -1
- package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
- package/dist/modules/order/utils/withPoolRef.js.map +0 -1
- package/dist/modules/order/working_grid.d.ts.map +0 -1
- package/dist/modules/order/working_grid.js.map +0 -1
- package/dist/modules/path_api.d.ts.map +0 -1
- package/dist/modules/path_api.js.map +0 -1
- package/dist/modules/paths.d.ts.map +0 -1
- package/dist/modules/paths.js.map +0 -1
- package/dist/modules/process_discovery.d.ts.map +0 -1
- package/dist/modules/process_discovery.js.map +0 -1
- package/dist/modules/runtime.d.ts.map +0 -1
- package/dist/modules/runtime.js.map +0 -1
- package/dist/modules/runtime_settings.d.ts.map +0 -1
- package/dist/modules/runtime_settings.js.map +0 -1
- package/dist/modules/settings_merge.d.ts.map +0 -1
- package/dist/modules/settings_merge.js.map +0 -1
- package/dist/modules/socket_json_client.d.ts.map +0 -1
- package/dist/modules/socket_json_client.js.map +0 -1
- package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
- package/dist/modules/storage/browser_adapter.js.map +0 -1
- package/dist/modules/storage/index.d.ts.map +0 -1
- package/dist/modules/storage/index.js.map +0 -1
- package/dist/modules/storage/node_adapter.d.ts.map +0 -1
- package/dist/modules/storage/node_adapter.js.map +0 -1
- package/dist/modules/storage/types.d.ts.map +0 -1
- package/dist/modules/storage/types.js.map +0 -1
- package/dist/modules/types.d.ts.map +0 -1
- package/dist/modules/types.js.map +0 -1
- package/dist/modules/utils/base58check.d.ts.map +0 -1
- package/dist/modules/utils/base58check.js.map +0 -1
- package/dist/modules/utils/build_dir.d.ts.map +0 -1
- package/dist/modules/utils/build_dir.js.map +0 -1
- package/dist/modules/utils/chain_logs.d.ts.map +0 -1
- package/dist/modules/utils/chain_logs.js.map +0 -1
- package/dist/modules/utils/errors.d.ts.map +0 -1
- package/dist/modules/utils/errors.js.map +0 -1
- package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
- package/dist/modules/utils/sanitize_key.js.map +0 -1
- package/dist/modules/utils/text_width.d.ts.map +0 -1
- package/dist/modules/utils/text_width.js.map +0 -1
- package/dist/modules/validate_profiles.d.ts.map +0 -1
- package/dist/modules/validate_profiles.js.map +0 -1
- package/dist/pm2.d.ts.map +0 -1
- package/dist/pm2.js.map +0 -1
- package/dist/scripts/analyze-credit.d.ts.map +0 -1
- package/dist/scripts/analyze-credit.js.map +0 -1
- package/dist/scripts/analyze-git.d.ts.map +0 -1
- package/dist/scripts/analyze-git.js.map +0 -1
- package/dist/scripts/analyze-orders.d.ts.map +0 -1
- package/dist/scripts/analyze-orders.js.map +0 -1
- package/dist/scripts/chart_command.d.ts.map +0 -1
- package/dist/scripts/chart_command.js.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
- package/dist/scripts/diagnose-pool-history.js.map +0 -1
- package/dist/scripts/divergence-calc.d.ts.map +0 -1
- package/dist/scripts/divergence-calc.js.map +0 -1
- package/dist/scripts/dw.d.ts.map +0 -1
- package/dist/scripts/dw.js.map +0 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
- package/dist/scripts/generate_lp_chart.js.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
- package/dist/scripts/native_release_gates.d.ts.map +0 -1
- package/dist/scripts/native_release_gates.js.map +0 -1
- package/dist/scripts/print_grid.d.ts.map +0 -1
- package/dist/scripts/print_grid.js.map +0 -1
- package/dist/scripts/run-tests.d.ts.map +0 -1
- package/dist/scripts/run-tests.js.map +0 -1
- package/dist/scripts/runner.d.ts.map +0 -1
- package/dist/scripts/runner.js.map +0 -1
- package/dist/scripts/sync-version.d.ts.map +0 -1
- package/dist/scripts/sync-version.js.map +0 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
- package/dist/scripts/test-credit-renewal.js.map +0 -1
- package/dist/scripts/tv.d.ts.map +0 -1
- package/dist/scripts/tv.js.map +0 -1
- package/dist/scripts/update.d.ts.map +0 -1
- package/dist/scripts/update.js.map +0 -1
- package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
- package/dist/scripts/update_dist_freshness.js.map +0 -1
- package/dist/scripts/validate_bots.d.ts.map +0 -1
- package/dist/scripts/validate_bots.js.map +0 -1
- package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
- package/dist/scripts/verify-browser-bundle.js.map +0 -1
- package/dist/unlock.d.ts.map +0 -1
- package/dist/unlock.js.map +0 -1
|
@@ -1,1481 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { DEFAULT_CONFIG, MARKET_ADAPTER } from '../../modules/constants.js';
|
|
4
|
-
import { getAmaWarmupBars } from '../../market_adapter/core/strategies/ama.js';
|
|
5
|
-
import { bilinearInterpolate } from '../../market_adapter/core/strategies/regime_interp.js';
|
|
6
|
-
import { computeDynamicWeightSeries, computeAverageAmaSlopePct, computeAmaSlopeClipThreshold, echoLatchSeries, roundToN } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
|
|
7
|
-
import {
|
|
8
|
-
buildKalmanVelocitySeries,
|
|
9
|
-
computeAbsolutePercentileThreshold,
|
|
10
|
-
resolveKalmanVelocitySmoothingConfig,
|
|
11
|
-
smoothKalmanVelocityPoint,
|
|
12
|
-
} from '../../market_adapter/core/signals/kalman_velocity_smoothing.js';
|
|
13
|
-
import { embedFunctionSources, escapeHtml, serializeJsonForScript, toEpochSeconds, UPLOT_SHARED_SCRIPT, uplotInlineTags } from '../chart_utils.js';
|
|
14
|
-
import { sharedChartCSS } from '../chart_css.js';
|
|
15
|
-
import { Y_AXIS_SIZE, makeCursorConfig, bindHoverStateFn, wireChartEvents, zoomResetScript, sizeChartsFn } from '../chart_ui.js';
|
|
16
|
-
|
|
17
|
-
// Browser-embedded shared functions — the interactive chart runs the exact same
|
|
18
|
-
// pure logic as the live market adapter service instead of a hand-copied copy.
|
|
19
|
-
const EMBEDDED_SHARED_FUNCS = embedFunctionSources([
|
|
20
|
-
computeAverageAmaSlopePct,
|
|
21
|
-
computeAmaSlopeClipThreshold,
|
|
22
|
-
bilinearInterpolate,
|
|
23
|
-
echoLatchSeries,
|
|
24
|
-
buildKalmanVelocitySeries,
|
|
25
|
-
resolveKalmanVelocitySmoothingConfig,
|
|
26
|
-
smoothKalmanVelocityPoint,
|
|
27
|
-
computeAbsolutePercentileThreshold,
|
|
28
|
-
computeDynamicWeightSeries,
|
|
29
|
-
roundToN,
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
function generateHTML(data: any, title = 'Dynamic Weight Research') {
|
|
33
|
-
const results = data.allResults || [];
|
|
34
|
-
if (results.length === 0) throw new Error('No analysis results in input');
|
|
35
|
-
|
|
36
|
-
// Slider ranges — single source of truth for HTML attrs, tooltips,
|
|
37
|
-
// payload transport, and client paste-clamp bounds.
|
|
38
|
-
const LB_MIN = 1, LB_MAX = 32;
|
|
39
|
-
const GAIN_MIN = 0.5, GAIN_MAX = 2.0;
|
|
40
|
-
const AMA_MS_MIN = 0.06, AMA_MS_MAX = 0.12;
|
|
41
|
-
const KAL_MS_MIN = 0.5, KAL_MS_MAX = 1.5;
|
|
42
|
-
const CLIP_PCT_MAX = 20;
|
|
43
|
-
const EMA_MIN = 0, EMA_MAX = 32;
|
|
44
|
-
const TH_MIN = 0, TH_MAX = 0.5;
|
|
45
|
-
const KF_MIN = 0, KF_MAX = 200;
|
|
46
|
-
const KFD_MIN = 1.0, KFD_MAX = 3.0;
|
|
47
|
-
const DSP_MIN = 0.25, DSP_MAX = 4.0;
|
|
48
|
-
const KDT_MIN = 0.25, KDT_MAX = 3.0;
|
|
49
|
-
const KFS_MIN = 20, KFS_MAX = 200;
|
|
50
|
-
const CF_MIN = 0, CF_MAX = 5;
|
|
51
|
-
const REGI_MIN = 0, REGI_MAX = 2;
|
|
52
|
-
const SLIDER_RANGES = {
|
|
53
|
-
alpha: [0, 1],
|
|
54
|
-
dispWeight: [0, 1],
|
|
55
|
-
neutralZonePct: [0, 1],
|
|
56
|
-
lookbackBars: [LB_MIN, LB_MAX],
|
|
57
|
-
amaEmaSpan: [EMA_MIN, EMA_MAX],
|
|
58
|
-
amaMaxSlopePct: [AMA_MS_MIN, AMA_MS_MAX],
|
|
59
|
-
kalmanMaxSlopePct: [KAL_MS_MIN, KAL_MS_MAX],
|
|
60
|
-
clipPct: [0, CLIP_PCT_MAX],
|
|
61
|
-
minOutputThreshold: [TH_MIN, TH_MAX],
|
|
62
|
-
kalmanSmoothPct: [KF_MIN, KF_MAX],
|
|
63
|
-
kalmanDispScaleMult: [KFD_MIN, KFD_MAX],
|
|
64
|
-
dispScaleMinPct: [DSP_MIN, DSP_MAX],
|
|
65
|
-
kalmanDispThresholdMult: [KDT_MIN, KDT_MAX],
|
|
66
|
-
kalmanSmoothSpanPct: [KFS_MIN, KFS_MAX],
|
|
67
|
-
signalConfirmBars: [CF_MIN, CF_MAX],
|
|
68
|
-
gain: [GAIN_MIN, GAIN_MAX],
|
|
69
|
-
regimeSensitivity: [REGI_MIN, REGI_MAX],
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const ma = data.marketAdapter || {};
|
|
73
|
-
const amaWeightConfig = data.amaWeightConfig || {};
|
|
74
|
-
const defaultAlpha = data.alpha ?? ma.alpha ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_ALPHA;
|
|
75
|
-
const defaultGain = data.gain ?? ma.gain ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_GAIN;
|
|
76
|
-
const defaultNeutralZone = amaWeightConfig.neutralZonePct ?? ma.amaNeutralZonePct ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_NEUTRAL_ZONE_PCT;
|
|
77
|
-
const defaultDispWeight = data.dispWeight ?? ma.dispWeight ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_DW;
|
|
78
|
-
const defaultAmaMaxSlopePct = amaWeightConfig.amaMaxSlopePct
|
|
79
|
-
?? ma.amaMaxSlopePct
|
|
80
|
-
?? MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_MAX_SLOPE_PCT;
|
|
81
|
-
const defaultKalmanMaxSlopePct = amaWeightConfig.kalmanMaxSlopePct
|
|
82
|
-
?? ma.kalmanMaxSlopePct
|
|
83
|
-
?? defaultAmaMaxSlopePct
|
|
84
|
-
?? MARKET_ADAPTER.DYNAMIC_WEIGHT_KALMAN_MAX_SLOPE_PCT;
|
|
85
|
-
const defaultClipPct = data.clipPct ?? ma.clipPercentile ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_CLIP_PERCENTILE;
|
|
86
|
-
const defaultMinOutputThresholdRaw = data.minOutputThreshold ?? ma.minOutputThreshold ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_ASYMMETRIC_TREND_THRESHOLD;
|
|
87
|
-
const defaultMinOutputThreshold = Math.min(Math.max(defaultMinOutputThresholdRaw, TH_MIN), TH_MAX);
|
|
88
|
-
const defaultOutputClamp = data.outputClamp ?? ma.outputClamp ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_ASYMMETRIC_OFFSET_CLAMP;
|
|
89
|
-
const lookbackBarsRaw = amaWeightConfig.lookbackBars ?? ma.amaLookbackBars ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_LOOKBACK_BARS;
|
|
90
|
-
const lookbackBars = Math.ceil(Math.max(LB_MIN, Math.min(LB_MAX, Number.isFinite(lookbackBarsRaw) ? lookbackBarsRaw : LB_MIN)));
|
|
91
|
-
|
|
92
|
-
// Log mapping for lookback slider
|
|
93
|
-
const LB_LOG_MIN_N = Math.log(LB_MIN);
|
|
94
|
-
const LB_LOG_MAX_N = Math.log(LB_MAX);
|
|
95
|
-
const clampedLb = Math.min(Math.max(lookbackBars, LB_MIN), LB_MAX);
|
|
96
|
-
const lbInitSlider = Math.round((Math.log(clampedLb) - LB_LOG_MIN_N) / (LB_LOG_MAX_N - LB_LOG_MIN_N) * 1000);
|
|
97
|
-
|
|
98
|
-
// Log mapping for gain slider
|
|
99
|
-
const GAIN_LOG_MIN_N = Math.log(GAIN_MIN);
|
|
100
|
-
const GAIN_LOG_MAX_N = Math.log(GAIN_MAX);
|
|
101
|
-
const clampedGain = Math.min(Math.max(defaultGain, GAIN_MIN), GAIN_MAX);
|
|
102
|
-
const gainInitSlider = Math.round((Math.log(clampedGain) - GAIN_LOG_MIN_N) / (GAIN_LOG_MAX_N - GAIN_LOG_MIN_N) * 1000);
|
|
103
|
-
|
|
104
|
-
// Log mapping for slope saturation sliders
|
|
105
|
-
const AMA_MS_LOG_MIN_N = Math.log(AMA_MS_MIN);
|
|
106
|
-
const AMA_MS_LOG_MAX_N = Math.log(AMA_MS_MAX);
|
|
107
|
-
const KAL_MS_LOG_MIN_N = Math.log(KAL_MS_MIN);
|
|
108
|
-
const KAL_MS_LOG_MAX_N = Math.log(KAL_MS_MAX);
|
|
109
|
-
const clampedAmaMs = Math.min(Math.max(defaultAmaMaxSlopePct, AMA_MS_MIN), AMA_MS_MAX);
|
|
110
|
-
const clampedKalMs = Math.min(Math.max(defaultKalmanMaxSlopePct, KAL_MS_MIN), KAL_MS_MAX);
|
|
111
|
-
const amaMsInitSlider = Math.round((Math.log(clampedAmaMs) - AMA_MS_LOG_MIN_N) / (AMA_MS_LOG_MAX_N - AMA_MS_LOG_MIN_N) * 1000);
|
|
112
|
-
const kalMsInitSlider = Math.round((Math.log(clampedKalMs) - KAL_MS_LOG_MIN_N) / (KAL_MS_LOG_MAX_N - KAL_MS_LOG_MIN_N) * 1000);
|
|
113
|
-
|
|
114
|
-
const defaultRegimeSensitivity = data.regimeSensitivity ?? ma.regimeSensitivity ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_REGIME_SENSITIVITY;
|
|
115
|
-
const defaultAbsoluteThreshold = ma.absoluteThreshold ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_ABSOLUTE_THRESHOLD_DEFAULT;
|
|
116
|
-
const defaultDispScaleMinPct = data.dispScaleMinPct ?? ma.dispScaleMinPct ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_DISP_SCALE_MIN_PCT;
|
|
117
|
-
const defaultKalmanSmoothPct = data.kalmanSmoothPct ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_KALMAN_SMOOTH_PCT_DEFAULT;
|
|
118
|
-
const defaultKalmanDispScaleMult = data.kalmanDispScaleMult ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_KALMAN_DISP_SCALE_MULT_DEFAULT;
|
|
119
|
-
const defaultKalmanDispThresholdMult = data.kalmanDispThresholdMult ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_KALMAN_DISP_THRESHOLD_MULT_DEFAULT;
|
|
120
|
-
const defaultKalmanSmoothSpanPct = data.kalmanSmoothSpanPct ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_KALMAN_SMOOTH_SPAN_PCT_DEFAULT;
|
|
121
|
-
const defaultSignalConfirmBars = data.signalConfirmBars ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_SIGNAL_CONFIRM_BARS_DEFAULT;
|
|
122
|
-
// Research-only `ema` knob: EMA span in bars over the AMA input before the
|
|
123
|
-
// slope is taken. 0 (default) = off, keeps the raw AMA input.
|
|
124
|
-
const defaultAmaEmaSpanRaw = data.amaEmaSpan ?? ma.amaEmaSpan ?? 0;
|
|
125
|
-
const defaultAmaEmaSpan = Math.round(Math.min(EMA_MAX, Math.max(EMA_MIN, Number.isFinite(defaultAmaEmaSpanRaw) ? defaultAmaEmaSpanRaw : EMA_MIN)));
|
|
126
|
-
const regimeInitSlider = Math.round(defaultRegimeSensitivity * 100);
|
|
127
|
-
|
|
128
|
-
const interval = results.length > 1 ?
|
|
129
|
-
(new Date(results[1].timestamp).getTime() - new Date(results[0].timestamp).getTime()) / 1000 : 3600;
|
|
130
|
-
|
|
131
|
-
const dates = results.map((r: any, idx: number) => toEpochSeconds(r.timestamp || Date.now(), idx));
|
|
132
|
-
const prices = results.map((r: any) => r.price);
|
|
133
|
-
const hurstArr = results.map((r: any) => r.hurst ?? null);
|
|
134
|
-
const peArr = results.map((r: any) => r.pe ?? null);
|
|
135
|
-
const hurstSegments = results.map((r: any) => r.hurstSegment ?? null);
|
|
136
|
-
const peSegments = results.map((r: any) => r.peSegment ?? null);
|
|
137
|
-
const amaSlopePct = results.map((r: any) => r.amaSlopePct ?? null);
|
|
138
|
-
const kalmanVelocityPctRaw = results.map((r: any) => r.velocityRawPct ?? r.velocityPct ?? null);
|
|
139
|
-
const kalmanDisplacementPct = results.map((r: any) => r.displacementRawPct ?? r.displacementPct ?? null);
|
|
140
|
-
const kalmanVelocityPct = buildKalmanVelocitySeries(
|
|
141
|
-
results.map((r: any) => ({ velocityPct: r.velocityRawPct ?? r.velocityPct ?? null, displacementPct: r.displacementRawPct ?? r.displacementPct ?? null })),
|
|
142
|
-
{
|
|
143
|
-
kalmanSmoothPct: defaultKalmanSmoothPct,
|
|
144
|
-
kalmanDispScaleMult: defaultKalmanDispScaleMult,
|
|
145
|
-
kalmanDispThresholdMult: defaultKalmanDispThresholdMult,
|
|
146
|
-
kalmanSmoothSpanPct: defaultKalmanSmoothSpanPct,
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
const kalmanIsReady = results.map((r: any) => r.isReady ?? false);
|
|
150
|
-
const signals = results.map((r: any) => r.signal);
|
|
151
|
-
const amaLabel = data.amaKey || 'AMA3';
|
|
152
|
-
const ama3Prices = results.map((r: any) => r.ama3Price ?? null);
|
|
153
|
-
const defaultAmaKey = MARKET_ADAPTER.DEFAULT_AMA_KEY as keyof typeof MARKET_ADAPTER.AMAS;
|
|
154
|
-
const amaErPeriod = data.amaConfig?.erPeriod ?? MARKET_ADAPTER.AMAS[defaultAmaKey].erPeriod;
|
|
155
|
-
const amaSlowPeriod = data.amaConfig?.slowPeriod ?? MARKET_ADAPTER.AMAS[defaultAmaKey].slowPeriod;
|
|
156
|
-
const amaFastPeriod = data.amaConfig?.fastPeriod ?? MARKET_ADAPTER.AMAS[defaultAmaKey].fastPeriod;
|
|
157
|
-
const amaErSmoothPeriod = data.amaConfig?.erSmoothPeriod ?? 0;
|
|
158
|
-
const amaWarmupBars = getAmaWarmupBars(amaErPeriod, amaSlowPeriod, lookbackBars, amaFastPeriod, amaErSmoothPeriod);
|
|
159
|
-
const amaSlopeReadyBars = Math.ceil(amaErPeriod) + lookbackBars;
|
|
160
|
-
const amaSeedSmaLine = new Array(results.length).fill(null);
|
|
161
|
-
const amaSeedWindowEnd = Math.min(results.length - 1, Math.ceil(amaErPeriod));
|
|
162
|
-
if (amaSeedWindowEnd >= 0) {
|
|
163
|
-
let seedSum = 0;
|
|
164
|
-
let seedCount = 0;
|
|
165
|
-
for (let i = 0; i <= amaSeedWindowEnd; i++) {
|
|
166
|
-
if (Number.isFinite(prices[i])) {
|
|
167
|
-
seedSum += prices[i];
|
|
168
|
-
seedCount++;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (seedCount > 0) {
|
|
172
|
-
const seedSma = seedSum / seedCount;
|
|
173
|
-
for (let i = 0; i <= amaSeedWindowEnd; i++) {
|
|
174
|
-
amaSeedSmaLine[i] = seedSma;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const lastDate = dates[dates.length - 1];
|
|
180
|
-
for (let i = 1; i <= 150; i++) {
|
|
181
|
-
dates.push(lastDate + (i * interval));
|
|
182
|
-
prices.push(null);
|
|
183
|
-
hurstArr.push(null);
|
|
184
|
-
peArr.push(null);
|
|
185
|
-
hurstSegments.push(null);
|
|
186
|
-
peSegments.push(null);
|
|
187
|
-
amaSlopePct.push(null);
|
|
188
|
-
kalmanVelocityPctRaw.push(null);
|
|
189
|
-
kalmanVelocityPct.push(null);
|
|
190
|
-
kalmanDisplacementPct.push(null);
|
|
191
|
-
kalmanIsReady.push(null);
|
|
192
|
-
signals.push(null);
|
|
193
|
-
ama3Prices.push(null);
|
|
194
|
-
amaSeedSmaLine.push(null);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const realBarCount = results.length;
|
|
198
|
-
|
|
199
|
-
function maxAbsPct(arr: any[]) {
|
|
200
|
-
let m = 0;
|
|
201
|
-
for (let i = 0; i < realBarCount; i++) {
|
|
202
|
-
if (arr[i] != null && Math.abs(arr[i]) > m) m = Math.abs(arr[i]);
|
|
203
|
-
}
|
|
204
|
-
return m || 4;
|
|
205
|
-
}
|
|
206
|
-
const amaPctMax = Math.ceil(maxAbsPct(amaSlopePct) * 1.15) || 5;
|
|
207
|
-
const kalPctMax = Math.ceil(Math.max(maxAbsPct(kalmanVelocityPct), maxAbsPct(kalmanDisplacementPct)) * 1.15) || 5;
|
|
208
|
-
|
|
209
|
-
function buildPercentiles(arr: any[], startIndex = 0) {
|
|
210
|
-
const safeStartIndex = Math.max(0, Math.min(realBarCount, Math.ceil(startIndex)));
|
|
211
|
-
const sorted: number[] = [];
|
|
212
|
-
for (let i = safeStartIndex; i < realBarCount; i++) { if (arr[i] != null) sorted.push(Math.abs(arr[i])); }
|
|
213
|
-
sorted.sort((a, b) => a - b);
|
|
214
|
-
// Empty pool → Infinity: the live percentile lookup treats an empty
|
|
215
|
-
// history as "no clipping" (percentileFromSorted returns Infinity);
|
|
216
|
-
// collapsing to 0 here would clip every slope to ±0 instead.
|
|
217
|
-
if (sorted.length === 0) return new Array(101).fill(Infinity);
|
|
218
|
-
const pcts: number[] = [];
|
|
219
|
-
for (let p = 0; p <= 100; p++) {
|
|
220
|
-
const idx = Math.min(Math.floor(sorted.length * p / 100), sorted.length - 1);
|
|
221
|
-
pcts.push(sorted[idx]);
|
|
222
|
-
}
|
|
223
|
-
return pcts;
|
|
224
|
-
}
|
|
225
|
-
const amaPercentiles = buildPercentiles(amaSlopePct, amaSlopeReadyBars);
|
|
226
|
-
const kalPercentiles = buildPercentiles(kalmanVelocityPct);
|
|
227
|
-
const maxDispPct = Math.ceil(maxAbsPct(kalmanDisplacementPct) * 1.15) || 5;
|
|
228
|
-
return `<!DOCTYPE html>
|
|
229
|
-
<html lang="en">
|
|
230
|
-
<head>
|
|
231
|
-
<meta charset="UTF-8">
|
|
232
|
-
<title>${escapeHtml(title)}</title>
|
|
233
|
-
${uplotInlineTags()}
|
|
234
|
-
<style>
|
|
235
|
-
${sharedChartCSS()}
|
|
236
|
-
#price-panel { flex: 0 0 34%; min-height: 0; position: relative; border-bottom: 1px solid #30363d; }
|
|
237
|
-
#ama-panel { flex: 0 0 14%; min-height: 0; position: relative; border-bottom: 1px solid #30363d; }
|
|
238
|
-
#kalman-panel { flex: 0 0 21%; min-height: 0; position: relative; border-bottom: 1px solid #30363d; }
|
|
239
|
-
#output-panel { flex: 1 1 0; min-height: 0; position: relative; }
|
|
240
|
-
.legend { left: 70px; flex-wrap: wrap; gap: 4px 8px; color: #8b949e; max-width: calc(100% - 86px); }
|
|
241
|
-
.legend-item { gap: 3px; }
|
|
242
|
-
.legend-val { font-family: monospace; display: inline-block; text-align: right; min-width: 45px; }
|
|
243
|
-
#l-price, #l-ama3 { min-width: 62px; }
|
|
244
|
-
#l-ama-slope, #l-ama-slope-raw, #l-kal-vel, #l-kal-disp { min-width: 54px; }
|
|
245
|
-
#l-signal, #l-signal-latched { min-width: 70px; text-align: left; }
|
|
246
|
-
#l-combined-raw, #l-combined-echo { min-width: 42px; }
|
|
247
|
-
#l-mult { min-width: 38px; }
|
|
248
|
-
#l-sell, #l-buy { min-width: 30px; }
|
|
249
|
-
.ctrl { pointer-events: auto; display: inline-flex; align-items: center; gap: 2px; margin-left: 4px; }
|
|
250
|
-
.ctrl label { color: #8b949e; font-size: 10px; min-width: 24px; text-align: right; margin-right: 2px; }
|
|
251
|
-
.ctrl.alpha label { min-width: 8px; }
|
|
252
|
-
.ctrl.ms label { min-width: 32px; }
|
|
253
|
-
.ctrl.clip label { min-width: 30px; }
|
|
254
|
-
.ctrl.off label { min-width: 24px; }
|
|
255
|
-
.ctrl.regime label { min-width: 24px; }
|
|
256
|
-
.ctrl input[type="range"] { width: 80px; height: 3px; }
|
|
257
|
-
.ctrl .val { font-weight: bold; font-size: 10px; min-width: 30px; display: inline-block; text-align: right; }
|
|
258
|
-
.group-sep { border-left: 1px solid #30363d; margin-left: 6px; padding-left: 4px; display: inline-flex; align-items: center; height: 16px; }
|
|
259
|
-
.group-label { font-size: 9px; color: #484f58; text-transform: uppercase; letter-spacing: 0.5px; margin-left: 8px; font-weight: bold; }
|
|
260
|
-
.ctrl.alpha input[type="range"] { accent-color: #58a6ff; width: 80px; }
|
|
261
|
-
.ctrl.alpha .val { color: #58a6ff; }
|
|
262
|
-
.ctrl.dw label { min-width: 20px; }
|
|
263
|
-
.ctrl.dw input[type="range"] { accent-color: #a371f7; width: 80px; }
|
|
264
|
-
.ctrl.dw .val { color: #a371f7; }
|
|
265
|
-
.ctrl.kf label { min-width: 20px; }
|
|
266
|
-
.ctrl.kf input[type="range"] { accent-color: #79c0ff; width: 80px; }
|
|
267
|
-
.ctrl.kf .val { color: #79c0ff; }
|
|
268
|
-
.ctrl.kfd label { min-width: 20px; }
|
|
269
|
-
.ctrl.kfd input[type="range"] { accent-color: #58a6ff; width: 80px; }
|
|
270
|
-
.ctrl.kfd .val { color: #58a6ff; }
|
|
271
|
-
.ctrl.kdt label { min-width: 20px; }
|
|
272
|
-
.ctrl.kdt input[type="range"] { accent-color: #f78166; width: 80px; }
|
|
273
|
-
.ctrl.kdt .val { color: #f78166; }
|
|
274
|
-
.ctrl.kfs label { min-width: 20px; }
|
|
275
|
-
.ctrl.kfs input[type="range"] { accent-color: #ffab70; width: 80px; }
|
|
276
|
-
.ctrl.kfs .val { color: #ffab70; }
|
|
277
|
-
.ctrl.ms-ama label { min-width: 32px; }
|
|
278
|
-
.ctrl.ms-ama input[type="range"] { accent-color: #e3b341; width: 80px; }
|
|
279
|
-
.ctrl.ms-ama .val { color: #e3b341; }
|
|
280
|
-
.ctrl.ms-kal label { min-width: 32px; }
|
|
281
|
-
.ctrl.ms-kal input[type="range"] { accent-color: #f0883e; width: 80px; }
|
|
282
|
-
.ctrl.ms-kal .val { color: #f0883e; }
|
|
283
|
-
.ctrl.cf label { min-width: 20px; }
|
|
284
|
-
.ctrl.cf input[type="range"] { accent-color: #d2a8ff; width: 80px; }
|
|
285
|
-
.ctrl.cf .val { color: #d2a8ff; }
|
|
286
|
-
.ctrl.lb label { min-width: 20px; }
|
|
287
|
-
.ctrl.lb input[type="range"] { accent-color: #39d0d8; width: 80px; }
|
|
288
|
-
.ctrl.lb .val { color: #39d0d8; }
|
|
289
|
-
.ctrl.ema label { min-width: 20px; }
|
|
290
|
-
.ctrl.ema input[type="range"] { accent-color: #f0a000; width: 80px; }
|
|
291
|
-
.ctrl.ema .val { color: #f0a000; }
|
|
292
|
-
.ctrl.off input[type="range"] { accent-color: #3fb950; }
|
|
293
|
-
.ctrl.off .val { color: #3fb950; }
|
|
294
|
-
.ctrl.nz input[type="range"] { accent-color: #8b949e; }
|
|
295
|
-
.ctrl.nz .val { color: #8b949e; }
|
|
296
|
-
.copy-btn, .paste-btn { pointer-events: auto; margin-left: 6px; padding: 2px 10px; font-size: 10px; background: #21262d; color: #8b949e; border: 1px solid #30363d; border-radius: 4px; cursor: pointer; }
|
|
297
|
-
.copy-btn:hover, .paste-btn:hover { background: #30363d; color: #e6edf3; }
|
|
298
|
-
.copy-btn.copied { color: #3fb950; border-color: #3fb950; }
|
|
299
|
-
.paste-btn.pasted { color: #58a6ff; border-color: #58a6ff; }
|
|
300
|
-
.paste-btn.error { color: #f85149; border-color: #f85149; }
|
|
301
|
-
#paste-confirm { display: none; position: fixed; background: #161b22; border: 1px solid #30363d; border-radius: 6px; padding: 14px 16px; z-index: 1000; box-shadow: 0 4px 24px rgba(0,0,0,0.7); min-width: 200px; }
|
|
302
|
-
#paste-confirm-title { font-size: 10px; color: #8b949e; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
|
|
303
|
-
#paste-confirm-vals { font-size: 11px; font-family: monospace; color: #e6edf3; line-height: 1.7; margin-bottom: 12px; }
|
|
304
|
-
#paste-confirm-vals span { color: #58a6ff; }
|
|
305
|
-
#paste-confirm-btns { display: flex; gap: 6px; justify-content: flex-end; }
|
|
306
|
-
#paste-confirm-btns button { padding: 3px 12px; font-size: 10px; border-radius: 4px; cursor: pointer; border: 1px solid #30363d; background: #21262d; color: #8b949e; }
|
|
307
|
-
#paste-confirm-apply { background: #1f4e23 !important; color: #3fb950 !important; border-color: #3fb950 !important; }
|
|
308
|
-
#paste-confirm-apply:hover { background: #2ea043 !important; color: #fff !important; }
|
|
309
|
-
|
|
310
|
-
.ctrl.clip input[type="range"] { accent-color: #da3633; }
|
|
311
|
-
.ctrl.clip .val { color: #da3633; }
|
|
312
|
-
.ctrl.regime input[type="range"] { accent-color: #d2a8ff; }
|
|
313
|
-
.ctrl.regime .val { color: #d2a8ff; }
|
|
314
|
-
.row-break { flex-basis: 100%; height: 0; }
|
|
315
|
-
</style>
|
|
316
|
-
</head>
|
|
317
|
-
<body>
|
|
318
|
-
<div id="header">
|
|
319
|
-
<div style="font-weight:bold;color:#fff;">${escapeHtml(title)}</div>
|
|
320
|
-
<div style="font-size:11px;color:#8b949e;text-transform:uppercase;">Log Price \u2192 AMA Slope \u2192 Kalman Composite \u2192 Dynamic Weight | Scroll \u00b7 Drag \u00b7 Ctrl+0</div>
|
|
321
|
-
</div>
|
|
322
|
-
|
|
323
|
-
<div id="panels">
|
|
324
|
-
<div id="price-panel">
|
|
325
|
-
<div class="section-label">PRICE (LOG)</div>
|
|
326
|
-
<div class="legend">
|
|
327
|
-
<div class="legend-item"><div class="dot" style="background:#58a6ff;"></div>Price: <span id="l-price" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
328
|
-
<div class="legend-item"><div class="dot" style="background:#e3b341;"></div>${amaLabel}: <span id="l-ama3" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
329
|
-
<div class="legend-item"><div class="dot" style="background:#8b949e;"></div>Seed SMA: <span id="l-seed-sma" class="legend-val">-</span></div>
|
|
330
|
-
</div>
|
|
331
|
-
<div id="price-chart"></div>
|
|
332
|
-
</div>
|
|
333
|
-
<div id="ama-panel">
|
|
334
|
-
<div class="section-label">AMA SLOPE INPUT</div>
|
|
335
|
-
<div class="legend">
|
|
336
|
-
<div class="legend-item"><div class="dot" style="background:#f0a000;"></div>Slope‰: <span id="l-ama-slope" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
337
|
-
<div class="legend-item"><div class="dot" style="background:#8b949e;"></div>Raw‰: <span id="l-ama-slope-raw" class="legend-val">-</span></div>
|
|
338
|
-
</div>
|
|
339
|
-
<div id="ama-chart"></div>
|
|
340
|
-
</div>
|
|
341
|
-
<div id="kalman-panel">
|
|
342
|
-
<div class="section-label">KALMAN COMPOSITE INPUT</div>
|
|
343
|
-
<div class="legend">
|
|
344
|
-
<div class="legend-item"><div class="dot" style="background:#d2a8ff;"></div>Vel%: <span id="l-kal-vel" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
345
|
-
<div class="legend-item"><div class="dot" style="background:#79c0ff;"></div>Disp%: <span id="l-kal-disp" class="legend-val">-</span></div>
|
|
346
|
-
<div class="legend-item">Raw: <span id="l-signal" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
347
|
-
<div class="legend-item">Echo: <span id="l-signal-echo" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
348
|
-
<div class="legend-item">Latched: <span id="l-signal-latched" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
349
|
-
</div>
|
|
350
|
-
<div id="kalman-chart"></div>
|
|
351
|
-
</div>
|
|
352
|
-
<div id="output-panel">
|
|
353
|
-
<div class="section-label">COMBINED WEIGHT OUTPUT</div>
|
|
354
|
-
<div class="legend" style="gap: 4px;">
|
|
355
|
-
<div class="legend-item"><div class="dot" style="background:linear-gradient(to bottom,#8b949e,#8b949e);"></div>Raw: <span id="l-combined-raw" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
356
|
-
<div class="legend-item"><div class="dot" style="background:linear-gradient(to bottom,#2ea043,#f85149);"></div>Echo: <span id="l-combined-echo" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
357
|
-
<div class="legend-item">xMult: <span id="l-mult" class="legend-val" style="font-weight:bold;color:#d2a8ff;">-</span></div>
|
|
358
|
-
<div class="legend-item">S: <span id="l-sell" class="legend-val" style="color:#ff7b72;">-</span></div>
|
|
359
|
-
<div class="legend-item">B: <span id="l-buy" class="legend-val" style="color:#58a6ff;">-</span></div>
|
|
360
|
-
|
|
361
|
-
<div class="group-sep"></div>
|
|
362
|
-
<div class="ctrl alpha"><label for="alpha-slider">α</label><input type="range" id="alpha-slider" min="0" max="100" value="${Math.round(defaultAlpha * 100)}" title="Alpha Mix (AMA vs Kalman)"><span class="val" id="alpha-value">${defaultAlpha.toFixed(2)}</span></div>
|
|
363
|
-
<div class="ctrl dw"><label for="dw-slider">dw</label><input type="range" id="dw-slider" min="0" max="100" value="${Math.round(defaultDispWeight * 100)}" title="Displacement Weight"><span class="val" id="dw-value">${defaultDispWeight.toFixed(2)}</span></div>
|
|
364
|
-
|
|
365
|
-
<div class="group-sep"></div>
|
|
366
|
-
<div class="ctrl nz"><label for="nz-slider">nz%</label><input type="range" id="nz-slider" min="0" max="100" value="${Math.round(defaultNeutralZone * 100)}" title="Neutral Zone %"><span class="val" id="nz-value">${defaultNeutralZone.toFixed(2)}</span></div>
|
|
367
|
-
<div class="ctrl lb"><label for="lb-slider">lb</label><input type="range" id="lb-slider" min="0" max="1000" value="${lbInitSlider}" title="Lookback Bars (${LB_MIN}-${LB_MAX})"><span class="val" id="lb-value">${lookbackBars}</span></div>
|
|
368
|
-
<div class="ctrl ema"><label for="ema-slider">ema</label><input type="range" id="ema-slider" min="${EMA_MIN}" max="${EMA_MAX}" value="${defaultAmaEmaSpan}" title="AMA input EMA span in bars (${EMA_MIN} = off; noise std ~ 1/sqrt(span), lag ~ (span-1)/2 bars; span ~ lb is the balance point)"><span class="val" id="ema-value">${defaultAmaEmaSpan}</span></div>
|
|
369
|
-
<div class="ctrl ms-ama"><label for="ama-ms-slider">amaS%</label><input type="range" id="ama-ms-slider" min="0" max="1000" value="${amaMsInitSlider}" title="AMA Max Slope % per bar (${AMA_MS_MIN}-${AMA_MS_MAX})"><span class="val" id="ama-ms-value">${defaultAmaMaxSlopePct.toFixed(4)}</span></div>
|
|
370
|
-
<div class="ctrl clip"><label for="clip-slider">clip%</label><input type="range" id="clip-slider" min="0" max="${CLIP_PCT_MAX}" value="${Math.min(defaultClipPct, CLIP_PCT_MAX)}" title="Outlier Clip %"><span class="val" id="clip-value">${Math.min(defaultClipPct, CLIP_PCT_MAX)}%</span></div>
|
|
371
|
-
|
|
372
|
-
<div class="group-sep"></div>
|
|
373
|
-
<div class="ctrl th"><label for="th-slider">th%</label><input type="range" id="th-slider" min="0" max="${TH_MAX * 100}" value="${Math.round(defaultMinOutputThreshold * 100)}" title="Minimum pre-gain blended output required before the signal is allowed through (${TH_MIN.toFixed(2)}-${TH_MAX.toFixed(2)})"><span class="val" id="th-value">${defaultMinOutputThreshold.toFixed(2)}</span></div>
|
|
374
|
-
|
|
375
|
-
<div class="group-sep"></div>
|
|
376
|
-
<div class="row-break"></div>
|
|
377
|
-
<div class="ctrl ms-kal"><label for="kal-ms-slider">kalS%</label><input type="range" id="kal-ms-slider" min="0" max="1000" value="${kalMsInitSlider}" title="Kalman Max Slope % (${KAL_MS_MIN}-${KAL_MS_MAX})"><span class="val" id="kal-ms-value">${clampedKalMs.toFixed(2)}</span></div>
|
|
378
|
-
<div class="ctrl kf"><label for="kf-slider">kf</label><input type="range" id="kf-slider" min="${KF_MIN}" max="${KF_MAX}" value="${defaultKalmanSmoothPct}" title="Kalman smoothing blend (${KF_MIN} = raw, 100 = current adaptive smoothing, ${KF_MAX} = stronger smoothing)"><span class="val" id="kf-value">${defaultKalmanSmoothPct}%</span></div>
|
|
379
|
-
<div class="ctrl kfd"><label for="kfd-slider">kfd</label><input type="range" id="kfd-slider" min="${KFD_MIN * 100}" max="${KFD_MAX * 100}" value="${Math.round(defaultKalmanDispScaleMult * 100)}" title="Kalman displacement scale multiplier (${KFD_MIN}x to ${KFD_MAX}x)"><span class="val" id="kfd-value">${defaultKalmanDispScaleMult.toFixed(2)}x</span></div>
|
|
380
|
-
<div class="ctrl dsp"><label for="dsp-slider">dsp</label><input type="range" id="dsp-slider" min="${DSP_MIN * 100}" max="${DSP_MAX * 100}" value="${Math.round(defaultDispScaleMinPct * 100)}" title="Minimum displacement scale floor (${DSP_MIN}x to ${DSP_MAX.toFixed(1)}x)"><span class="val" id="dsp-value">${defaultDispScaleMinPct.toFixed(2)}x</span></div>
|
|
381
|
-
<div class="ctrl kdt"><label for="kdt-slider">kdt</label><input type="range" id="kdt-slider" min="${KDT_MIN * 100}" max="${KDT_MAX * 100}" value="${Math.round(defaultKalmanDispThresholdMult * 100)}" title="Kalman displacement threshold multiplier (${KDT_MIN}x to ${KDT_MAX}x)"><span class="val" id="kdt-value">${defaultKalmanDispThresholdMult.toFixed(2)}x</span></div>
|
|
382
|
-
<div class="ctrl kfs"><label for="kfs-slider">kfs</label><input type="range" id="kfs-slider" min="${KFS_MIN}" max="${KFS_MAX}" value="${defaultKalmanSmoothSpanPct}" title="Adaptive EMA span ratio (${KFS_MIN}% span / ${KFS_MAX}% span; floor fixed at 0)"><span class="val" id="kfs-value">${defaultKalmanSmoothSpanPct}%</span></div>
|
|
383
|
-
<div class="ctrl cf"><label for="cf-slider">cf</label><input type="range" id="cf-slider" min="${CF_MIN}" max="${CF_MAX}" value="${defaultSignalConfirmBars}" title="Signal confirmation bars (0 disables latching; otherwise flips after N opposite echo bars)"><span class="val" id="cf-value">${defaultSignalConfirmBars}</span></div>
|
|
384
|
-
<div class="ctrl off"><label for="gain-slider">gain</label><input type="range" id="gain-slider" min="0" max="1000" value="${gainInitSlider}" title="Output Gain (${GAIN_MIN.toFixed(1)}-${GAIN_MAX.toFixed(1)})"><span class="val" id="gain-value">${clampedGain.toFixed(3)}</span></div>
|
|
385
|
-
<div class="ctrl regime"><label for="regime-slider">regi</label><input type="range" id="regime-slider" min="0" max="${REGI_MAX * 100}" value="${regimeInitSlider}" title="Regime Sensitivity"><span class="val" id="regime-value">${defaultRegimeSensitivity.toFixed(2)}</span></div>
|
|
386
|
-
<button class="copy-btn" id="copy-params-btn">copy</button>
|
|
387
|
-
<button class="paste-btn" id="paste-params-btn">paste</button>
|
|
388
|
-
</div>
|
|
389
|
-
<div id="output-chart"></div>
|
|
390
|
-
</div>
|
|
391
|
-
</div>
|
|
392
|
-
|
|
393
|
-
<div id="paste-confirm">
|
|
394
|
-
<div id="paste-confirm-title">Confirm paste parameters</div>
|
|
395
|
-
<div id="paste-confirm-vals"></div>
|
|
396
|
-
<div id="paste-confirm-btns">
|
|
397
|
-
<button id="paste-confirm-cancel">Cancel</button>
|
|
398
|
-
<button id="paste-confirm-apply">Apply</button>
|
|
399
|
-
</div>
|
|
400
|
-
</div>
|
|
401
|
-
|
|
402
|
-
<script id="payload" type="application/json">${serializeJsonForScript({ dates, prices, hurstArr, peArr, hurstSegments, peSegments, ama3Prices, amaSeedSmaLine, amaSlopePct, kalmanVelocityPctRaw, kalmanVelocityPct, kalmanDisplacementPct, kalmanIsReady, signals, alpha: defaultAlpha, gain: defaultGain, kalmanSmoothPct: defaultKalmanSmoothPct, kalmanDispScaleMult: defaultKalmanDispScaleMult, kalmanDispThresholdMult: defaultKalmanDispThresholdMult, kalmanSmoothSpanPct: defaultKalmanSmoothSpanPct, signalConfirmBars: defaultSignalConfirmBars, neutralZonePct: defaultNeutralZone, dispWeight: defaultDispWeight, amaMaxSlopePct: defaultAmaMaxSlopePct, kalmanMaxSlopePct: defaultKalmanMaxSlopePct, maxDispPct, clipPct: defaultClipPct, minOutputThreshold: defaultMinOutputThreshold, outputClamp: defaultOutputClamp, regimeSensitivity: defaultRegimeSensitivity, absoluteThreshold: defaultAbsoluteThreshold, lookbackBars, amaErPeriod, amaSlowPeriod, amaWarmupBars, amaSlopeReadyBars, realBarCount, amaPctMax, kalPctMax, amaPercentiles, kalPercentiles, amaSlopeLogMin: AMA_MS_LOG_MIN_N, amaSlopeLogMax: AMA_MS_LOG_MAX_N, kalSlopeLogMin: KAL_MS_LOG_MIN_N, kalSlopeLogMax: KAL_MS_LOG_MAX_N, lbLogMin: LB_LOG_MIN_N, lbLogMax: LB_LOG_MAX_N, amaEmaSpan: defaultAmaEmaSpan, gainLogMin: GAIN_LOG_MIN_N, gainLogMax: GAIN_LOG_MAX_N, sliderRanges: SLIDER_RANGES, dispScaleMinPct: defaultDispScaleMinPct, weightMin: MARKET_ADAPTER.DYNAMIC_WEIGHT_MIN_WEIGHT, weightMax: MARKET_ADAPTER.DYNAMIC_WEIGHT_MAX_WEIGHT, marketAdapter: ma, amaWeightConfig, hNodes: [0.5 + MARKET_ADAPTER.HURST_ZONE_BAND, 0.5, 0.5 - MARKET_ADAPTER.HURST_ZONE_BAND], pNodes: MARKET_ADAPTER.PE_NODES, regimeTable: MARKET_ADAPTER.REGIME_TABLE })}</script>
|
|
403
|
-
|
|
404
|
-
<script>
|
|
405
|
-
const data = JSON.parse(document.getElementById('payload').textContent);
|
|
406
|
-
|
|
407
|
-
${EMBEDDED_SHARED_FUNCS}
|
|
408
|
-
|
|
409
|
-
const SYNC_KEY = "dyn-wt-res-v4";
|
|
410
|
-
const Y_AXIS_SIZE = ${Y_AXIS_SIZE};
|
|
411
|
-
const ma = data.marketAdapter || {};
|
|
412
|
-
const amaWeightConfig = data.amaWeightConfig || {};
|
|
413
|
-
const SR = data.sliderRanges ?? ${serializeJsonForScript(SLIDER_RANGES)};
|
|
414
|
-
|
|
415
|
-
const ABSOLUTE_THRESHOLD = data.absoluteThreshold ?? ${JSON.stringify(defaultAbsoluteThreshold)};
|
|
416
|
-
const WEIGHT_MIN = data.weightMin ?? ${JSON.stringify(MARKET_ADAPTER.DYNAMIC_WEIGHT_MIN_WEIGHT)};
|
|
417
|
-
const WEIGHT_MAX = data.weightMax ?? ${JSON.stringify(MARKET_ADAPTER.DYNAMIC_WEIGHT_MAX_WEIGHT)};
|
|
418
|
-
const OUTPUT_CLAMP = data.outputClamp ?? ${JSON.stringify(defaultOutputClamp)};
|
|
419
|
-
const weightDistribution = ${serializeJsonForScript(DEFAULT_CONFIG.weightDistribution)};
|
|
420
|
-
const STATIC_SELL = Number.isFinite(weightDistribution.sell) ? weightDistribution.sell : ${JSON.stringify(DEFAULT_CONFIG.weightDistribution.sell)};
|
|
421
|
-
const STATIC_BUY = Number.isFinite(weightDistribution.buy) ? weightDistribution.buy : ${JSON.stringify(DEFAULT_CONFIG.weightDistribution.buy)};
|
|
422
|
-
|
|
423
|
-
let currentAlpha = data.alpha ?? ${JSON.stringify(defaultAlpha)};
|
|
424
|
-
let currentGain = data.gain ?? ${JSON.stringify(defaultGain)};
|
|
425
|
-
let currentMinOutputThreshold = Math.min(Math.max(data.minOutputThreshold ?? ${JSON.stringify(defaultMinOutputThreshold)}, SR.minOutputThreshold[0]), SR.minOutputThreshold[1]);
|
|
426
|
-
let currentKalmanSmoothPct = data.kalmanSmoothPct ?? ${JSON.stringify(defaultKalmanSmoothPct)};
|
|
427
|
-
let currentKalmanDispScaleMult = data.kalmanDispScaleMult ?? ${JSON.stringify(defaultKalmanDispScaleMult)};
|
|
428
|
-
let currentKalmanDispThresholdMult = data.kalmanDispThresholdMult ?? ${JSON.stringify(defaultKalmanDispThresholdMult)};
|
|
429
|
-
let currentKalmanSmoothSpanPct = data.kalmanSmoothSpanPct ?? ${JSON.stringify(defaultKalmanSmoothSpanPct)};
|
|
430
|
-
let currentDispScaleMinPct = data.dispScaleMinPct ?? ${JSON.stringify(defaultDispScaleMinPct)};
|
|
431
|
-
let currentSignalConfirmBars = data.signalConfirmBars ?? ${JSON.stringify(defaultSignalConfirmBars)};
|
|
432
|
-
let currentNz = data.neutralZonePct ?? ${JSON.stringify(defaultNeutralZone)};
|
|
433
|
-
let currentDw = data.dispWeight ?? ${JSON.stringify(defaultDispWeight)};
|
|
434
|
-
let currentAmaMaxSlopePct = data.amaMaxSlopePct ?? ${JSON.stringify(defaultAmaMaxSlopePct)};
|
|
435
|
-
let currentKalmanMaxSlopePct = data.kalmanMaxSlopePct ?? ${JSON.stringify(defaultKalmanMaxSlopePct)};
|
|
436
|
-
const AMA_MS_LOG_MIN = data.amaSlopeLogMin;
|
|
437
|
-
const AMA_MS_LOG_MAX = data.amaSlopeLogMax;
|
|
438
|
-
const KAL_MS_LOG_MIN = data.kalSlopeLogMin;
|
|
439
|
-
const KAL_MS_LOG_MAX = data.kalSlopeLogMax;
|
|
440
|
-
const amaMsSliderToVal = (pos) => Math.exp(AMA_MS_LOG_MIN + (pos / 1000) * (AMA_MS_LOG_MAX - AMA_MS_LOG_MIN));
|
|
441
|
-
const kalMsSliderToVal = (pos) => Math.exp(KAL_MS_LOG_MIN + (pos / 1000) * (KAL_MS_LOG_MAX - KAL_MS_LOG_MIN));
|
|
442
|
-
|
|
443
|
-
let currentLookbackBars = data.lookbackBars ?? ${JSON.stringify(lookbackBars)};
|
|
444
|
-
let currentAmaEmaSpan = Math.max(SR.amaEmaSpan[0], Math.min(SR.amaEmaSpan[1], Math.round(data.amaEmaSpan ?? 0)));
|
|
445
|
-
let currentAmaSource = data.ama3Prices;
|
|
446
|
-
const LB_LOG_MIN = data.lbLogMin;
|
|
447
|
-
const LB_LOG_MAX = data.lbLogMax;
|
|
448
|
-
const lbSliderToVal = (pos) => Math.round(Math.exp(LB_LOG_MIN + (pos / 1000) * (LB_LOG_MAX - LB_LOG_MIN)));
|
|
449
|
-
const lbValToSlider = (val) => Math.round((Math.log(Math.max(SR.lookbackBars[0], val)) - LB_LOG_MIN) / (LB_LOG_MAX - LB_LOG_MIN) * 1000);
|
|
450
|
-
|
|
451
|
-
const GAIN_LOG_MIN = data.gainLogMin;
|
|
452
|
-
const GAIN_LOG_MAX = data.gainLogMax;
|
|
453
|
-
const gainSliderToVal = (pos) => Math.exp(GAIN_LOG_MIN + (pos / 1000) * (GAIN_LOG_MAX - GAIN_LOG_MIN));
|
|
454
|
-
const gainValToSlider = (val) => Math.round((Math.log(Math.max(Math.exp(GAIN_LOG_MIN), val)) - GAIN_LOG_MIN) / (GAIN_LOG_MAX - GAIN_LOG_MIN) * 1000);
|
|
455
|
-
|
|
456
|
-
let currentClipPct = data.clipPct ?? ${JSON.stringify(defaultClipPct)};
|
|
457
|
-
// Only the clipPct===0 branch value is ever read (recalcWeights reads
|
|
458
|
-
// currentAmaClipThreshold solely when clipping is disabled; otherwise
|
|
459
|
-
// it uses the canonical dynamicClipThreshold from computeAmaSlopeClipThreshold).
|
|
460
|
-
const maxAmaSlope = data.amaPercentiles[data.amaPercentiles.length - 1];
|
|
461
|
-
let currentAmaClipThreshold = currentClipPct === 0 ? maxAmaSlope : Infinity;
|
|
462
|
-
let currentKalClipThreshold = currentClipPct === 0 ? Infinity : data.kalPercentiles[100 - currentClipPct];
|
|
463
|
-
|
|
464
|
-
// Regime table and axis nodes from payload — sourced from MARKET_ADAPTER in constants.ts
|
|
465
|
-
const REGIME_TABLE = data.regimeTable;
|
|
466
|
-
const H_NODES = data.hNodes; // [0.5+band, 0.5, 0.5-band]
|
|
467
|
-
const P_NODES = data.pNodes; // PE_NODES
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Regime multiplier for smooth gating — canonical bilinear interpolation
|
|
471
|
-
* (bilinearInterpolate injected above) plus the dead-band / clamp logic.
|
|
472
|
-
*/
|
|
473
|
-
function getRegimeMultiplier(H, PE) {
|
|
474
|
-
if (H == null || PE == null) return 1.0;
|
|
475
|
-
return bilinearInterpolate(H, PE, REGIME_TABLE, { hNodes: H_NODES, pNodes: P_NODES });
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
let currentRegimeSensitivity = data.regimeSensitivity ?? ma.regimeSensitivity;
|
|
479
|
-
|
|
480
|
-
const currentKalmanVelocityPct = new Array(data.dates.length).fill(null);
|
|
481
|
-
const currentLatchedSignals = new Array(data.dates.length).fill(null);
|
|
482
|
-
const dynamicAmaOff = new Array(data.dates.length).fill(null);
|
|
483
|
-
const dynamicAmaSlopePct = new Array(data.dates.length).fill(null);
|
|
484
|
-
const dynamicAmaSlopePctRaw = new Array(data.dates.length).fill(null);
|
|
485
|
-
const dynamicKalOff = new Array(data.dates.length).fill(null);
|
|
486
|
-
const combinedOff = new Array(data.dates.length).fill(null);
|
|
487
|
-
const combinedSell = new Array(data.dates.length).fill(null);
|
|
488
|
-
const combinedBuy = new Array(data.dates.length).fill(null);
|
|
489
|
-
const echoCombinedOff = new Array(data.dates.length).fill(null);
|
|
490
|
-
const echoCombinedSell = new Array(data.dates.length).fill(null);
|
|
491
|
-
const echoCombinedBuy = new Array(data.dates.length).fill(null);
|
|
492
|
-
const currentMults = new Array(data.dates.length).fill(null);
|
|
493
|
-
let currentOutputAxisMax = 0.5;
|
|
494
|
-
let dynamicClipThreshold = Infinity;
|
|
495
|
-
|
|
496
|
-
// Shared Kalman velocity smoothing (smoothKalmanVelocityPoint /
|
|
497
|
-
// buildKalmanVelocitySeries / resolveKalmanVelocitySmoothingConfig /
|
|
498
|
-
// computeAbsolutePercentileThreshold injected above).
|
|
499
|
-
function recalcKalmanVelocity() {
|
|
500
|
-
const rawSeries = data.kalmanVelocityPctRaw || data.kalmanVelocityPct;
|
|
501
|
-
const dispSeries = data.kalmanDisplacementPct;
|
|
502
|
-
const points = new Array(data.dates.length).fill(null);
|
|
503
|
-
for (let i = 0; i < data.dates.length; i++) {
|
|
504
|
-
points[i] = { velocityPct: rawSeries[i], displacementPct: dispSeries[i] };
|
|
505
|
-
}
|
|
506
|
-
const smoothed = buildKalmanVelocitySeries(points, {
|
|
507
|
-
kalmanSmoothPct: currentKalmanSmoothPct,
|
|
508
|
-
kalmanDispScaleMult: currentKalmanDispScaleMult,
|
|
509
|
-
kalmanDispThresholdMult: currentKalmanDispThresholdMult,
|
|
510
|
-
kalmanSmoothSpanPct: currentKalmanSmoothSpanPct,
|
|
511
|
-
});
|
|
512
|
-
for (let i = 0; i < data.dates.length; i++) {
|
|
513
|
-
currentKalmanVelocityPct[i] = smoothed[i] ?? null;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function recalcKalmanClipThreshold() {
|
|
518
|
-
currentKalClipThreshold = computeAbsolutePercentileThreshold(
|
|
519
|
-
currentKalmanVelocityPct,
|
|
520
|
-
currentClipPct,
|
|
521
|
-
Infinity
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
function signalDirectionForIndex(i) {
|
|
526
|
-
const sig = data.signals[i];
|
|
527
|
-
if (!sig) return 0;
|
|
528
|
-
if (sig.includes('BULL')) return 1;
|
|
529
|
-
if (sig.includes('BEAR')) return -1;
|
|
530
|
-
return 0;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
function directionToSignal(dir) {
|
|
534
|
-
if (dir > 0) return 'BULLISH_DISPLACEMENT';
|
|
535
|
-
if (dir < 0) return 'BEARISH_DISPLACEMENT';
|
|
536
|
-
return 'NEUTRAL';
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
function recalcLatchedSignals() {
|
|
540
|
-
const confirmBars = Math.max(SR.signalConfirmBars[0], Math.min(SR.signalConfirmBars[1], currentSignalConfirmBars));
|
|
541
|
-
if (confirmBars === 0) {
|
|
542
|
-
for (let i = 0; i < data.dates.length; i++) {
|
|
543
|
-
currentLatchedSignals[i] = data.signals[i] || null;
|
|
544
|
-
}
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
let latchedDir = 0;
|
|
548
|
-
let pendingDir = 0;
|
|
549
|
-
let pendingCount = 0;
|
|
550
|
-
|
|
551
|
-
for (let i = 0; i < data.dates.length; i++) {
|
|
552
|
-
const raw = data.signals[i];
|
|
553
|
-
const echoDir = signalDirectionForIndex(i);
|
|
554
|
-
|
|
555
|
-
if (raw == null) {
|
|
556
|
-
currentLatchedSignals[i] = null;
|
|
557
|
-
pendingDir = 0;
|
|
558
|
-
pendingCount = 0;
|
|
559
|
-
continue;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
if (echoDir === 0) {
|
|
563
|
-
currentLatchedSignals[i] = directionToSignal(latchedDir);
|
|
564
|
-
continue;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
if (latchedDir === 0) {
|
|
568
|
-
latchedDir = echoDir;
|
|
569
|
-
pendingDir = 0;
|
|
570
|
-
pendingCount = 0;
|
|
571
|
-
currentLatchedSignals[i] = directionToSignal(latchedDir);
|
|
572
|
-
continue;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
if (echoDir === latchedDir) {
|
|
576
|
-
pendingDir = 0;
|
|
577
|
-
pendingCount = 0;
|
|
578
|
-
currentLatchedSignals[i] = directionToSignal(latchedDir);
|
|
579
|
-
continue;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
if (pendingDir !== echoDir) {
|
|
583
|
-
pendingDir = echoDir;
|
|
584
|
-
pendingCount = 1;
|
|
585
|
-
} else {
|
|
586
|
-
pendingCount++;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
if (pendingCount >= confirmBars) {
|
|
590
|
-
latchedDir = echoDir;
|
|
591
|
-
pendingDir = 0;
|
|
592
|
-
pendingCount = 0;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
currentLatchedSignals[i] = directionToSignal(latchedDir);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
* Research-only ema knob — EMA low-pass over the AMA input before the
|
|
601
|
-
* slope is taken (EMA-then-difference == difference-then-EMA, both are
|
|
602
|
-
* linear filters). span bars, alpha = 2/(span+1): noise std shrinks ~
|
|
603
|
-
* 1/sqrt(span), lag grows ~ (span-1)/2 bars. Seeded with an SMA over the
|
|
604
|
-
* first 'span' finite values (mirrors the AMA seed SMA) so the transient
|
|
605
|
-
* is gone before any slope bar can go ready. Nulls (warmup / trailing
|
|
606
|
-
* padding) stay null so no fabricated values reach the clip-percentile
|
|
607
|
-
* pool or the offset pipeline. span <= 0 returns the input untouched.
|
|
608
|
-
*/
|
|
609
|
-
function buildEmaSeries(values, span) {
|
|
610
|
-
if (!(span > 0) || !Array.isArray(values)) return values;
|
|
611
|
-
const n = values.length;
|
|
612
|
-
const out = new Array(n);
|
|
613
|
-
const alpha = 2 / (span + 1);
|
|
614
|
-
let seedSum = 0, seedCount = 0;
|
|
615
|
-
for (let i = 0; i < n && seedCount < span; i++) {
|
|
616
|
-
const v = values[i];
|
|
617
|
-
if (v == null || !Number.isFinite(v)) continue;
|
|
618
|
-
seedSum += v; seedCount++;
|
|
619
|
-
}
|
|
620
|
-
let prev = seedCount > 0 ? seedSum / seedCount : null;
|
|
621
|
-
for (let i = 0; i < n; i++) {
|
|
622
|
-
const v = values[i];
|
|
623
|
-
if (v == null || !Number.isFinite(v)) { out[i] = null; continue; }
|
|
624
|
-
prev = prev == null ? v : alpha * v + (1 - alpha) * prev;
|
|
625
|
-
out[i] = prev;
|
|
626
|
-
}
|
|
627
|
-
return out;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
function computeSlopeAtIndex(idx, lb, values) {
|
|
631
|
-
// Canonical AMA slope % (computeAverageAmaSlopePct injected above).
|
|
632
|
-
const sp = computeAverageAmaSlopePct(values[idx], values[idx - lb], lb);
|
|
633
|
-
return sp == null ? 0 : sp;
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
function recalcInputs() {
|
|
637
|
-
recalcKalmanVelocity();
|
|
638
|
-
recalcKalmanClipThreshold();
|
|
639
|
-
recalcLatchedSignals();
|
|
640
|
-
currentAmaSource = buildEmaSeries(data.ama3Prices, currentAmaEmaSpan);
|
|
641
|
-
const lb = currentLookbackBars;
|
|
642
|
-
const amaErWarmup = Math.max(0, Number.isFinite(data.amaErPeriod) ? Math.ceil(data.amaErPeriod) : ${JSON.stringify(MARKET_ADAPTER.AMAS[MARKET_ADAPTER.DEFAULT_AMA_KEY as keyof typeof MARKET_ADAPTER.AMAS].erPeriod)});
|
|
643
|
-
const amaReadyBar = Math.max(lb, amaErWarmup + lb);
|
|
644
|
-
|
|
645
|
-
// Recompute clip threshold based on current lookback — canonical
|
|
646
|
-
// implementation (computeAmaSlopeClipThreshold injected above),
|
|
647
|
-
// shared with the live market adapter service. Trailing padded
|
|
648
|
-
// nulls beyond realBarCount are skipped by its finiteness guards.
|
|
649
|
-
// Clip pool follows the (possibly EMA-filtered) AMA input so the
|
|
650
|
-
// percentile threshold matches the series the offsets derive from.
|
|
651
|
-
dynamicClipThreshold = computeAmaSlopeClipThreshold(currentAmaSource, amaErWarmup, lb, currentClipPct);
|
|
652
|
-
|
|
653
|
-
for (let i = 0; i < data.realBarCount; i++) {
|
|
654
|
-
// AMA slope % for the display panel (offsets computed in
|
|
655
|
-
// recalcWeights): the raw reference line from the unfiltered AMA
|
|
656
|
-
// input, the plotted series from the EMA-filtered input.
|
|
657
|
-
dynamicAmaSlopePctRaw[i] = i < amaReadyBar ? null : computeSlopeAtIndex(i, lb, data.ama3Prices);
|
|
658
|
-
dynamicAmaSlopePct[i] = i < amaReadyBar ? null : computeSlopeAtIndex(i, lb, currentAmaSource);
|
|
659
|
-
}
|
|
660
|
-
for (let i = data.realBarCount; i < data.dates.length; i++) {
|
|
661
|
-
dynamicAmaSlopePct[i] = null;
|
|
662
|
-
dynamicAmaSlopePctRaw[i] = null;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
function recalcWeights() {
|
|
667
|
-
// Normalize each channel by the configured clamp so alpha remains a pure ratio knob.
|
|
668
|
-
// Gain then scales the blended output linearly after the dead-band decision.
|
|
669
|
-
currentOutputAxisMax = Math.max(0.5, OUTPUT_CLAMP);
|
|
670
|
-
const channelNorm = Math.max(Math.abs(OUTPUT_CLAMP), 1e-9);
|
|
671
|
-
const outputThreshold = currentMinOutputThreshold;
|
|
672
|
-
const n = data.realBarCount;
|
|
673
|
-
|
|
674
|
-
// Per-bar regime multiplier (display + pipeline input)
|
|
675
|
-
for (let i = 0; i < data.dates.length; i++) {
|
|
676
|
-
if (i >= n) { currentMults[i] = null; continue; }
|
|
677
|
-
const baseMult = getRegimeMultiplier(data.hurstArr[i], data.peArr[i]);
|
|
678
|
-
// Use power for sensitivity: pushes away from 1.0 in both directions without flipping sign
|
|
679
|
-
const rawMult = Math.pow(baseMult, currentRegimeSensitivity);
|
|
680
|
-
// Dead-band: only apply regime multiplier when |mult - 1.0| >= absoluteThreshold
|
|
681
|
-
// Clamp to 1.0 max: regime only dampens, never amplifies
|
|
682
|
-
currentMults[i] = Math.abs(rawMult - 1.0) >= ABSOLUTE_THRESHOLD ? Math.min(rawMult, 1.0) : 1.0;
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
// Per-bar offset pipeline — canonical implementation (computeDynamicWeightSeries
|
|
686
|
-
// injected above), shared with the live market adapter service.
|
|
687
|
-
const res = computeDynamicWeightSeries({
|
|
688
|
-
amaValues: currentAmaSource,
|
|
689
|
-
kalmanVelocityPct: currentKalmanVelocityPct,
|
|
690
|
-
kalmanDisplacementPct: data.kalmanDisplacementPct,
|
|
691
|
-
kalmanIsReady: data.kalmanIsReady,
|
|
692
|
-
regimeMultipliers: currentMults,
|
|
693
|
-
lookbackBars: currentLookbackBars,
|
|
694
|
-
amaErPeriod: data.amaErPeriod,
|
|
695
|
-
amaClipThreshold: currentClipPct > 0 ? dynamicClipThreshold : currentAmaClipThreshold,
|
|
696
|
-
kalClipThreshold: currentKalClipThreshold,
|
|
697
|
-
neutralZonePct: currentNz,
|
|
698
|
-
amaMaxSlopePct: currentAmaMaxSlopePct,
|
|
699
|
-
kalmanMaxSlopePct: currentKalmanMaxSlopePct,
|
|
700
|
-
offsetClamp: OUTPUT_CLAMP,
|
|
701
|
-
dispScaleMinPct: currentDispScaleMinPct,
|
|
702
|
-
alpha: currentAlpha,
|
|
703
|
-
dw: currentDw,
|
|
704
|
-
gain: currentGain,
|
|
705
|
-
minOutputThreshold: currentMinOutputThreshold,
|
|
706
|
-
signalConfirmBars: currentSignalConfirmBars,
|
|
707
|
-
clampFinalOutput: false,
|
|
708
|
-
});
|
|
709
|
-
|
|
710
|
-
for (let i = 0; i < data.dates.length; i++) {
|
|
711
|
-
if (i >= n) {
|
|
712
|
-
dynamicAmaOff[i] = null;
|
|
713
|
-
dynamicKalOff[i] = null;
|
|
714
|
-
combinedOff[i] = null;
|
|
715
|
-
combinedSell[i] = null;
|
|
716
|
-
combinedBuy[i] = null;
|
|
717
|
-
echoCombinedOff[i] = null;
|
|
718
|
-
echoCombinedSell[i] = null;
|
|
719
|
-
echoCombinedBuy[i] = null;
|
|
720
|
-
continue;
|
|
721
|
-
}
|
|
722
|
-
const aOff = res.amaOffsets[i];
|
|
723
|
-
const kOff = res.kalmanOffsets[i];
|
|
724
|
-
const cOff = res.combinedOffSeries[i];
|
|
725
|
-
const eOff = res.echoedOffSeries[i];
|
|
726
|
-
dynamicAmaOff[i] = aOff;
|
|
727
|
-
// Keep pre-warmup bars as gaps (not flat 0) to match the historical
|
|
728
|
-
// research-chart rendering: the Kalman channel contributes nothing
|
|
729
|
-
// until the analyzer reports ready with a measurable velocity.
|
|
730
|
-
const kalReady = data.kalmanIsReady[i] === true
|
|
731
|
-
&& currentKalmanVelocityPct[i] != null
|
|
732
|
-
&& data.kalmanDisplacementPct[i] != null;
|
|
733
|
-
if (!kalReady) {
|
|
734
|
-
dynamicKalOff[i] = null;
|
|
735
|
-
combinedOff[i] = null;
|
|
736
|
-
combinedSell[i] = null;
|
|
737
|
-
combinedBuy[i] = null;
|
|
738
|
-
echoCombinedOff[i] = null;
|
|
739
|
-
echoCombinedSell[i] = null;
|
|
740
|
-
echoCombinedBuy[i] = null;
|
|
741
|
-
continue;
|
|
742
|
-
}
|
|
743
|
-
dynamicKalOff[i] = kOff;
|
|
744
|
-
combinedOff[i] = cOff;
|
|
745
|
-
combinedSell[i] = Math.max(WEIGHT_MIN, Math.min(WEIGHT_MAX, Math.round((STATIC_SELL - cOff) * 100) / 100));
|
|
746
|
-
combinedBuy[i] = Math.max(WEIGHT_MIN, Math.min(WEIGHT_MAX, Math.round((STATIC_BUY + cOff) * 100) / 100));
|
|
747
|
-
echoCombinedOff[i] = eOff;
|
|
748
|
-
echoCombinedSell[i] = Math.max(WEIGHT_MIN, Math.min(WEIGHT_MAX, Math.round((STATIC_SELL - eOff) * 100) / 100));
|
|
749
|
-
echoCombinedBuy[i] = Math.max(WEIGHT_MIN, Math.min(WEIGHT_MAX, Math.round((STATIC_BUY + eOff) * 100) / 100));
|
|
750
|
-
currentOutputAxisMax = Math.max(currentOutputAxisMax, Math.abs(cOff), Math.abs(eOff));
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
recalcInputs();
|
|
754
|
-
recalcWeights();
|
|
755
|
-
|
|
756
|
-
const xMin = data.dates[0];
|
|
757
|
-
const xMax = data.dates[data.dates.length - 1];
|
|
758
|
-
let pendingRange = null;
|
|
759
|
-
let pendingRangeRaf = 0;
|
|
760
|
-
let priceChart, amaChart, kalmanChart, outputChart;
|
|
761
|
-
let charts;
|
|
762
|
-
|
|
763
|
-
${UPLOT_SHARED_SCRIPT}
|
|
764
|
-
|
|
765
|
-
function refreshChartsPreservingZoom() {
|
|
766
|
-
const xs = outputChart?.scales?.x;
|
|
767
|
-
const savedX = xs ? {
|
|
768
|
-
min: Number.isFinite(xs.min) ? xs.min : xMin,
|
|
769
|
-
max: Number.isFinite(xs.max) ? xs.max : xMax,
|
|
770
|
-
} : null;
|
|
771
|
-
|
|
772
|
-
amaChart.setData([data.dates, dynamicAmaSlopePctRaw, dynamicAmaSlopePct], false);
|
|
773
|
-
kalmanChart.setData([data.dates, currentKalmanVelocityPct, data.kalmanDisplacementPct], false);
|
|
774
|
-
outputChart.setData([data.dates, combinedOff, echoCombinedOff], false);
|
|
775
|
-
|
|
776
|
-
if (savedX) {
|
|
777
|
-
charts.forEach(c => c.batch(() => c.setScale('x', savedX)));
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
let lastLiveIdx = data.realBarCount - 1;
|
|
782
|
-
|
|
783
|
-
function updateLegend(idx) {
|
|
784
|
-
if (idx == null) return;
|
|
785
|
-
lastLiveIdx = idx;
|
|
786
|
-
|
|
787
|
-
const price = data.prices[idx];
|
|
788
|
-
const priceEl = document.getElementById('l-price');
|
|
789
|
-
if (price == null) { priceEl.textContent = '-'; priceEl.style.color = '#8b949e'; }
|
|
790
|
-
else { priceEl.textContent = price.toFixed(4); priceEl.style.color = '#58a6ff'; }
|
|
791
|
-
|
|
792
|
-
const ama3 = data.ama3Prices[idx];
|
|
793
|
-
const ama3El = document.getElementById('l-ama3');
|
|
794
|
-
if (ama3 == null) { ama3El.textContent = '-'; ama3El.style.color = '#8b949e'; }
|
|
795
|
-
else { ama3El.textContent = ama3.toFixed(4); ama3El.style.color = '#e3b341'; }
|
|
796
|
-
|
|
797
|
-
const seedSma = data.amaSeedSmaLine[idx];
|
|
798
|
-
const seedSmaEl = document.getElementById('l-seed-sma');
|
|
799
|
-
if (seedSma == null) { seedSmaEl.textContent = '-'; seedSmaEl.style.color = '#8b949e'; }
|
|
800
|
-
else { seedSmaEl.textContent = seedSma.toFixed(4); seedSmaEl.style.color = '#8b949e'; }
|
|
801
|
-
|
|
802
|
-
const sp = dynamicAmaSlopePct[idx];
|
|
803
|
-
const spEl = document.getElementById('l-ama-slope');
|
|
804
|
-
if (sp == null) { spEl.textContent = '-'; spEl.style.color = '#8b949e'; }
|
|
805
|
-
else { spEl.textContent = (sp >= 0 ? '+' : '') + (sp * 10).toFixed(3) + '‰'; spEl.style.color = sp > 0.01 ? '#2ea043' : sp < -0.01 ? '#f85149' : '#8b949e'; }
|
|
806
|
-
|
|
807
|
-
const spRaw = dynamicAmaSlopePctRaw[idx];
|
|
808
|
-
const spRawEl = document.getElementById('l-ama-slope-raw');
|
|
809
|
-
if (spRaw == null) { spRawEl.textContent = '-'; spRawEl.style.color = '#8b949e'; }
|
|
810
|
-
else { spRawEl.textContent = (spRaw >= 0 ? '+' : '') + (spRaw * 10).toFixed(3) + '‰'; spRawEl.style.color = '#8b949e'; }
|
|
811
|
-
|
|
812
|
-
const vp = currentKalmanVelocityPct[idx];
|
|
813
|
-
const vpEl = document.getElementById('l-kal-vel');
|
|
814
|
-
if (vp == null) { vpEl.textContent = '-'; vpEl.style.color = '#8b949e'; }
|
|
815
|
-
else { vpEl.textContent = (vp >= 0 ? '+' : '') + vp.toFixed(3) + '%'; vpEl.style.color = vp > 0.01 ? '#2ea043' : vp < -0.01 ? '#f85149' : '#8b949e'; }
|
|
816
|
-
|
|
817
|
-
const dp = data.kalmanDisplacementPct[idx];
|
|
818
|
-
const dpEl = document.getElementById('l-kal-disp');
|
|
819
|
-
if (dp == null) { dpEl.textContent = '-'; dpEl.style.color = '#8b949e'; }
|
|
820
|
-
else { dpEl.textContent = (dp >= 0 ? '+' : '') + dp.toFixed(2) + '%'; dpEl.style.color = dp > 0.3 ? '#2ea043' : dp < -0.3 ? '#f85149' : '#8b949e'; }
|
|
821
|
-
|
|
822
|
-
const sig = data.signals[idx];
|
|
823
|
-
const echoSig = directionToSignal(signalDirectionForIndex(idx));
|
|
824
|
-
const latchedSig = currentLatchedSignals[idx];
|
|
825
|
-
const sigEl = document.getElementById('l-signal');
|
|
826
|
-
if (!sig) { sigEl.textContent = '-'; sigEl.style.color = '#8b949e'; }
|
|
827
|
-
else if (sig.includes('BULL')) { sigEl.textContent = '\u25b2 BULL'; sigEl.style.color = '#2ea043'; }
|
|
828
|
-
else if (sig.includes('BEAR')) { sigEl.textContent = '\u25bc BEAR'; sigEl.style.color = '#f85149'; }
|
|
829
|
-
else if (sig === 'EQUILIBRIUM') { sigEl.textContent = '\u2248 EQ'; sigEl.style.color = '#58a6ff'; }
|
|
830
|
-
else { sigEl.textContent = '\u25cb NEU'; sigEl.style.color = '#8b949e'; }
|
|
831
|
-
const echoEl = document.getElementById('l-signal-echo');
|
|
832
|
-
if (!echoSig) { echoEl.textContent = '-'; echoEl.style.color = '#8b949e'; }
|
|
833
|
-
else if (echoSig.includes('BULL')) { echoEl.textContent = '\u25b2 BULL'; echoEl.style.color = '#3fb950'; }
|
|
834
|
-
else if (echoSig.includes('BEAR')) { echoEl.textContent = '\u25bc BEAR'; echoEl.style.color = '#ff7b72'; }
|
|
835
|
-
else { echoEl.textContent = '\u25cb NEU'; echoEl.style.color = '#8b949e'; }
|
|
836
|
-
const latchedEl = document.getElementById('l-signal-latched');
|
|
837
|
-
if (!latchedSig) { latchedEl.textContent = '-'; latchedEl.style.color = '#8b949e'; }
|
|
838
|
-
else if (latchedSig.includes('BULL')) { latchedEl.textContent = '\u25b2 BULL'; latchedEl.style.color = '#3fb950'; }
|
|
839
|
-
else if (latchedSig.includes('BEAR')) { latchedEl.textContent = '\u25bc BEAR'; latchedEl.style.color = '#ff7b72'; }
|
|
840
|
-
else if (latchedSig === 'EQUILIBRIUM') { latchedEl.textContent = '\u2248 EQ'; latchedEl.style.color = '#79c0ff'; }
|
|
841
|
-
else { latchedEl.textContent = '\u25cb NEU'; latchedEl.style.color = '#8b949e'; }
|
|
842
|
-
|
|
843
|
-
const cRaw = combinedOff[idx];
|
|
844
|
-
const cRawEl = document.getElementById('l-combined-raw');
|
|
845
|
-
if (cRaw == null) { cRawEl.textContent = '-'; cRawEl.style.color = '#8b949e'; }
|
|
846
|
-
else { cRawEl.textContent = (cRaw >= 0 ? '+' : '') + cRaw.toFixed(3); cRawEl.style.color = '#8b949e'; }
|
|
847
|
-
|
|
848
|
-
const cEcho = echoCombinedOff[idx];
|
|
849
|
-
const cEchoEl = document.getElementById('l-combined-echo');
|
|
850
|
-
if (cEcho == null) { cEchoEl.textContent = '-'; cEchoEl.style.color = '#8b949e'; }
|
|
851
|
-
else { cEchoEl.textContent = (cEcho >= 0 ? '+' : '') + cEcho.toFixed(3); cEchoEl.style.color = cEcho > 0.01 ? '#2ea043' : cEcho < -0.01 ? '#f85149' : '#8b949e'; }
|
|
852
|
-
|
|
853
|
-
const mult = currentMults[idx];
|
|
854
|
-
const multEl = document.getElementById('l-mult');
|
|
855
|
-
if (mult == null) { multEl.textContent = '-'; }
|
|
856
|
-
else { multEl.textContent = 'x' + mult.toFixed(2); multEl.style.color = mult > 1.05 ? '#3fb950' : mult < 0.95 ? '#f85149' : '#d2a8ff'; }
|
|
857
|
-
|
|
858
|
-
document.getElementById('l-sell').textContent = echoCombinedSell[idx] != null ? echoCombinedSell[idx].toFixed(2) : '-';
|
|
859
|
-
document.getElementById('l-buy').textContent = echoCombinedBuy[idx] != null ? echoCombinedBuy[idx].toFixed(2) : '-';
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
function makeSignalBgHook(scaleKey) {
|
|
863
|
-
return u => {
|
|
864
|
-
const { ctx, bbox } = u;
|
|
865
|
-
ctx.save();
|
|
866
|
-
ctx.beginPath(); ctx.rect(bbox.left, bbox.top, bbox.width, bbox.height); ctx.clip();
|
|
867
|
-
ctx.globalCompositeOperation = 'destination-over';
|
|
868
|
-
let i = 0;
|
|
869
|
-
while (i < data.signals.length) {
|
|
870
|
-
const s = currentLatchedSignals[i] || data.signals[i];
|
|
871
|
-
if (!s || i >= data.realBarCount) { i++; continue; }
|
|
872
|
-
const isBull = s.includes('BULL');
|
|
873
|
-
const isBear = s.includes('BEAR');
|
|
874
|
-
let j = i + 1;
|
|
875
|
-
while (j < data.realBarCount) {
|
|
876
|
-
const sj = currentLatchedSignals[j] || data.signals[j];
|
|
877
|
-
if (sj !== s) break;
|
|
878
|
-
j++;
|
|
879
|
-
}
|
|
880
|
-
const x0 = u.valToPos(data.dates[i], 'x', true);
|
|
881
|
-
const x1 = j < data.realBarCount ? u.valToPos(data.dates[j], 'x', true) : bbox.left + bbox.width;
|
|
882
|
-
if (isBull) { ctx.fillStyle = 'rgba(46,160,67,0.06)'; ctx.fillRect(x0, bbox.top, x1 - x0, bbox.height); }
|
|
883
|
-
else if (isBear) { ctx.fillStyle = 'rgba(248,81,73,0.06)'; ctx.fillRect(x0, bbox.top, x1 - x0, bbox.height); }
|
|
884
|
-
i = j;
|
|
885
|
-
}
|
|
886
|
-
// Neutral zone band
|
|
887
|
-
if (scaleKey) {
|
|
888
|
-
const nzY = u.valToPos(currentNz, scaleKey, true);
|
|
889
|
-
const nzYNeg = u.valToPos(-currentNz, scaleKey, true);
|
|
890
|
-
ctx.globalCompositeOperation = 'source-over';
|
|
891
|
-
ctx.fillStyle = 'rgba(139,148,158,0.06)';
|
|
892
|
-
ctx.fillRect(bbox.left, Math.min(nzY, nzYNeg), bbox.width, Math.abs(nzYNeg - nzY));
|
|
893
|
-
}
|
|
894
|
-
ctx.restore();
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
function makePctFillHook(values, scaleKey, posColor, negColor, strokeStyle = 'rgba(255,255,255,0.35)') {
|
|
899
|
-
return u => {
|
|
900
|
-
const { ctx, bbox } = u;
|
|
901
|
-
ctx.save();
|
|
902
|
-
ctx.beginPath(); ctx.rect(bbox.left, bbox.top, bbox.width, bbox.height); ctx.clip();
|
|
903
|
-
const zeroY = u.valToPos(0, scaleKey, true);
|
|
904
|
-
const path = new Path2D();
|
|
905
|
-
let inSeg = false, lastX = 0;
|
|
906
|
-
for (let i = 0; i < values.length; i++) {
|
|
907
|
-
const v = values[i];
|
|
908
|
-
if (v === null) { if (inSeg) { path.lineTo(lastX, zeroY); inSeg = false; } continue; }
|
|
909
|
-
const x = u.valToPos(data.dates[i], 'x', true);
|
|
910
|
-
const y = u.valToPos(v, scaleKey, true);
|
|
911
|
-
if (!inSeg) { path.moveTo(x, zeroY); path.lineTo(x, y); inSeg = true; }
|
|
912
|
-
else path.lineTo(x, y);
|
|
913
|
-
lastX = x;
|
|
914
|
-
}
|
|
915
|
-
if (inSeg) path.lineTo(lastX, zeroY);
|
|
916
|
-
ctx.save();
|
|
917
|
-
ctx.beginPath(); ctx.rect(bbox.left, bbox.top, bbox.width, zeroY - bbox.top); ctx.clip();
|
|
918
|
-
ctx.fillStyle = posColor; ctx.fill(path);
|
|
919
|
-
ctx.restore();
|
|
920
|
-
ctx.save();
|
|
921
|
-
ctx.beginPath(); ctx.rect(bbox.left, zeroY, bbox.width, bbox.top + bbox.height - zeroY); ctx.clip();
|
|
922
|
-
ctx.fillStyle = negColor; ctx.fill(path);
|
|
923
|
-
ctx.restore();
|
|
924
|
-
if (strokeStyle) {
|
|
925
|
-
ctx.strokeStyle = strokeStyle; ctx.lineWidth = 1; ctx.stroke(path);
|
|
926
|
-
ctx.strokeStyle = 'rgba(255,255,255,0.15)'; ctx.lineWidth = 1;
|
|
927
|
-
ctx.beginPath(); ctx.moveTo(bbox.left, zeroY); ctx.lineTo(bbox.left + bbox.width, zeroY); ctx.stroke();
|
|
928
|
-
}
|
|
929
|
-
ctx.restore();
|
|
930
|
-
};
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
function makeClampLineHook(scaleKey, clampValue, label = 'clamp') {
|
|
934
|
-
return u => {
|
|
935
|
-
const { ctx, bbox } = u;
|
|
936
|
-
ctx.save();
|
|
937
|
-
ctx.beginPath(); ctx.rect(bbox.left, bbox.top, bbox.width, bbox.height); ctx.clip();
|
|
938
|
-
|
|
939
|
-
const y = u.valToPos(clampValue, scaleKey, true);
|
|
940
|
-
ctx.strokeStyle = '#a371f7';
|
|
941
|
-
ctx.shadowColor = 'rgba(163,113,247,0.65)';
|
|
942
|
-
ctx.shadowBlur = 5;
|
|
943
|
-
ctx.lineWidth = 1.5;
|
|
944
|
-
ctx.setLineDash([5, 4]);
|
|
945
|
-
ctx.beginPath();
|
|
946
|
-
ctx.moveTo(bbox.left, y);
|
|
947
|
-
ctx.lineTo(bbox.left + bbox.width, y);
|
|
948
|
-
ctx.stroke();
|
|
949
|
-
ctx.setLineDash([]);
|
|
950
|
-
ctx.shadowBlur = 0;
|
|
951
|
-
ctx.shadowColor = 'transparent';
|
|
952
|
-
|
|
953
|
-
if (label) {
|
|
954
|
-
ctx.font = 'bold 10px Segoe UI, sans-serif';
|
|
955
|
-
ctx.textBaseline = 'middle';
|
|
956
|
-
const textW = ctx.measureText(label).width + 8;
|
|
957
|
-
const textX = Math.max(bbox.left + 4, bbox.left + bbox.width - textW - 2);
|
|
958
|
-
const textY = y - 8;
|
|
959
|
-
ctx.fillStyle = 'rgba(11,14,20,0.82)';
|
|
960
|
-
ctx.fillRect(textX - 4, textY - 7, textW, 14);
|
|
961
|
-
ctx.fillStyle = '#a371f7';
|
|
962
|
-
ctx.fillText(label, textX, textY);
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
ctx.restore();
|
|
966
|
-
};
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
function makeClampPairHooks(scaleKey, clampValue) {
|
|
970
|
-
return [
|
|
971
|
-
makeClampLineHook(scaleKey, clampValue, 'clamp ' + clampValue.toFixed(2)),
|
|
972
|
-
makeClampLineHook(scaleKey, -clampValue, 'clamp -' + clampValue.toFixed(2)),
|
|
973
|
-
];
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
const cursorCfg = ${makeCursorConfig()};
|
|
977
|
-
|
|
978
|
-
const TIME_MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
979
|
-
|
|
980
|
-
function pad2(n) {
|
|
981
|
-
return String(n).padStart(2, '0');
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
function formatTimeLabel(tsSec, spanSec) {
|
|
985
|
-
const d = new Date(tsSec * 1000);
|
|
986
|
-
if (!Number.isFinite(spanSec)) spanSec = 0;
|
|
987
|
-
|
|
988
|
-
if (spanSec >= 365 * 24 * 3600 * 2) {
|
|
989
|
-
return String(d.getUTCFullYear());
|
|
990
|
-
}
|
|
991
|
-
if (spanSec >= 90 * 24 * 3600) {
|
|
992
|
-
return TIME_MONTHS[d.getUTCMonth()] + ' ' + d.getUTCFullYear();
|
|
993
|
-
}
|
|
994
|
-
if (spanSec >= 14 * 24 * 3600) {
|
|
995
|
-
return TIME_MONTHS[d.getUTCMonth()] + ' ' + d.getUTCDate();
|
|
996
|
-
}
|
|
997
|
-
return TIME_MONTHS[d.getUTCMonth()] + ' ' + d.getUTCDate() + ' ' + pad2(d.getUTCHours()) + ':' + pad2(d.getUTCMinutes());
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
function makeTimeAxis(showLabels = false) {
|
|
1001
|
-
return {
|
|
1002
|
-
show: true,
|
|
1003
|
-
stroke: '#ffffff',
|
|
1004
|
-
grid: { stroke: '#1c2128' },
|
|
1005
|
-
ticks: { stroke: '#30363d', width: 1 },
|
|
1006
|
-
size: showLabels ? 24 : 0,
|
|
1007
|
-
font: '11px Segoe UI, sans-serif',
|
|
1008
|
-
values: showLabels ? (u, vals) => {
|
|
1009
|
-
const xScale = u.scales.x || {};
|
|
1010
|
-
const spanSec = Number.isFinite(xScale.min) && Number.isFinite(xScale.max)
|
|
1011
|
-
? Math.max(0, xScale.max - xScale.min)
|
|
1012
|
-
: (xMax - xMin);
|
|
1013
|
-
return vals.map((ts) => formatTimeLabel(ts, spanSec));
|
|
1014
|
-
} : () => [],
|
|
1015
|
-
};
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
function init() {
|
|
1019
|
-
// Force all sliders to match JS state — overrides browser form-restore memory
|
|
1020
|
-
document.getElementById('alpha-slider').value = Math.round(currentAlpha * 100);
|
|
1021
|
-
document.getElementById('ama-ms-slider').value = Math.round((Math.log(currentAmaMaxSlopePct) - AMA_MS_LOG_MIN) / (AMA_MS_LOG_MAX - AMA_MS_LOG_MIN) * 1000);
|
|
1022
|
-
document.getElementById('kal-ms-slider').value = Math.round((Math.log(currentKalmanMaxSlopePct) - KAL_MS_LOG_MIN) / (KAL_MS_LOG_MAX - KAL_MS_LOG_MIN) * 1000);
|
|
1023
|
-
document.getElementById('th-slider').value = Math.round(currentMinOutputThreshold * 100);
|
|
1024
|
-
document.getElementById('th-value').textContent = currentMinOutputThreshold.toFixed(2);
|
|
1025
|
-
document.getElementById('gain-slider').value = gainValToSlider(currentGain);
|
|
1026
|
-
document.getElementById('kf-slider').value = currentKalmanSmoothPct;
|
|
1027
|
-
document.getElementById('kfd-slider').value = Math.round(currentKalmanDispScaleMult * 100);
|
|
1028
|
-
document.getElementById('dsp-slider').value = Math.round(currentDispScaleMinPct * 100);
|
|
1029
|
-
document.getElementById('kdt-slider').value = Math.round(currentKalmanDispThresholdMult * 100);
|
|
1030
|
-
document.getElementById('kfs-slider').value = currentKalmanSmoothSpanPct;
|
|
1031
|
-
document.getElementById('cf-slider').value = currentSignalConfirmBars;
|
|
1032
|
-
document.getElementById('clip-slider').value = currentClipPct;
|
|
1033
|
-
document.getElementById('nz-slider').value = Math.round(currentNz * 100);
|
|
1034
|
-
document.getElementById('lb-slider').value = lbValToSlider(currentLookbackBars);
|
|
1035
|
-
document.getElementById('ema-slider').value = currentAmaEmaSpan;
|
|
1036
|
-
|
|
1037
|
-
const priceEl = document.getElementById('price-panel');
|
|
1038
|
-
const amaEl = document.getElementById('ama-panel');
|
|
1039
|
-
const kalmanEl = document.getElementById('kalman-panel');
|
|
1040
|
-
const outputEl = document.getElementById('output-panel');
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
priceChart = new uPlot({
|
|
1044
|
-
width: priceEl.offsetWidth, height: priceEl.offsetHeight,
|
|
1045
|
-
padding: [4, 8, 0, 4], select: { show: false }, legend: { show: false },
|
|
1046
|
-
scales: {
|
|
1047
|
-
x: { time: true },
|
|
1048
|
-
y: { auto: true, distr: 3, log: 10, range: (u, min, max) => [min * 0.9, max * 1.1] }
|
|
1049
|
-
},
|
|
1050
|
-
series: [
|
|
1051
|
-
{ label: 'Time' },
|
|
1052
|
-
{ label: 'Price', stroke: '#58a6ff', width: 1.5, scale: 'y', points: { show: false } },
|
|
1053
|
-
{ label: '${amaLabel}', stroke: '#e3b341', width: 1.5, scale: 'y', points: { show: false } },
|
|
1054
|
-
{ label: 'Seed SMA', stroke: '#8b949e', width: 1.5, dash: [4, 4], scale: 'y', points: { show: false } },
|
|
1055
|
-
],
|
|
1056
|
-
axes: [
|
|
1057
|
-
makeTimeAxis(false),
|
|
1058
|
-
{ scale: 'y', stroke: '#ffffff', grid: { stroke: '#1c2128' }, ticks: { stroke: '#30363d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
|
|
1059
|
-
values: (u, v) => v.map(x => x != null ? x.toFixed(4) : ''), }
|
|
1060
|
-
],
|
|
1061
|
-
cursor: cursorCfg,
|
|
1062
|
-
hooks: { draw: [makeSignalBgHook('y')] }
|
|
1063
|
-
}, [data.dates, data.prices, data.ama3Prices, data.amaSeedSmaLine], document.getElementById('price-chart'));
|
|
1064
|
-
|
|
1065
|
-
amaChart = new uPlot({
|
|
1066
|
-
width: amaEl.offsetWidth, height: amaEl.offsetHeight,
|
|
1067
|
-
padding: [4, 8, 0, 4], select: { show: false }, legend: { show: false },
|
|
1068
|
-
scales: { x: { time: true }, p: { auto: true } },
|
|
1069
|
-
series: [
|
|
1070
|
-
{ label: 'Time' },
|
|
1071
|
-
{ label: 'Raw‰', stroke: '#8b949e', width: 1, dash: [3, 3], scale: 'p', points: { show: false } },
|
|
1072
|
-
{ label: 'Slope‰', stroke: '#f0a000', width: 2, scale: 'p', points: { show: false } },
|
|
1073
|
-
],
|
|
1074
|
-
axes: [
|
|
1075
|
-
makeTimeAxis(false),
|
|
1076
|
-
{ scale: 'p', stroke: '#ffffff', grid: { stroke: '#1c2128', dash: [4, 4] }, ticks: { stroke: '#30363d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
|
|
1077
|
-
values: (u, v) => v.map(x => x != null ? (x >= 0 ? '+' : '') + (x * 10).toFixed(2) + '‰' : '') }
|
|
1078
|
-
],
|
|
1079
|
-
cursor: cursorCfg,
|
|
1080
|
-
hooks: { draw: [makePctFillHook(dynamicAmaSlopePct, 'p', 'rgba(46,160,67,0.20)', 'rgba(248,81,73,0.20)'), makeSignalBgHook('p')] }
|
|
1081
|
-
}, [data.dates, dynamicAmaSlopePctRaw, dynamicAmaSlopePct], document.getElementById('ama-chart'));
|
|
1082
|
-
|
|
1083
|
-
kalmanChart = new uPlot({
|
|
1084
|
-
width: kalmanEl.offsetWidth, height: kalmanEl.offsetHeight,
|
|
1085
|
-
padding: [4, 8, 0, 4], select: { show: false }, legend: { show: false },
|
|
1086
|
-
scales: { x: { time: true }, v: { auto: true } },
|
|
1087
|
-
series: [
|
|
1088
|
-
{ label: 'Time' },
|
|
1089
|
-
{ label: 'Vel%', stroke: '#d2a8ff', width: 2, scale: 'v', points: { show: false } },
|
|
1090
|
-
{ label: 'Disp%', stroke: '#79c0ff', width: 1.5, dash: [6, 3], scale: 'v', points: { show: false } },
|
|
1091
|
-
],
|
|
1092
|
-
axes: [
|
|
1093
|
-
makeTimeAxis(false),
|
|
1094
|
-
{ scale: 'v', stroke: '#ffffff', grid: { stroke: '#1c2128', dash: [4, 4] }, ticks: { stroke: '#30363d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
|
|
1095
|
-
values: (u, v) => v.map(x => x != null ? (x >= 0 ? '+' : '') + x.toFixed(1) + '%' : '') }
|
|
1096
|
-
],
|
|
1097
|
-
cursor: cursorCfg,
|
|
1098
|
-
hooks: { draw: [
|
|
1099
|
-
makePctFillHook(currentKalmanVelocityPct, 'v', 'rgba(210,168,255,0.18)', 'rgba(210,168,255,0.18)'),
|
|
1100
|
-
makeSignalBgHook('v')
|
|
1101
|
-
] }
|
|
1102
|
-
}, [data.dates, currentKalmanVelocityPct, data.kalmanDisplacementPct], document.getElementById('kalman-chart'));
|
|
1103
|
-
|
|
1104
|
-
outputChart = new uPlot({
|
|
1105
|
-
width: outputEl.offsetWidth, height: outputEl.offsetHeight,
|
|
1106
|
-
padding: [20, 8, 0, 4], select: { show: false }, legend: { show: false },
|
|
1107
|
-
scales: { x: { time: true }, ow: { auto: true, range: (u, min, max) => {
|
|
1108
|
-
const m = 0.5;
|
|
1109
|
-
const pad = (max - min) * 0.1 || 0.02;
|
|
1110
|
-
return [Math.min(min - pad, -m), Math.max(max + pad, m)];
|
|
1111
|
-
}}},
|
|
1112
|
-
series: [
|
|
1113
|
-
{ label: 'Time' },
|
|
1114
|
-
{ label: 'RawOff', stroke: 'transparent', width: 0, scale: 'ow', points: { show: false } },
|
|
1115
|
-
{ label: 'EchoOff', stroke: 'transparent', width: 0, scale: 'ow', points: { show: false } }
|
|
1116
|
-
],
|
|
1117
|
-
axes: [
|
|
1118
|
-
makeTimeAxis(true),
|
|
1119
|
-
{ scale: 'ow', stroke: '#ffffff', grid: { stroke: '#1c2128', dash: [4, 4] }, ticks: { stroke: '#30363d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
|
|
1120
|
-
values: (u, v) => v.map(x => x != null ? (x >= 0 ? '+' : '') + x.toFixed(2) : ''),
|
|
1121
|
-
splits: () => { const m = Math.max(0.5, currentOutputAxisMax || 0.5); return [-m, -m/2, 0, m/2, m]; } }
|
|
1122
|
-
],
|
|
1123
|
-
cursor: cursorCfg,
|
|
1124
|
-
hooks: { draw: [
|
|
1125
|
-
makePctFillHook(combinedOff, 'ow', 'rgba(108,117,125,0.08)', 'rgba(108,117,125,0.06)', null),
|
|
1126
|
-
makePctFillHook(echoCombinedOff, 'ow', 'rgba(46,160,67,0.18)', 'rgba(248,81,73,0.18)', null),
|
|
1127
|
-
...makeClampPairHooks('ow', OUTPUT_CLAMP)
|
|
1128
|
-
] }
|
|
1129
|
-
}, [data.dates, combinedOff, echoCombinedOff], document.getElementById('output-chart'));
|
|
1130
|
-
|
|
1131
|
-
charts = [priceChart, amaChart, kalmanChart, outputChart];
|
|
1132
|
-
${bindHoverStateFn()}
|
|
1133
|
-
${wireChartEvents('charts', 'updateLegend', 'lastLiveIdx')}
|
|
1134
|
-
|
|
1135
|
-
function onSliderChange() {
|
|
1136
|
-
recalcInputs();
|
|
1137
|
-
recalcWeights();
|
|
1138
|
-
refreshChartsPreservingZoom();
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
document.getElementById('alpha-slider').addEventListener('input', (e) => {
|
|
1142
|
-
currentAlpha = parseInt(e.target.value, 10) / 100;
|
|
1143
|
-
document.getElementById('alpha-value').textContent = currentAlpha.toFixed(2);
|
|
1144
|
-
recalcWeights();
|
|
1145
|
-
refreshChartsPreservingZoom();
|
|
1146
|
-
});
|
|
1147
|
-
|
|
1148
|
-
document.getElementById('dw-slider').addEventListener('input', (e) => {
|
|
1149
|
-
currentDw = parseInt(e.target.value, 10) / 100;
|
|
1150
|
-
document.getElementById('dw-value').textContent = currentDw.toFixed(2);
|
|
1151
|
-
onSliderChange();
|
|
1152
|
-
});
|
|
1153
|
-
|
|
1154
|
-
document.getElementById('ama-ms-slider').addEventListener('input', (e) => {
|
|
1155
|
-
currentAmaMaxSlopePct = amaMsSliderToVal(parseInt(e.target.value, 10));
|
|
1156
|
-
document.getElementById('ama-ms-value').textContent = currentAmaMaxSlopePct.toFixed(4);
|
|
1157
|
-
onSliderChange();
|
|
1158
|
-
});
|
|
1159
|
-
|
|
1160
|
-
document.getElementById('kal-ms-slider').addEventListener('input', (e) => {
|
|
1161
|
-
currentKalmanMaxSlopePct = kalMsSliderToVal(parseInt(e.target.value, 10));
|
|
1162
|
-
document.getElementById('kal-ms-value').textContent = currentKalmanMaxSlopePct.toFixed(2);
|
|
1163
|
-
onSliderChange();
|
|
1164
|
-
});
|
|
1165
|
-
|
|
1166
|
-
document.getElementById('gain-slider').addEventListener('input', (e) => {
|
|
1167
|
-
currentGain = gainSliderToVal(parseInt(e.target.value, 10));
|
|
1168
|
-
document.getElementById('gain-value').textContent = currentGain.toFixed(3);
|
|
1169
|
-
onSliderChange();
|
|
1170
|
-
});
|
|
1171
|
-
|
|
1172
|
-
document.getElementById('th-slider').addEventListener('input', (e) => {
|
|
1173
|
-
currentMinOutputThreshold = Math.min(Math.max(parseInt(e.target.value, 10) / 100, SR.minOutputThreshold[0]), SR.minOutputThreshold[1]);
|
|
1174
|
-
document.getElementById('th-value').textContent = currentMinOutputThreshold.toFixed(2);
|
|
1175
|
-
recalcWeights();
|
|
1176
|
-
refreshChartsPreservingZoom();
|
|
1177
|
-
});
|
|
1178
|
-
|
|
1179
|
-
document.getElementById('kf-slider').addEventListener('input', (e) => {
|
|
1180
|
-
currentKalmanSmoothPct = parseInt(e.target.value, 10);
|
|
1181
|
-
document.getElementById('kf-value').textContent = currentKalmanSmoothPct + '%';
|
|
1182
|
-
onSliderChange();
|
|
1183
|
-
});
|
|
1184
|
-
|
|
1185
|
-
document.getElementById('kfd-slider').addEventListener('input', (e) => {
|
|
1186
|
-
currentKalmanDispScaleMult = parseInt(e.target.value, 10) / 100;
|
|
1187
|
-
document.getElementById('kfd-value').textContent = currentKalmanDispScaleMult.toFixed(2) + 'x';
|
|
1188
|
-
onSliderChange();
|
|
1189
|
-
});
|
|
1190
|
-
|
|
1191
|
-
document.getElementById('dsp-slider').addEventListener('input', (e) => {
|
|
1192
|
-
currentDispScaleMinPct = parseInt(e.target.value, 10) / 100;
|
|
1193
|
-
document.getElementById('dsp-value').textContent = currentDispScaleMinPct.toFixed(2) + 'x';
|
|
1194
|
-
onSliderChange();
|
|
1195
|
-
});
|
|
1196
|
-
|
|
1197
|
-
document.getElementById('kdt-slider').addEventListener('input', (e) => {
|
|
1198
|
-
currentKalmanDispThresholdMult = parseInt(e.target.value, 10) / 100;
|
|
1199
|
-
document.getElementById('kdt-value').textContent = currentKalmanDispThresholdMult.toFixed(2) + 'x';
|
|
1200
|
-
onSliderChange();
|
|
1201
|
-
});
|
|
1202
|
-
|
|
1203
|
-
document.getElementById('kfs-slider').addEventListener('input', (e) => {
|
|
1204
|
-
currentKalmanSmoothSpanPct = parseInt(e.target.value, 10);
|
|
1205
|
-
document.getElementById('kfs-value').textContent = currentKalmanSmoothSpanPct + '%';
|
|
1206
|
-
onSliderChange();
|
|
1207
|
-
});
|
|
1208
|
-
|
|
1209
|
-
document.getElementById('cf-slider').addEventListener('input', (e) => {
|
|
1210
|
-
currentSignalConfirmBars = parseInt(e.target.value, 10);
|
|
1211
|
-
document.getElementById('cf-value').textContent = currentSignalConfirmBars;
|
|
1212
|
-
onSliderChange();
|
|
1213
|
-
});
|
|
1214
|
-
|
|
1215
|
-
document.getElementById('clip-slider').addEventListener('input', (e) => {
|
|
1216
|
-
currentClipPct = parseInt(e.target.value, 10);
|
|
1217
|
-
if (currentClipPct === 0) {
|
|
1218
|
-
currentAmaClipThreshold = data.amaPercentiles[data.amaPercentiles.length - 1];
|
|
1219
|
-
currentKalClipThreshold = Infinity;
|
|
1220
|
-
} else {
|
|
1221
|
-
// AMA clip threshold for clipPct>0 comes from the canonical
|
|
1222
|
-
// computeAmaSlopeClipThreshold inside recalcInputs() —
|
|
1223
|
-
// no percentile-table store needed here.
|
|
1224
|
-
recalcKalmanClipThreshold();
|
|
1225
|
-
}
|
|
1226
|
-
document.getElementById('clip-value').textContent = currentClipPct + '%';
|
|
1227
|
-
onSliderChange();
|
|
1228
|
-
});
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
document.getElementById('nz-slider').addEventListener('input', (e) => {
|
|
1232
|
-
currentNz = parseInt(e.target.value, 10) / 100;
|
|
1233
|
-
document.getElementById('nz-value').textContent = currentNz.toFixed(2);
|
|
1234
|
-
onSliderChange();
|
|
1235
|
-
});
|
|
1236
|
-
|
|
1237
|
-
document.getElementById('lb-slider').addEventListener('input', (e) => {
|
|
1238
|
-
currentLookbackBars = lbSliderToVal(parseInt(e.target.value, 10));
|
|
1239
|
-
document.getElementById('lb-value').textContent = currentLookbackBars;
|
|
1240
|
-
onSliderChange();
|
|
1241
|
-
});
|
|
1242
|
-
|
|
1243
|
-
document.getElementById('ema-slider').addEventListener('input', (e) => {
|
|
1244
|
-
currentAmaEmaSpan = parseInt(e.target.value, 10);
|
|
1245
|
-
document.getElementById('ema-value').textContent = currentAmaEmaSpan;
|
|
1246
|
-
onSliderChange();
|
|
1247
|
-
});
|
|
1248
|
-
|
|
1249
|
-
document.getElementById('regime-slider').addEventListener('input', (e) => {
|
|
1250
|
-
currentRegimeSensitivity = parseInt(e.target.value, 10) / 100;
|
|
1251
|
-
document.getElementById('regime-value').textContent = currentRegimeSensitivity.toFixed(2);
|
|
1252
|
-
recalcWeights();
|
|
1253
|
-
refreshChartsPreservingZoom();
|
|
1254
|
-
});
|
|
1255
|
-
|
|
1256
|
-
function applyParams(p, btn) {
|
|
1257
|
-
if (typeof p !== 'object' || p === null) throw new Error('not an object');
|
|
1258
|
-
if (p.alpha != null) {
|
|
1259
|
-
currentAlpha = Math.max(SR.alpha[0], Math.min(SR.alpha[1], p.alpha));
|
|
1260
|
-
document.getElementById('alpha-slider').value = Math.round(currentAlpha * 100);
|
|
1261
|
-
document.getElementById('alpha-value').textContent = currentAlpha.toFixed(2);
|
|
1262
|
-
}
|
|
1263
|
-
if (p.dispWeight != null) {
|
|
1264
|
-
currentDw = Math.max(SR.dispWeight[0], Math.min(SR.dispWeight[1], p.dispWeight));
|
|
1265
|
-
document.getElementById('dw-slider').value = Math.round(currentDw * 100);
|
|
1266
|
-
document.getElementById('dw-value').textContent = currentDw.toFixed(2);
|
|
1267
|
-
}
|
|
1268
|
-
if (p.amaMaxSlopePct != null) {
|
|
1269
|
-
currentAmaMaxSlopePct = Math.max(SR.amaMaxSlopePct[0], Math.min(SR.amaMaxSlopePct[1], p.amaMaxSlopePct));
|
|
1270
|
-
document.getElementById('ama-ms-slider').value = Math.round((Math.log(currentAmaMaxSlopePct) - AMA_MS_LOG_MIN) / (AMA_MS_LOG_MAX - AMA_MS_LOG_MIN) * 1000);
|
|
1271
|
-
document.getElementById('ama-ms-value').textContent = currentAmaMaxSlopePct.toFixed(4);
|
|
1272
|
-
}
|
|
1273
|
-
if (p.kalmanMaxSlopePct != null) {
|
|
1274
|
-
currentKalmanMaxSlopePct = Math.max(SR.kalmanMaxSlopePct[0], Math.min(SR.kalmanMaxSlopePct[1], p.kalmanMaxSlopePct));
|
|
1275
|
-
document.getElementById('kal-ms-slider').value = Math.round((Math.log(currentKalmanMaxSlopePct) - KAL_MS_LOG_MIN) / (KAL_MS_LOG_MAX - KAL_MS_LOG_MIN) * 1000);
|
|
1276
|
-
document.getElementById('kal-ms-value').textContent = currentKalmanMaxSlopePct.toFixed(2);
|
|
1277
|
-
}
|
|
1278
|
-
if (p.gain != null) {
|
|
1279
|
-
currentGain = Math.max(SR.gain[0], Math.min(SR.gain[1], p.gain));
|
|
1280
|
-
document.getElementById('gain-slider').value = gainValToSlider(currentGain);
|
|
1281
|
-
document.getElementById('gain-value').textContent = currentGain.toFixed(3);
|
|
1282
|
-
}
|
|
1283
|
-
if (p.minOutputThreshold != null) {
|
|
1284
|
-
currentMinOutputThreshold = Math.max(SR.minOutputThreshold[0], Math.min(SR.minOutputThreshold[1], p.minOutputThreshold));
|
|
1285
|
-
document.getElementById('th-slider').value = Math.round(currentMinOutputThreshold * 100);
|
|
1286
|
-
document.getElementById('th-value').textContent = currentMinOutputThreshold.toFixed(2);
|
|
1287
|
-
}
|
|
1288
|
-
if (p.kalmanSmoothPct != null) {
|
|
1289
|
-
currentKalmanSmoothPct = Math.max(SR.kalmanSmoothPct[0], Math.min(SR.kalmanSmoothPct[1], Math.round(p.kalmanSmoothPct)));
|
|
1290
|
-
document.getElementById('kf-slider').value = currentKalmanSmoothPct;
|
|
1291
|
-
document.getElementById('kf-value').textContent = currentKalmanSmoothPct + '%';
|
|
1292
|
-
}
|
|
1293
|
-
if (p.kalmanDispScaleMult != null) {
|
|
1294
|
-
currentKalmanDispScaleMult = Math.max(SR.kalmanDispScaleMult[0], Math.min(SR.kalmanDispScaleMult[1], p.kalmanDispScaleMult));
|
|
1295
|
-
document.getElementById('kfd-slider').value = Math.round(currentKalmanDispScaleMult * 100);
|
|
1296
|
-
document.getElementById('kfd-value').textContent = currentKalmanDispScaleMult.toFixed(2) + 'x';
|
|
1297
|
-
}
|
|
1298
|
-
if (p.dispScaleMinPct != null) {
|
|
1299
|
-
currentDispScaleMinPct = Math.max(SR.dispScaleMinPct[0], Math.min(SR.dispScaleMinPct[1], p.dispScaleMinPct));
|
|
1300
|
-
document.getElementById('dsp-slider').value = Math.round(currentDispScaleMinPct * 100);
|
|
1301
|
-
document.getElementById('dsp-value').textContent = currentDispScaleMinPct.toFixed(2) + 'x';
|
|
1302
|
-
}
|
|
1303
|
-
if (p.kalmanDispThresholdMult != null) {
|
|
1304
|
-
currentKalmanDispThresholdMult = Math.max(SR.kalmanDispThresholdMult[0], Math.min(SR.kalmanDispThresholdMult[1], p.kalmanDispThresholdMult));
|
|
1305
|
-
document.getElementById('kdt-slider').value = Math.round(currentKalmanDispThresholdMult * 100);
|
|
1306
|
-
document.getElementById('kdt-value').textContent = currentKalmanDispThresholdMult.toFixed(2) + 'x';
|
|
1307
|
-
}
|
|
1308
|
-
if (p.kalmanSmoothSpanPct != null) {
|
|
1309
|
-
currentKalmanSmoothSpanPct = Math.max(SR.kalmanSmoothSpanPct[0], Math.min(SR.kalmanSmoothSpanPct[1], Math.round(p.kalmanSmoothSpanPct)));
|
|
1310
|
-
document.getElementById('kfs-slider').value = currentKalmanSmoothSpanPct;
|
|
1311
|
-
document.getElementById('kfs-value').textContent = currentKalmanSmoothSpanPct + '%';
|
|
1312
|
-
}
|
|
1313
|
-
if (p.signalConfirmBars != null) {
|
|
1314
|
-
currentSignalConfirmBars = Math.max(SR.signalConfirmBars[0], Math.min(SR.signalConfirmBars[1], Math.round(p.signalConfirmBars)));
|
|
1315
|
-
document.getElementById('cf-slider').value = currentSignalConfirmBars;
|
|
1316
|
-
document.getElementById('cf-value').textContent = currentSignalConfirmBars;
|
|
1317
|
-
}
|
|
1318
|
-
if (p.clipPct != null) {
|
|
1319
|
-
currentClipPct = Math.max(SR.clipPct[0], Math.min(SR.clipPct[1], Math.round(p.clipPct)));
|
|
1320
|
-
document.getElementById('clip-slider').value = currentClipPct;
|
|
1321
|
-
document.getElementById('clip-value').textContent = currentClipPct + '%';
|
|
1322
|
-
if (currentClipPct === 0) {
|
|
1323
|
-
currentAmaClipThreshold = data.amaPercentiles[data.amaPercentiles.length - 1];
|
|
1324
|
-
currentKalClipThreshold = Infinity;
|
|
1325
|
-
} else {
|
|
1326
|
-
recalcKalmanClipThreshold();
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
if (p.neutralZonePct != null) {
|
|
1330
|
-
currentNz = Math.max(SR.neutralZonePct[0], Math.min(SR.neutralZonePct[1], p.neutralZonePct));
|
|
1331
|
-
document.getElementById('nz-slider').value = Math.round(currentNz * 100);
|
|
1332
|
-
document.getElementById('nz-value').textContent = currentNz.toFixed(2);
|
|
1333
|
-
}
|
|
1334
|
-
if (p.regimeSensitivity != null) {
|
|
1335
|
-
currentRegimeSensitivity = Math.max(SR.regimeSensitivity[0], Math.min(SR.regimeSensitivity[1], p.regimeSensitivity));
|
|
1336
|
-
document.getElementById('regime-slider').value = Math.round(currentRegimeSensitivity * 100);
|
|
1337
|
-
document.getElementById('regime-value').textContent = currentRegimeSensitivity.toFixed(2);
|
|
1338
|
-
}
|
|
1339
|
-
if (p.lookbackBars != null) {
|
|
1340
|
-
currentLookbackBars = Math.max(SR.lookbackBars[0], Math.min(SR.lookbackBars[1], Math.round(p.lookbackBars)));
|
|
1341
|
-
document.getElementById('lb-slider').value = lbValToSlider(currentLookbackBars);
|
|
1342
|
-
document.getElementById('lb-value').textContent = currentLookbackBars;
|
|
1343
|
-
}
|
|
1344
|
-
if (p.amaEmaSpan != null) {
|
|
1345
|
-
currentAmaEmaSpan = Math.max(SR.amaEmaSpan[0], Math.min(SR.amaEmaSpan[1], Math.round(p.amaEmaSpan)));
|
|
1346
|
-
document.getElementById('ema-slider').value = currentAmaEmaSpan;
|
|
1347
|
-
document.getElementById('ema-value').textContent = currentAmaEmaSpan;
|
|
1348
|
-
}
|
|
1349
|
-
recalcInputs();
|
|
1350
|
-
recalcWeights();
|
|
1351
|
-
refreshChartsPreservingZoom();
|
|
1352
|
-
if (btn) { btn.textContent = 'pasted!'; btn.classList.add('pasted'); setTimeout(() => { btn.textContent = 'paste'; btn.classList.remove('pasted'); }, 1500); }
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
let _confirmPending = null;
|
|
1356
|
-
function showConfirm(p, btn) {
|
|
1357
|
-
_confirmPending = { p, btn };
|
|
1358
|
-
const labels = {
|
|
1359
|
-
alpha: 'alpha',
|
|
1360
|
-
amaMaxSlopePct: 'amaS%',
|
|
1361
|
-
kalmanMaxSlopePct: 'kalS%',
|
|
1362
|
-
minOutputThreshold: 'th%',
|
|
1363
|
-
gain: 'gain',
|
|
1364
|
-
kalmanSmoothPct: 'kf',
|
|
1365
|
-
kalmanDispScaleMult: 'kfd',
|
|
1366
|
-
dispScaleMinPct: 'dsp',
|
|
1367
|
-
kalmanDispThresholdMult: 'kdt',
|
|
1368
|
-
kalmanSmoothSpanPct: 'kfs',
|
|
1369
|
-
signalConfirmBars: 'cf',
|
|
1370
|
-
clipPct: 'clip%',
|
|
1371
|
-
neutralZonePct: 'nz%',
|
|
1372
|
-
regimeSensitivity: 'regime',
|
|
1373
|
-
dispWeight: 'dw',
|
|
1374
|
-
lookbackBars: 'lb',
|
|
1375
|
-
amaEmaSpan: 'ema',
|
|
1376
|
-
};
|
|
1377
|
-
document.getElementById('paste-confirm-vals').innerHTML = Object.entries(labels)
|
|
1378
|
-
.filter(([k]) => p[k] != null)
|
|
1379
|
-
.map(([k, label]) => label + ': <span>' + p[k] + '</span>')
|
|
1380
|
-
.join('<br>');
|
|
1381
|
-
const popup = document.getElementById('paste-confirm');
|
|
1382
|
-
popup.style.display = 'block';
|
|
1383
|
-
const r = btn.getBoundingClientRect();
|
|
1384
|
-
const pw = popup.offsetWidth, ph = popup.offsetHeight;
|
|
1385
|
-
let top = r.top - ph - 6;
|
|
1386
|
-
let left = r.right - pw;
|
|
1387
|
-
if (top < 4) top = r.bottom + 6;
|
|
1388
|
-
if (left < 4) left = 4;
|
|
1389
|
-
popup.style.top = top + 'px';
|
|
1390
|
-
popup.style.left = left + 'px';
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
document.getElementById('paste-confirm-apply').addEventListener('click', () => {
|
|
1394
|
-
document.getElementById('paste-confirm').style.display = 'none';
|
|
1395
|
-
if (_confirmPending) { applyParams(_confirmPending.p, _confirmPending.btn); _confirmPending = null; }
|
|
1396
|
-
});
|
|
1397
|
-
document.getElementById('paste-confirm-cancel').addEventListener('click', () => {
|
|
1398
|
-
document.getElementById('paste-confirm').style.display = 'none';
|
|
1399
|
-
_confirmPending = null;
|
|
1400
|
-
});
|
|
1401
|
-
document.addEventListener('keydown', (e) => {
|
|
1402
|
-
if (e.key === 'Escape' && document.getElementById('paste-confirm').style.display !== 'none') {
|
|
1403
|
-
document.getElementById('paste-confirm').style.display = 'none';
|
|
1404
|
-
_confirmPending = null;
|
|
1405
|
-
}
|
|
1406
|
-
});
|
|
1407
|
-
|
|
1408
|
-
const LS_KEY = 'dw_research_params';
|
|
1409
|
-
|
|
1410
|
-
document.getElementById('copy-params-btn').addEventListener('click', () => {
|
|
1411
|
-
const btn = document.getElementById('copy-params-btn');
|
|
1412
|
-
const params = {
|
|
1413
|
-
alpha: +currentAlpha.toFixed(2),
|
|
1414
|
-
amaMaxSlopePct: +currentAmaMaxSlopePct.toFixed(4),
|
|
1415
|
-
kalmanMaxSlopePct: +currentKalmanMaxSlopePct.toFixed(2),
|
|
1416
|
-
minOutputThreshold: +currentMinOutputThreshold.toFixed(2),
|
|
1417
|
-
gain: +currentGain.toFixed(3),
|
|
1418
|
-
kalmanSmoothPct: currentKalmanSmoothPct,
|
|
1419
|
-
kalmanDispScaleMult: +currentKalmanDispScaleMult.toFixed(2),
|
|
1420
|
-
dispScaleMinPct: +currentDispScaleMinPct.toFixed(2),
|
|
1421
|
-
kalmanDispThresholdMult: +currentKalmanDispThresholdMult.toFixed(2),
|
|
1422
|
-
kalmanSmoothSpanPct: currentKalmanSmoothSpanPct,
|
|
1423
|
-
signalConfirmBars: currentSignalConfirmBars,
|
|
1424
|
-
clipPct: currentClipPct,
|
|
1425
|
-
neutralZonePct: +currentNz.toFixed(3),
|
|
1426
|
-
regimeSensitivity: +currentRegimeSensitivity.toFixed(2),
|
|
1427
|
-
dispWeight: +currentDw.toFixed(2),
|
|
1428
|
-
lookbackBars: currentLookbackBars,
|
|
1429
|
-
amaEmaSpan: currentAmaEmaSpan,
|
|
1430
|
-
};
|
|
1431
|
-
const json = JSON.stringify(params, null, 2);
|
|
1432
|
-
localStorage.setItem(LS_KEY, json);
|
|
1433
|
-
navigator.clipboard.writeText(json).catch(() => {});
|
|
1434
|
-
btn.textContent = 'copied!';
|
|
1435
|
-
btn.classList.add('copied');
|
|
1436
|
-
setTimeout(() => { btn.textContent = 'copy'; btn.classList.remove('copied'); }, 1500);
|
|
1437
|
-
});
|
|
1438
|
-
|
|
1439
|
-
document.getElementById('paste-params-btn').addEventListener('click', () => {
|
|
1440
|
-
const btn = document.getElementById('paste-params-btn');
|
|
1441
|
-
const tryParse = (text) => {
|
|
1442
|
-
try { showConfirm(JSON.parse(text), btn); }
|
|
1443
|
-
catch { btn.textContent = 'error'; btn.classList.add('error'); setTimeout(() => { btn.textContent = 'paste'; btn.classList.remove('error'); }, 1500); }
|
|
1444
|
-
};
|
|
1445
|
-
// Use localStorage first (same-tab copy/paste), fallback to Ctrl+V
|
|
1446
|
-
const stored = localStorage.getItem(LS_KEY);
|
|
1447
|
-
if (stored) {
|
|
1448
|
-
try { showConfirm(JSON.parse(stored), btn); return; } catch {}
|
|
1449
|
-
}
|
|
1450
|
-
// No localStorage data - use Ctrl+V method
|
|
1451
|
-
btn.textContent = 'Ctrl+V…';
|
|
1452
|
-
btn.classList.add('pasted');
|
|
1453
|
-
const ta = document.createElement('textarea');
|
|
1454
|
-
ta.style.cssText = 'position:fixed;opacity:0;top:0;left:0;width:1px;height:1px;font-size:16px;';
|
|
1455
|
-
document.body.appendChild(ta);
|
|
1456
|
-
ta.focus();
|
|
1457
|
-
const cleanup = () => { document.body.removeChild(ta); btn.textContent = 'paste'; btn.classList.remove('pasted'); };
|
|
1458
|
-
ta.addEventListener('paste', (e) => {
|
|
1459
|
-
const text = (e.clipboardData || window.clipboardData).getData('text');
|
|
1460
|
-
cleanup();
|
|
1461
|
-
tryParse(text);
|
|
1462
|
-
}, { once: true });
|
|
1463
|
-
ta.addEventListener('keydown', (e) => { if (e.key === 'Escape') cleanup(); });
|
|
1464
|
-
setTimeout(cleanup, 10000);
|
|
1465
|
-
});
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
${sizeChartsFn([['priceChart', 'price-panel'], ['amaChart', 'ama-panel'], ['kalmanChart', 'kalman-panel'], ['outputChart', 'output-panel']])}
|
|
1469
|
-
|
|
1470
|
-
window.addEventListener('resize', sizeCharts);
|
|
1471
|
-
${zoomResetScript()}
|
|
1472
|
-
|
|
1473
|
-
init();
|
|
1474
|
-
requestAnimationFrame(() => { sizeCharts(); updateLegend(lastLiveIdx); });
|
|
1475
|
-
</script>
|
|
1476
|
-
</body>
|
|
1477
|
-
</html>`;
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
export { generateHTML }
|
|
1481
|
-
|