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
|
@@ -10,8 +10,9 @@ import { getStorage } from '../../modules/storage/index.js';
|
|
|
10
10
|
const { readJSON } = getStorage();
|
|
11
11
|
import { getErrorMessage } from '../../modules/utils/errors.js';
|
|
12
12
|
import { parseRelativeMultiplier } from '../../modules/order/utils/math.js';
|
|
13
|
-
import { computeAverageAmaSlopePct, computeAmaSlopeClipThreshold } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
|
|
13
|
+
import { computeAverageAmaSlopePct, computeAmaSlopeClipThreshold, createAmaSlopeClipTracker, percentileFromSorted } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
|
|
14
14
|
import { resolveBaseBounds, computeAsymmetricBoundsMetrics, applyAsymmetricBounds, applyNarrowingSideGuard, } from '../../market_adapter/core/asymmetric_bounds.js';
|
|
15
|
+
import { simulateGridResetSeries, gridSimSlopeSignal, gridSimPositiveNumber, gridSimNonNegativeInt, GRID_RESET_NONE, GRID_RESET_BOOTSTRAP, GRID_RESET_PRICE, GRID_RESET_SLOPE, } from './grid_reset_sim.js';
|
|
15
16
|
function inferBaseIntervalSeconds(candles, fallback = 3600) {
|
|
16
17
|
if (!Array.isArray(candles) || candles.length < 2)
|
|
17
18
|
return fallback;
|
|
@@ -172,8 +173,16 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
172
173
|
maxAsymmetryFactor: Number.isFinite(Number(data.grid.maxAsymmetryFactor)) && Number(data.grid.maxAsymmetryFactor) > 0
|
|
173
174
|
? Number(data.grid.maxAsymmetryFactor)
|
|
174
175
|
: rangeSlope.maxAsymmetryFactor,
|
|
176
|
+
minScaleSlots: Number.isFinite(Number(data.grid.minScaleSlots)) && Number(data.grid.minScaleSlots) > 0
|
|
177
|
+
? Number(data.grid.minScaleSlots)
|
|
178
|
+
: rangeSlope.minScaleSlots,
|
|
175
179
|
} : null,
|
|
176
180
|
rangeSlope,
|
|
181
|
+
// Grid-reset simulation: thresholds already resolved through the live
|
|
182
|
+
// adapter's config chain (analysis/tradingview/grid_reset_config.ts).
|
|
183
|
+
// Only present for AMA-grid bots, so pool/pair charts stay untouched.
|
|
184
|
+
gridSim: (data.gridSim && data.gridSim.enabled === true) ? data.gridSim : null,
|
|
185
|
+
gridSimEnabled: data.gridSimEnabled !== false,
|
|
177
186
|
};
|
|
178
187
|
const assetLabelA = meta.assetA?.symbol || meta.assetA?.id || 'Asset A';
|
|
179
188
|
const assetLabelB = meta.assetB?.symbol || meta.assetB?.id || 'Asset B';
|
|
@@ -214,6 +223,8 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
214
223
|
updateMarkerTsSec: Number(data.updateMarkerTsSec) > 0 ? Number(data.updateMarkerTsSec) : null,
|
|
215
224
|
updateMarkerNewBars: Number(data.updateMarkerNewBars) || null,
|
|
216
225
|
rangeSlope,
|
|
226
|
+
gridSim: defaults.gridSim,
|
|
227
|
+
gridSimEnabled: defaults.gridSimEnabled,
|
|
217
228
|
defaultPairMode,
|
|
218
229
|
assetLabelA,
|
|
219
230
|
assetLabelB,
|
|
@@ -574,6 +585,9 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
574
585
|
<span id="range-span-val" style="font-size:11px;color:#8b949e;width:40px;display:inline-block;text-align:right">${defaults.rangeSpan.toFixed(2)}x</span>
|
|
575
586
|
</span>
|
|
576
587
|
</div>
|
|
588
|
+
${defaults.gridSim ? `<div class="indicator" title="Simulated grid resets: accepted grid center (step line) and range, recentered when the AMA moves past the AMA-\u0394 threshold or the AMA slope past AMA-Slope \u0394">
|
|
589
|
+
<label><input type="checkbox" id="grid-sim-toggle"${defaults.gridSimEnabled ? ' checked' : ''}> Resets</label>
|
|
590
|
+
</div>` : ''}
|
|
577
591
|
<div class="indicator">
|
|
578
592
|
<label title="Init Offset"><input type="checkbox" id="ama-init-offset-toggle"> Offset</label>
|
|
579
593
|
<input type="range" id="ama-init-offset" min="-50" max="50" value="0" step="1" style="width:90px;vertical-align:middle" disabled>
|
|
@@ -596,6 +610,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
596
610
|
<span class="legend-item"><span class="legend-dot" style="background:#93c5fd"></span><span class="legend-label">VWMA</span> <span class="legend-value" id="legend-vwap">-</span></span>
|
|
597
611
|
<span class="legend-item"><span class="legend-dot" style="background:#22c55e"></span><span class="legend-label">AMA Init</span> <span class="legend-value" id="legend-sma-init">-</span></span>
|
|
598
612
|
<span class="legend-item"><span class="legend-dot" style="background:#2dd4bf"></span><span class="legend-label">AMA</span> <span class="legend-value" id="legend-ama">-</span></span>
|
|
613
|
+
${defaults.gridSim ? `<span class="legend-item"><span class="legend-dot" style="background:#c084fc"></span><span class="legend-label" title="Grid center the bot would be running right now (step line)">Grid</span> <span class="legend-value" id="legend-grid-center">-</span><span class="legend-value" id="legend-grid-reason"></span></span>` : ''}
|
|
599
614
|
</div>
|
|
600
615
|
</div>
|
|
601
616
|
<div id="price-chart" title="Wheel: zoom time (out = empty space around data) · Shift+wheel: zoom price · Drag: pan time + price (sets manual price scale) · Wheel/drag on price axis: zoom price · Drag on time axis: zoom time · Double-click price axis: autofit"></div>
|
|
@@ -645,6 +660,11 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
645
660
|
? Math.min(2, Math.max(1.2, Number(state.rangeSpan)))
|
|
646
661
|
: (Number.isFinite(Number(payload.rangeSpan)) && Number(payload.rangeSpan) > 0 ? Math.min(2, Math.max(1.2, Number(payload.rangeSpan))) : 1.55);
|
|
647
662
|
let currentOrdersVisible = state.ordersVisible ?? true;
|
|
663
|
+
// Grid-reset simulation (AMA-price Δ / AMA-slope Δ). Static per
|
|
664
|
+
// generation: payload.gridSim is null for non-AMA charts, which removes
|
|
665
|
+
// the toggle, the series and the panel together.
|
|
666
|
+
const gridSimCfg = payload.gridSim || null;
|
|
667
|
+
let currentGridSimEnabled = gridSimCfg ? (state.gridSimEnabled ?? !!payload.gridSimEnabled) : false;
|
|
648
668
|
let currentVolumeVisible = state.volumeVisible ?? true;
|
|
649
669
|
let currentVolumeMode = state.volumeMode === 'quote' ? 'quote' : 'base';
|
|
650
670
|
// Static per generation: the overlay (levels, reserve/ceiling lines,
|
|
@@ -678,6 +698,15 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
678
698
|
let currentAmaOff = [];
|
|
679
699
|
let currentRangeUpper = [];
|
|
680
700
|
let currentRangeLower = [];
|
|
701
|
+
let currentGridCenter = [];
|
|
702
|
+
let currentSimUpper = [];
|
|
703
|
+
let currentSimLower = [];
|
|
704
|
+
let currentSimReason = [];
|
|
705
|
+
let currentSimStats = null;
|
|
706
|
+
// Event indices come from the 1h replay; these are the matching indices
|
|
707
|
+
// in the DISPLAYED (aggregated) series, so the panel can label them.
|
|
708
|
+
let currentSimStartIdx = null;
|
|
709
|
+
let currentSimLastIdx = null;
|
|
681
710
|
let priceChart = null;
|
|
682
711
|
let volumeChart = null;
|
|
683
712
|
let lastRenderedPriceScale = null;
|
|
@@ -1010,6 +1039,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1010
1039
|
rangeWidthPct: currentRangeWidthPct,
|
|
1011
1040
|
rangeSpan: currentRangeSpan,
|
|
1012
1041
|
ordersVisible: currentOrdersVisible,
|
|
1042
|
+
gridSimEnabled: currentGridSimEnabled,
|
|
1013
1043
|
volumeVisible: currentVolumeVisible,
|
|
1014
1044
|
volumeMode: currentVolumeMode,
|
|
1015
1045
|
amaInitOffset: currentAmaInitOffset,
|
|
@@ -1447,7 +1477,115 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1447
1477
|
// red [AMA, upper], green [lower, AMA].
|
|
1448
1478
|
// Never reads candles, pair-display mapping, or axis/zoom state —
|
|
1449
1479
|
// inversion and timeframe sampling apply to the AMA first.
|
|
1450
|
-
${embedFunctionSources([computeAverageAmaSlopePct, computeAmaSlopeClipThreshold, resolveBaseBounds, computeAsymmetricBoundsMetrics, applyAsymmetricBounds, applyNarrowingSideGuard, parseRelativeMultiplier])}
|
|
1480
|
+
${embedFunctionSources([computeAverageAmaSlopePct, computeAmaSlopeClipThreshold, resolveBaseBounds, computeAsymmetricBoundsMetrics, applyAsymmetricBounds, applyNarrowingSideGuard, parseRelativeMultiplier, percentileFromSorted, createAmaSlopeClipTracker, gridSimPositiveNumber, gridSimNonNegativeInt, gridSimSlopeSignal, simulateGridResetSeries])}
|
|
1481
|
+
// ── Grid-reset simulation ──
|
|
1482
|
+
// Replays the two market-adapter recentering triggers (docs/GRID_RECALCULATION.md
|
|
1483
|
+
// §3 AMA Δ / §4 AMA-Slope Δ) over the 1h AMA series: the accepted grid center
|
|
1484
|
+
// ratchets only on a trigger, and the accepted slope baseline re-seeds on every
|
|
1485
|
+
// reset (the advanceTriggeredBotState chain). Thresholds arrive pre-resolved
|
|
1486
|
+
// through the live config chain in payload.gridSim. The replay itself is the
|
|
1487
|
+
// canonical simulateGridResetSeries() embedded above — not a hand copy.
|
|
1488
|
+
const GRID_RESET_NONE = ${GRID_RESET_NONE};
|
|
1489
|
+
const GRID_RESET_BOOTSTRAP = ${GRID_RESET_BOOTSTRAP};
|
|
1490
|
+
const GRID_RESET_PRICE = ${GRID_RESET_PRICE};
|
|
1491
|
+
const GRID_RESET_SLOPE = ${GRID_RESET_SLOPE};
|
|
1492
|
+
const GRID_RESET_REASON = {
|
|
1493
|
+
none: GRID_RESET_NONE,
|
|
1494
|
+
bootstrap: GRID_RESET_BOOTSTRAP,
|
|
1495
|
+
price: GRID_RESET_PRICE,
|
|
1496
|
+
slope: GRID_RESET_SLOPE,
|
|
1497
|
+
};
|
|
1498
|
+
function gridSimReasonLabel(reason) {
|
|
1499
|
+
if (reason === GRID_RESET_REASON.bootstrap) return 'init';
|
|
1500
|
+
if (reason === GRID_RESET_REASON.price) return '\u03941';
|
|
1501
|
+
if (reason === GRID_RESET_REASON.slope) return '\u0394s';
|
|
1502
|
+
return '';
|
|
1503
|
+
}
|
|
1504
|
+
function buildGridSimSeries(baseAma) {
|
|
1505
|
+
if (!gridSimCfg || !currentAmaEnabled || !Array.isArray(baseAma) || baseAma.length === 0) return null;
|
|
1506
|
+
// The adapter only starts accepting centers after the AMA has
|
|
1507
|
+
// converged (getAmaWarmupBars). On a chart shorter than that
|
|
1508
|
+
// convergence window the gate would swallow the whole series, so
|
|
1509
|
+
// cap it at half the data and report the applied value in the
|
|
1510
|
+
// panel — the replay then honestly shows the AMA transient.
|
|
1511
|
+
const n = baseAma.length;
|
|
1512
|
+
const warmup = Math.min(
|
|
1513
|
+
Math.max(0, Math.round(Number(gridSimCfg.warmupBars) || 0)),
|
|
1514
|
+
Math.floor(n / 2),
|
|
1515
|
+
);
|
|
1516
|
+
const override = gridSimCfg.warmupBarsOverride;
|
|
1517
|
+
const warmupBars = (override != null && Number.isFinite(Number(override)) && Number(override) >= 0)
|
|
1518
|
+
? Math.ceil(Number(override))
|
|
1519
|
+
: warmup;
|
|
1520
|
+
const cfg = Object.assign({}, gridSimCfg, { warmupBars: warmupBars });
|
|
1521
|
+
return simulateGridResetSeries(baseAma, cfg);
|
|
1522
|
+
}
|
|
1523
|
+
// Simulated grid range for each bar: the accepted center with the accepted
|
|
1524
|
+
// (frozen) slope tilt, through the same canonical pipeline the grid build
|
|
1525
|
+
// uses — applyAsymmetricBounds then applyNarrowingSideGuard. The base range
|
|
1526
|
+
// resolves per side: an absolute bot bound is a fixed level, a "Nx" bound
|
|
1527
|
+
// travels with the accepted center, and a missing side falls back to the
|
|
1528
|
+
// x-range span slider, exactly like computeRangeBand.
|
|
1529
|
+
function computeGridSimRange(sim) {
|
|
1530
|
+
const n = sim && Array.isArray(sim.center) ? sim.center.length : 0;
|
|
1531
|
+
const upper = new Array(n).fill(null);
|
|
1532
|
+
const lower = new Array(n).fill(null);
|
|
1533
|
+
if (!sim || n === 0) return { upper, lower };
|
|
1534
|
+
const gridCfg = payload.grid || null;
|
|
1535
|
+
const downMul = parseRelativeMultiplier(gridCfg && gridCfg.minPrice);
|
|
1536
|
+
const upMul = parseRelativeMultiplier(gridCfg && gridCfg.maxPrice);
|
|
1537
|
+
const hasRelMin = downMul != null && downMul > 1;
|
|
1538
|
+
const hasRelMax = upMul != null && upMul > 1;
|
|
1539
|
+
const inc = gridCfg && Number(gridCfg.incrementPercent) > 0
|
|
1540
|
+
? Number(gridCfg.incrementPercent)
|
|
1541
|
+
: (Number(gridSimCfg.incrementPercent) > 0 ? Number(gridSimCfg.incrementPercent) : null);
|
|
1542
|
+
const minSlots = Math.floor(Number(gridCfg && gridCfg.minScaleSlots) > 0 ? Number(gridCfg.minScaleSlots) : (Number(gridSimCfg.minScaleSlots) || 0));
|
|
1543
|
+
const maxAsym = gridCfg && Number(gridCfg.maxAsymmetryFactor) > 0
|
|
1544
|
+
? Number(gridCfg.maxAsymmetryFactor)
|
|
1545
|
+
: (Number(gridSimCfg.maxAsymmetryFactor) > 0 ? Number(gridSimCfg.maxAsymmetryFactor) : 0.333);
|
|
1546
|
+
const maxSlopeOffset = gridSimPositiveNumber(gridSimCfg.maxSlopeOffset, 0.5);
|
|
1547
|
+
const span = Math.min(2, Math.max(1.2, Number(currentRangeSpan) > 0 ? Number(currentRangeSpan) : 1.55));
|
|
1548
|
+
// Absolute bot bounds are fixed price levels; relative ("Nx") bounds
|
|
1549
|
+
// travel with the accepted center. Each side resolves independently so
|
|
1550
|
+
// a mixed absolute/"Nx" config matches the runtime grid build.
|
|
1551
|
+
const absMin = Number(gridSimCfg.clampMin);
|
|
1552
|
+
const absMax = Number(gridSimCfg.clampMax);
|
|
1553
|
+
const hasAbsMin = Number.isFinite(absMin) && absMin > 0;
|
|
1554
|
+
const hasAbsMax = Number.isFinite(absMax) && absMax > 0;
|
|
1555
|
+
for (let i = 0; i < n; i++) {
|
|
1556
|
+
const center = sim.center[i];
|
|
1557
|
+
if (!Number.isFinite(center) || center <= 0) continue;
|
|
1558
|
+
const rMin = hasAbsMin ? absMin : (hasRelMin ? center / downMul : center / span);
|
|
1559
|
+
const rMax = hasAbsMax ? absMax : (hasRelMax ? center * upMul : center * span);
|
|
1560
|
+
if (!Number.isFinite(rMin) || !Number.isFinite(rMax) || rMin <= 0 || rMax <= rMin) continue;
|
|
1561
|
+
const trend = sim.acceptedTrend[i];
|
|
1562
|
+
if ((trend === 'UP' || trend === 'DOWN') && Number(sim.acceptedSlopeOffset[i]) !== 0) {
|
|
1563
|
+
const tilt = applyAsymmetricBounds({
|
|
1564
|
+
centerPrice: center,
|
|
1565
|
+
minPrice: rMin,
|
|
1566
|
+
maxPrice: rMax,
|
|
1567
|
+
trend,
|
|
1568
|
+
slopeOffset: sim.acceptedSlopeOffset[i],
|
|
1569
|
+
maxSlopeOffset,
|
|
1570
|
+
maxAsymmetryFactor: maxAsym,
|
|
1571
|
+
});
|
|
1572
|
+
const guard = applyNarrowingSideGuard({
|
|
1573
|
+
centerPrice: center,
|
|
1574
|
+
minPrice: tilt.resolvedMinPrice,
|
|
1575
|
+
maxPrice: tilt.resolvedMaxPrice,
|
|
1576
|
+
trend,
|
|
1577
|
+
incrementPercent: inc,
|
|
1578
|
+
minScaleSlots: minSlots,
|
|
1579
|
+
});
|
|
1580
|
+
upper[i] = guard.maxPrice;
|
|
1581
|
+
lower[i] = guard.minPrice;
|
|
1582
|
+
} else {
|
|
1583
|
+
upper[i] = rMax;
|
|
1584
|
+
lower[i] = rMin;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
return { upper, lower };
|
|
1588
|
+
}
|
|
1451
1589
|
function computeRangeBand(baseAma) {
|
|
1452
1590
|
const n = Array.isArray(baseAma) ? baseAma.length : 0;
|
|
1453
1591
|
const upper = new Array(n).fill(null);
|
|
@@ -1531,6 +1669,11 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1531
1669
|
}
|
|
1532
1670
|
return lo;
|
|
1533
1671
|
}
|
|
1672
|
+
// How far the simulated grid range may stretch the auto price fit
|
|
1673
|
+
// before it is ignored. Bots with extreme bounds (e.g. 1.65x / 10x)
|
|
1674
|
+
// would otherwise squash the candles into a sliver; the band simply
|
|
1675
|
+
// clips in that case and the user can zoom out on the axis.
|
|
1676
|
+
const SIM_FIT_MAX_STRETCH = 2.5;
|
|
1534
1677
|
function visiblePriceRange(u) {
|
|
1535
1678
|
if (!currentCandles.length) return null;
|
|
1536
1679
|
const xs = u.data[0];
|
|
@@ -1541,6 +1684,8 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1541
1684
|
let end = Math.min(xs.length, lowerBound(xs, maxX) + 2);
|
|
1542
1685
|
let min = Infinity;
|
|
1543
1686
|
let max = -Infinity;
|
|
1687
|
+
let simMin = Infinity;
|
|
1688
|
+
let simMax = -Infinity;
|
|
1544
1689
|
// Range scaling active: fit the price axis to the full envelope
|
|
1545
1690
|
// (lower ↔ upper through AMA) instead of the candles, so the
|
|
1546
1691
|
// switch visibly adjusts the range. Falls through to the candle
|
|
@@ -1571,6 +1716,25 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1571
1716
|
if (Number.isFinite(s)) { if (s < min) min = s; if (s > max) max = s; }
|
|
1572
1717
|
if (Number.isFinite(a)) { if (a < min) min = a; if (a > max) max = a; }
|
|
1573
1718
|
if (Number.isFinite(v)) { if (v < min) min = v; if (v > max) max = v; }
|
|
1719
|
+
// Simulated grid: the accepted center always joins the fit (it
|
|
1720
|
+
// is the price the grid is anchored to); its band only joins it
|
|
1721
|
+
// while that stays within SIM_FIT_MAX_STRETCH.
|
|
1722
|
+
if (currentGridSimEnabled && gridSimCfg) {
|
|
1723
|
+
const c = currentGridCenter[i];
|
|
1724
|
+
const su = currentSimUpper[i];
|
|
1725
|
+
const sl = currentSimLower[i];
|
|
1726
|
+
if (Number.isFinite(c) && c > 0) { if (c < min) min = c; if (c > max) max = c; }
|
|
1727
|
+
if (Number.isFinite(su) && su > 0) { if (su > simMax) simMax = su; }
|
|
1728
|
+
if (Number.isFinite(sl) && sl > 0) { if (sl < simMin) simMin = sl; }
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
if (Number.isFinite(simMin) && Number.isFinite(simMax) && simMax > simMin) {
|
|
1732
|
+
const candleSpan = max - min;
|
|
1733
|
+
const simSpan = simMax - simMin;
|
|
1734
|
+
if (!(candleSpan > 0) || simSpan <= candleSpan * SIM_FIT_MAX_STRETCH) {
|
|
1735
|
+
if (simMin < min) min = simMin;
|
|
1736
|
+
if (simMax > max) max = simMax;
|
|
1737
|
+
}
|
|
1574
1738
|
}
|
|
1575
1739
|
if (!Number.isFinite(min) || !Number.isFinite(max) || min <= 0 || max <= 0) return null;
|
|
1576
1740
|
if (min === max) return [min * 0.96, max * 1.04];
|
|
@@ -1642,6 +1806,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1642
1806
|
setIndicatorSeriesVisible(8, currentAmaEnabled);
|
|
1643
1807
|
setIndicatorSeriesVisible(9, currentAmaEnabled && currentAmaInitOffset !== 0);
|
|
1644
1808
|
setIndicatorSeriesVisible(10, currentAmaEnabled && currentAmaInitOffset !== 0);
|
|
1809
|
+
setIndicatorSeriesVisible(11, currentAmaEnabled && currentGridSimEnabled && !!gridSimCfg);
|
|
1645
1810
|
}
|
|
1646
1811
|
function hideSmaSeriesImmediate() {
|
|
1647
1812
|
clearSMAWorker();
|
|
@@ -1669,17 +1834,32 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1669
1834
|
currentSmaInitOff = new Array(currentCandles.length).fill(null);
|
|
1670
1835
|
currentRangeUpper = new Array(currentCandles.length).fill(null);
|
|
1671
1836
|
currentRangeLower = new Array(currentCandles.length).fill(null);
|
|
1837
|
+
// The simulation replays triggers off the AMA series, so it goes
|
|
1838
|
+
// dark with it (draw hooks have no uPlot series of their own and
|
|
1839
|
+
// would otherwise keep painting the last replay).
|
|
1840
|
+
currentGridCenter = new Array(currentCandles.length).fill(null);
|
|
1841
|
+
currentSimUpper = new Array(currentCandles.length).fill(null);
|
|
1842
|
+
currentSimLower = new Array(currentCandles.length).fill(null);
|
|
1843
|
+
currentSimReason = new Array(currentCandles.length).fill(null);
|
|
1844
|
+
currentSimStats = null;
|
|
1845
|
+
currentSimStartIdx = null;
|
|
1846
|
+
currentSimLastIdx = null;
|
|
1672
1847
|
if (Array.isArray(currentPriceData) && currentPriceData.length >= 11) {
|
|
1673
1848
|
currentPriceData[6] = currentAma;
|
|
1674
1849
|
currentPriceData[8] = currentSmaInit;
|
|
1675
1850
|
currentPriceData[9] = currentSmaInitOff;
|
|
1676
1851
|
currentPriceData[10] = currentAmaOff;
|
|
1677
1852
|
}
|
|
1853
|
+
if (Array.isArray(currentPriceData) && currentPriceData.length >= 12) {
|
|
1854
|
+
currentPriceData[11] = currentGridCenter;
|
|
1855
|
+
}
|
|
1678
1856
|
setIndicatorSeriesVisible(6, false);
|
|
1679
1857
|
setIndicatorSeriesVisible(8, false);
|
|
1680
1858
|
setIndicatorSeriesVisible(9, false);
|
|
1681
1859
|
setIndicatorSeriesVisible(10, false);
|
|
1860
|
+
setIndicatorSeriesVisible(11, false);
|
|
1682
1861
|
refreshLegend();
|
|
1862
|
+
renderGridSimPanel();
|
|
1683
1863
|
saveState();
|
|
1684
1864
|
}
|
|
1685
1865
|
function hideVwapSeriesImmediate() {
|
|
@@ -1707,6 +1887,18 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1707
1887
|
document.getElementById('legend-vwap').textContent = Number.isFinite(currentVwap[idx]) ? fmtPrice(currentVwap[idx]) : '-';
|
|
1708
1888
|
document.getElementById('legend-sma-init').textContent = Number.isFinite(currentSmaInit[idx]) ? fmtPrice(currentSmaInit[idx]) : '-';
|
|
1709
1889
|
document.getElementById('legend-ama').textContent = Number.isFinite(currentAma[idx]) ? fmtPrice(currentAma[idx]) : '-';
|
|
1890
|
+
const gridLegend = document.getElementById('legend-grid-center');
|
|
1891
|
+
if (gridLegend) {
|
|
1892
|
+
gridLegend.textContent = Number.isFinite(currentGridCenter[idx]) ? fmtPrice(currentGridCenter[idx]) : '-';
|
|
1893
|
+
const reasonEl = document.getElementById('legend-grid-reason');
|
|
1894
|
+
if (reasonEl) {
|
|
1895
|
+
const label = gridSimReasonLabel(currentSimReason[idx]);
|
|
1896
|
+
reasonEl.textContent = label ? ' ' + label : '';
|
|
1897
|
+
reasonEl.style.color = currentSimReason[idx] === GRID_RESET_REASON.slope
|
|
1898
|
+
? '#22d3ee'
|
|
1899
|
+
: (currentSimReason[idx] === GRID_RESET_REASON.price ? '#f59e0b' : '#94a3b8');
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1710
1902
|
}
|
|
1711
1903
|
function candlePlugin() {
|
|
1712
1904
|
function drawCandles(u) {
|
|
@@ -1923,6 +2115,141 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1923
2115
|
}
|
|
1924
2116
|
return { hooks: { draw: [drawRangeBand] } };
|
|
1925
2117
|
}
|
|
2118
|
+
// ── Grid-reset simulation overlay ──
|
|
2119
|
+
// Two layers:
|
|
2120
|
+
// 1. the simulated grid range (accepted center + accepted slope tilt),
|
|
2121
|
+
// painted behind the candles like the AMA range band but in the
|
|
2122
|
+
// simulation's own hue, and
|
|
2123
|
+
// 2. one vertical marker per simulated reset, colored by trigger
|
|
2124
|
+
// (amber = AMA-price Δ, cyan = AMA-slope Δ, grey = first snapshot).
|
|
2125
|
+
function gridResetPlugin() {
|
|
2126
|
+
const BAND_FILL = 'rgba(192,132,252,0.10)';
|
|
2127
|
+
const BAND_EDGE = 'rgba(192,132,252,0.75)';
|
|
2128
|
+
const REASON_COLOR = {
|
|
2129
|
+
[GRID_RESET_REASON.bootstrap]: '#94a3b8',
|
|
2130
|
+
[GRID_RESET_REASON.price]: '#f59e0b',
|
|
2131
|
+
[GRID_RESET_REASON.slope]: '#22d3ee',
|
|
2132
|
+
};
|
|
2133
|
+
function drawSimBand(u) {
|
|
2134
|
+
if (!currentGridSimEnabled || !currentAmaEnabled || !currentCandles.length) return;
|
|
2135
|
+
const xs = u.data[0];
|
|
2136
|
+
if (!Array.isArray(xs) || xs.length === 0) return;
|
|
2137
|
+
u.ctx.save();
|
|
2138
|
+
u.ctx.beginPath();
|
|
2139
|
+
u.ctx.rect(u.bbox.left, u.bbox.top, u.bbox.width, u.bbox.height);
|
|
2140
|
+
u.ctx.clip();
|
|
2141
|
+
// Behind candles/lines, same trick as the range band.
|
|
2142
|
+
u.ctx.globalCompositeOperation = 'destination-over';
|
|
2143
|
+
const [iMin, iMax] = (u.series[0] && u.series[0].idxs) ? u.series[0].idxs : [0, xs.length - 1];
|
|
2144
|
+
let seg = [];
|
|
2145
|
+
const flush = () => {
|
|
2146
|
+
if (seg.length > 1) {
|
|
2147
|
+
u.ctx.fillStyle = BAND_FILL;
|
|
2148
|
+
u.ctx.beginPath();
|
|
2149
|
+
u.ctx.moveTo(seg[0][0], seg[0][1]);
|
|
2150
|
+
for (let k = 1; k < seg.length; k++) u.ctx.lineTo(seg[k][0], seg[k][1]);
|
|
2151
|
+
for (let k = seg.length - 1; k >= 0; k--) u.ctx.lineTo(seg[k][0], seg[k][2]);
|
|
2152
|
+
u.ctx.closePath();
|
|
2153
|
+
u.ctx.fill();
|
|
2154
|
+
u.ctx.strokeStyle = BAND_EDGE;
|
|
2155
|
+
u.ctx.lineWidth = 1;
|
|
2156
|
+
u.ctx.beginPath();
|
|
2157
|
+
u.ctx.moveTo(seg[0][0], seg[0][1]);
|
|
2158
|
+
for (let k = 1; k < seg.length; k++) u.ctx.lineTo(seg[k][0], seg[k][1]);
|
|
2159
|
+
u.ctx.stroke();
|
|
2160
|
+
u.ctx.beginPath();
|
|
2161
|
+
u.ctx.moveTo(seg[0][0], seg[0][2]);
|
|
2162
|
+
for (let k = 1; k < seg.length; k++) u.ctx.lineTo(seg[k][0], seg[k][2]);
|
|
2163
|
+
u.ctx.stroke();
|
|
2164
|
+
}
|
|
2165
|
+
seg = [];
|
|
2166
|
+
};
|
|
2167
|
+
for (let i = iMin; i <= iMax; i++) {
|
|
2168
|
+
const center = currentGridCenter[i];
|
|
2169
|
+
const up = currentSimUpper[i];
|
|
2170
|
+
const lo = currentSimLower[i];
|
|
2171
|
+
if (!Number.isFinite(center) || center <= 0
|
|
2172
|
+
|| !Number.isFinite(up) || up <= center
|
|
2173
|
+
|| !Number.isFinite(lo) || lo <= 0 || lo >= center) {
|
|
2174
|
+
flush();
|
|
2175
|
+
continue;
|
|
2176
|
+
}
|
|
2177
|
+
const x = u.valToPos(xs[i], 'x', true);
|
|
2178
|
+
const yU = u.valToPos(up, 'y', true);
|
|
2179
|
+
const yL = u.valToPos(lo, 'y', true);
|
|
2180
|
+
if (!Number.isFinite(x) || !Number.isFinite(yU) || !Number.isFinite(yL)) {
|
|
2181
|
+
flush();
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
seg.push([x, yU, yL]);
|
|
2185
|
+
}
|
|
2186
|
+
flush();
|
|
2187
|
+
u.ctx.restore();
|
|
2188
|
+
}
|
|
2189
|
+
function drawSimResets(u) {
|
|
2190
|
+
if (!currentGridSimEnabled || !currentAmaEnabled || !currentCandles.length) return;
|
|
2191
|
+
const xs = u.data[0];
|
|
2192
|
+
if (!Array.isArray(xs) || xs.length === 0) return;
|
|
2193
|
+
const [iMin, iMax] = (u.series[0] && u.series[0].idxs) ? u.series[0].idxs : [0, xs.length - 1];
|
|
2194
|
+
const top = u.bbox.top;
|
|
2195
|
+
const height = u.bbox.height;
|
|
2196
|
+
u.ctx.save();
|
|
2197
|
+
u.ctx.beginPath();
|
|
2198
|
+
u.ctx.rect(u.bbox.left, u.bbox.top, u.bbox.width, u.bbox.height);
|
|
2199
|
+
u.ctx.clip();
|
|
2200
|
+
let lastLabelX = [-Infinity, -Infinity];
|
|
2201
|
+
u.ctx.font = '600 10px Segoe UI, sans-serif';
|
|
2202
|
+
u.ctx.textAlign = 'left';
|
|
2203
|
+
u.ctx.textBaseline = 'middle';
|
|
2204
|
+
for (let i = iMin; i <= iMax; i++) {
|
|
2205
|
+
const reason = currentSimReason[i];
|
|
2206
|
+
if (!reason) continue;
|
|
2207
|
+
const x = u.valToPos(xs[i], 'x', true);
|
|
2208
|
+
if (!Number.isFinite(x)) continue;
|
|
2209
|
+
const color = REASON_COLOR[reason] || '#94a3b8';
|
|
2210
|
+
// Slope resets are typically far more frequent than price
|
|
2211
|
+
// resets, so they are drawn fainter to keep clusters readable.
|
|
2212
|
+
const emphasis = reason === GRID_RESET_REASON.slope ? 0.4 : 0.8;
|
|
2213
|
+
u.ctx.strokeStyle = color;
|
|
2214
|
+
u.ctx.globalAlpha = emphasis;
|
|
2215
|
+
u.ctx.lineWidth = 1.5;
|
|
2216
|
+
u.ctx.setLineDash(reason === GRID_RESET_REASON.price ? [] : [4, 3]);
|
|
2217
|
+
u.ctx.beginPath();
|
|
2218
|
+
u.ctx.moveTo(x, top);
|
|
2219
|
+
u.ctx.lineTo(x, top + height);
|
|
2220
|
+
u.ctx.stroke();
|
|
2221
|
+
// A tick where the center jumped to, so the step is visible
|
|
2222
|
+
// even when the accepted center is off-screen.
|
|
2223
|
+
const center = currentGridCenter[i];
|
|
2224
|
+
const yC = Number.isFinite(center) ? u.valToPos(center, 'y', true) : NaN;
|
|
2225
|
+
if (Number.isFinite(yC)) {
|
|
2226
|
+
u.ctx.setLineDash([]);
|
|
2227
|
+
u.ctx.fillStyle = color;
|
|
2228
|
+
u.ctx.beginPath();
|
|
2229
|
+
u.ctx.arc(x, yC, 3, 0, Math.PI * 2);
|
|
2230
|
+
u.ctx.fill();
|
|
2231
|
+
}
|
|
2232
|
+
// Two label lanes; a lane is skipped when the next marker
|
|
2233
|
+
// would overlap the previous label on it.
|
|
2234
|
+
if (x - u.bbox.left > u.bbox.width - 60) continue;
|
|
2235
|
+
const lane = (x - lastLabelX[0]) > 40 ? 0 : 1;
|
|
2236
|
+
if ((x - lastLabelX[lane]) <= 40) continue;
|
|
2237
|
+
lastLabelX[lane] = x;
|
|
2238
|
+
const labelY = top + 10 + lane * 15;
|
|
2239
|
+
const text = gridSimReasonLabel(reason);
|
|
2240
|
+
u.ctx.globalAlpha = 1;
|
|
2241
|
+
const w = u.ctx.measureText(text).width + 6;
|
|
2242
|
+
u.ctx.fillStyle = 'rgba(13,17,23,0.9)';
|
|
2243
|
+
u.ctx.fillRect(x + 2, labelY - 7, w, 14);
|
|
2244
|
+
u.ctx.fillStyle = color;
|
|
2245
|
+
u.ctx.fillText(text, x + 5, labelY);
|
|
2246
|
+
}
|
|
2247
|
+
u.ctx.setLineDash([]);
|
|
2248
|
+
u.ctx.globalAlpha = 1;
|
|
2249
|
+
u.ctx.restore();
|
|
2250
|
+
}
|
|
2251
|
+
return { hooks: { draw: [drawSimBand, drawSimResets] } };
|
|
2252
|
+
}
|
|
1926
2253
|
function buildData() {
|
|
1927
2254
|
const tf = timeframeMap.get(currentTimeframe) || timeframeMap.get(defaultTimeframe.label) || timeframes[0];
|
|
1928
2255
|
currentSeriesState = getSeriesState(currentPairMode);
|
|
@@ -1960,6 +2287,36 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1960
2287
|
const baseRange = computeRangeBand(baseAma);
|
|
1961
2288
|
currentRangeUpper = sampleSeriesByIndex(baseRange.upper, aggregated.idxs);
|
|
1962
2289
|
currentRangeLower = sampleSeriesByIndex(baseRange.lower, aggregated.idxs);
|
|
2290
|
+
// Grid-reset simulation: replayed on the 1h AMA series (so AMA input
|
|
2291
|
+
// changes re-run it), then sampled onto the active timeframe like
|
|
2292
|
+
// every other indicator.
|
|
2293
|
+
const baseSim = currentGridSimEnabled ? buildGridSimSeries(baseAma) : null;
|
|
2294
|
+
currentSimStats = baseSim ? baseSim.stats : null;
|
|
2295
|
+
// First displayed bar at/after a 1h replay index (aggregated.idxs
|
|
2296
|
+
// holds the last 1h index of every displayed bucket).
|
|
2297
|
+
const displayIndexOf = (baseIdx) => {
|
|
2298
|
+
if (baseIdx == null) return null;
|
|
2299
|
+
for (let k = 0; k < aggregated.idxs.length; k++) {
|
|
2300
|
+
if (aggregated.idxs[k] >= baseIdx) return k;
|
|
2301
|
+
}
|
|
2302
|
+
return aggregated.idxs.length > 0 ? aggregated.idxs.length - 1 : null;
|
|
2303
|
+
};
|
|
2304
|
+
currentSimStartIdx = baseSim ? displayIndexOf(baseSim.stats.bootstrapIndex) : null;
|
|
2305
|
+
currentSimLastIdx = baseSim ? displayIndexOf(baseSim.stats.lastResetIndex) : null;
|
|
2306
|
+
if (baseSim) {
|
|
2307
|
+
currentGridCenter = sampleSeriesByIndex(baseSim.center, aggregated.idxs);
|
|
2308
|
+
currentSimReason = sampleSeriesByIndex(baseSim.reason, aggregated.idxs);
|
|
2309
|
+
const simRange = computeGridSimRange(baseSim);
|
|
2310
|
+
currentSimUpper = sampleSeriesByIndex(simRange.upper, aggregated.idxs);
|
|
2311
|
+
currentSimLower = sampleSeriesByIndex(simRange.lower, aggregated.idxs);
|
|
2312
|
+
} else {
|
|
2313
|
+
currentGridCenter = new Array(currentCandles.length).fill(null);
|
|
2314
|
+
currentSimReason = new Array(currentCandles.length).fill(null);
|
|
2315
|
+
currentSimUpper = new Array(currentCandles.length).fill(null);
|
|
2316
|
+
currentSimLower = new Array(currentCandles.length).fill(null);
|
|
2317
|
+
currentSimStartIdx = null;
|
|
2318
|
+
currentSimLastIdx = null;
|
|
2319
|
+
}
|
|
1963
2320
|
currentAmaOff = currentAmaEnabled && currentAmaInitOffset !== 0 ? sampleSeriesByIndex(baseAmaOff, aggregated.idxs) : new Array(currentCandles.length).fill(null);
|
|
1964
2321
|
currentVwap = currentVwapEnabled ? sampleSeriesByIndex(baseVwap, aggregated.idxs) : new Array(currentCandles.length).fill(null);
|
|
1965
2322
|
const amaCfg = currentAmaConfig();
|
|
@@ -1996,6 +2353,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1996
2353
|
currentSmaInit,
|
|
1997
2354
|
currentSmaInitOff,
|
|
1998
2355
|
currentAmaOff,
|
|
2356
|
+
currentGridCenter,
|
|
1999
2357
|
];
|
|
2000
2358
|
currentVolumeData = [
|
|
2001
2359
|
currentCandles.map((c) => c.time),
|
|
@@ -2048,6 +2406,9 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
2048
2406
|
{ label: 'AMA Init', stroke: '#22c55e', width: 1.5, dash: [6, 4], points: { show: false }, spanGaps: false },
|
|
2049
2407
|
{ label: 'Off Init', stroke: '#a855f7', width: 1.5, dash: [6, 4], points: { show: false }, spanGaps: false },
|
|
2050
2408
|
{ label: 'AMA Off', stroke: '#a855f7', width: 1.5, dash: [4, 4], points: { show: false }, spanGaps: false },
|
|
2409
|
+
// Accepted grid center: piecewise constant (ratchets only on a
|
|
2410
|
+
// simulated reset), so the plain polyline already draws as steps.
|
|
2411
|
+
{ label: 'Grid Ctr', stroke: '#c084fc', width: 1.5, dash: [3, 3], points: { show: false }, spanGaps: false },
|
|
2051
2412
|
],
|
|
2052
2413
|
axes: [
|
|
2053
2414
|
makeTimeAxis(false),
|
|
@@ -2078,7 +2439,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
2078
2439
|
|
|
2079
2440
|
const plugin = candlePlugin();
|
|
2080
2441
|
plugin.opts(null, priceOpts);
|
|
2081
|
-
priceOpts.plugins = [rangeBandPlugin(), plugin];
|
|
2442
|
+
priceOpts.plugins = [rangeBandPlugin(), gridResetPlugin(), plugin];
|
|
2082
2443
|
if (!priceChart) priceChart = new uPlot(priceOpts, data.priceData, priceEl);
|
|
2083
2444
|
else priceChart.setData(data.priceData, false);
|
|
2084
2445
|
|
|
@@ -2733,6 +3094,8 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
2733
3094
|
setActivePriceScale(currentPriceScale);
|
|
2734
3095
|
const ordersToggle = document.getElementById('orders-toggle');
|
|
2735
3096
|
if (ordersToggle) ordersToggle.checked = currentOrdersVisible;
|
|
3097
|
+
const gridSimToggle = document.getElementById('grid-sim-toggle');
|
|
3098
|
+
if (gridSimToggle) gridSimToggle.checked = currentGridSimEnabled;
|
|
2736
3099
|
const volumeToggleEl = document.getElementById('volume-toggle');
|
|
2737
3100
|
if (volumeToggleEl) volumeToggleEl.checked = currentVolumeVisible;
|
|
2738
3101
|
setActiveVolumeUnit();
|
|
@@ -2856,6 +3219,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
2856
3219
|
renderMarketPanel();
|
|
2857
3220
|
renderRangePanel();
|
|
2858
3221
|
renderVolumePanel();
|
|
3222
|
+
renderGridSimPanel();
|
|
2859
3223
|
saveState();
|
|
2860
3224
|
}
|
|
2861
3225
|
|
|
@@ -2905,6 +3269,17 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
2905
3269
|
renderMarketPanel();
|
|
2906
3270
|
});
|
|
2907
3271
|
}
|
|
3272
|
+
// Grid-reset simulation toggle: replays the accepted center/band, so it
|
|
3273
|
+
// needs a full rerender (the replay is derived from the AMA series).
|
|
3274
|
+
const gridSimToggleInit = document.getElementById('grid-sim-toggle');
|
|
3275
|
+
if (gridSimToggleInit) {
|
|
3276
|
+
gridSimToggleInit.checked = currentGridSimEnabled;
|
|
3277
|
+
gridSimToggleInit.addEventListener('change', () => {
|
|
3278
|
+
currentGridSimEnabled = gridSimToggleInit.checked;
|
|
3279
|
+
setControls();
|
|
3280
|
+
rerender(true);
|
|
3281
|
+
});
|
|
3282
|
+
}
|
|
2908
3283
|
// Volume toggle: hide the volume chart so flex yields the space to
|
|
2909
3284
|
// the price chart (larger). No rerender, resize only.
|
|
2910
3285
|
const applyVolumeVisibility = () => {
|
|
@@ -3189,6 +3564,46 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
3189
3564
|
panel.style.display = 'block';
|
|
3190
3565
|
panel.innerHTML = '<div style="color:#e8eef5">max ' + fmtVolumeWithSym(stats.vol) + '</div>';
|
|
3191
3566
|
}
|
|
3567
|
+
// Grid-reset panel (bottom-left of the price chart): the thresholds the
|
|
3568
|
+
// replay used, where each came from (constants / general.settings /
|
|
3569
|
+
// market_adapter_settings globals|pair|bot / cli), and how often the
|
|
3570
|
+
// grid would have recentered. Only rendered for AMA-grid bots.
|
|
3571
|
+
function fmtSimSource(source) {
|
|
3572
|
+
if (source === 'market_adapter_settings:bot') return 'bot';
|
|
3573
|
+
if (source === 'market_adapter_settings:pair') return 'pair';
|
|
3574
|
+
if (source === 'market_adapter_settings:globals') return 'ma-globals';
|
|
3575
|
+
if (source === 'general.settings') return 'general';
|
|
3576
|
+
if (source === 'cli') return 'cli';
|
|
3577
|
+
return 'default';
|
|
3578
|
+
}
|
|
3579
|
+
function renderGridSimPanel() {
|
|
3580
|
+
if (!priceChart) return;
|
|
3581
|
+
let panel = document.getElementById('grid-sim-panel');
|
|
3582
|
+
if (!panel) {
|
|
3583
|
+
panel = document.createElement('div');
|
|
3584
|
+
panel.id = 'grid-sim-panel';
|
|
3585
|
+
panel.style.cssText = 'position:absolute;z-index:26;bottom:10px;left:10px;pointer-events:none;font:600 12px ui-monospace,SFMono-Regular,Menlo,monospace;line-height:1.5;padding:6px 10px;border-radius:8px;background:rgba(13,17,23,0.85);border:1px solid #263241;white-space:nowrap;text-align:left;';
|
|
3586
|
+
priceChart.root.appendChild(panel);
|
|
3587
|
+
}
|
|
3588
|
+
if (!gridSimCfg || !currentGridSimEnabled || !currentSimStats) { panel.style.display = 'none'; return; }
|
|
3589
|
+
const st = currentSimStats;
|
|
3590
|
+
const priceThr = gridSimCfg.priceDeltaThresholdPercent;
|
|
3591
|
+
const slopeThr = gridSimCfg.slopeDeltaThresholdPercent;
|
|
3592
|
+
panel.style.display = 'block';
|
|
3593
|
+
let html = '<div style="color:#c084fc">sim grid resets: ' + st.resets + ' <span style="color:#f59e0b">\u03941 ' + st.priceResets + '</span> <span style="color:#22d3ee">\u0394s ' + st.slopeResets + '</span></div>';
|
|
3594
|
+
html += '<div style="color:#e8eef5">AMA \u0394 ' + (Number.isFinite(priceThr) ? Number(priceThr).toFixed(2) + '%' : '-') + ' <span style="color:#8b949e">(' + fmtSimSource(gridSimCfg.priceSource) + ')</span></div>';
|
|
3595
|
+
html += '<div style="color:#e8eef5">Slope \u0394 ' + (Number.isFinite(slopeThr) ? Number(slopeThr).toFixed(4) + '%/bar' : '-')
|
|
3596
|
+
+ ' <span style="color:#8b949e">(' + fmtSimSource(gridSimCfg.slopeSource) + (st.slopeTriggerArmed ? '' : ', off') + ')</span></div>';
|
|
3597
|
+
if (st.lastResetIndex != null) {
|
|
3598
|
+
const last = currentCandles[Math.max(0, Math.min(currentCandles.length - 1, currentSimLastIdx ?? 0))];
|
|
3599
|
+
html += '<div style="color:#8b949e">last ' + (last ? fmtTime(last.time) : '-') + ' (' + st.barsSinceLastReset + ' bars ago)</div>';
|
|
3600
|
+
}
|
|
3601
|
+
if (st.bootstrapIndex != null) {
|
|
3602
|
+
const first = currentCandles[Math.max(0, Math.min(currentCandles.length - 1, currentSimStartIdx ?? 0))];
|
|
3603
|
+
html += '<div style="color:#8b949e">sim from ' + (first ? fmtTime(first.time) : '-') + ' (' + st.warmupBars + ' warmup)</div>';
|
|
3604
|
+
}
|
|
3605
|
+
panel.innerHTML = html;
|
|
3606
|
+
}
|
|
3192
3607
|
function scheduleStatPanels() {
|
|
3193
3608
|
if (rangePanelRaf) return;
|
|
3194
3609
|
rangePanelRaf = requestAnimationFrame(() => {
|
|
@@ -3229,6 +3644,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
3229
3644
|
renderMarketPanel();
|
|
3230
3645
|
renderRangePanel();
|
|
3231
3646
|
renderVolumePanel();
|
|
3647
|
+
renderGridSimPanel();
|
|
3232
3648
|
|
|
3233
3649
|
window.addEventListener('resize', () => {
|
|
3234
3650
|
if (!charts.length) return;
|