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.
Files changed (613) hide show
  1. package/CHANGELOG.md +49 -1
  2. package/README.md +3 -3
  3. package/analysis/README.md +2 -3
  4. package/analysis/tradingview/README.md +78 -1
  5. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
  6. package/claw/package.json +1 -1
  7. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  8. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  9. package/dist/analysis/tradingview/analyze_tradingview.d.ts +4 -0
  10. package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
  11. package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
  12. package/dist/analysis/tradingview/grid_reset_config.js +235 -0
  13. package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
  14. package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
  15. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
  16. package/dist/dexbot.js +22 -6
  17. package/dist/market_adapter/core/market_adapter_service.js +14 -2
  18. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
  19. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
  20. package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
  21. package/dist/market_adapter/inputs/window_cache.js +302 -48
  22. package/dist/market_adapter/market_adapter.d.ts +8 -1
  23. package/dist/market_adapter/market_adapter.js +22 -4
  24. package/dist/modules/account_bots.js +10 -0
  25. package/dist/modules/account_orders.d.ts +24 -2
  26. package/dist/modules/account_orders.js +41 -4
  27. package/dist/modules/bot_settings.js +10 -1
  28. package/dist/modules/config.d.ts +1 -0
  29. package/dist/modules/config.js +1 -0
  30. package/dist/modules/constants.d.ts +11 -3
  31. package/dist/modules/constants.js +116 -37
  32. package/dist/modules/dexbot_class.d.ts +6 -76
  33. package/dist/modules/dexbot_class.js +0 -32
  34. package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
  35. package/dist/modules/dexbot_cow_runtime.js +4 -87
  36. package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -1
  37. package/dist/modules/dexbot_maintenance_runtime.js +59 -11
  38. package/dist/modules/dexbot_startup_runtime.js +73 -20
  39. package/dist/modules/dexbot_state_recovery.d.ts +6 -0
  40. package/dist/modules/dexbot_state_recovery.js +21 -0
  41. package/dist/modules/order/async_lock.d.ts +8 -0
  42. package/dist/modules/order/async_lock.js +15 -0
  43. package/dist/modules/order/genesis_policy.d.ts +162 -0
  44. package/dist/modules/order/genesis_policy.js +267 -0
  45. package/dist/modules/order/grid.js +76 -134
  46. package/dist/modules/order/grid_reconcile.d.ts +9 -0
  47. package/dist/modules/order/grid_reconcile.js +13 -4
  48. package/dist/modules/order/grid_reconcile_internal.js +2 -2
  49. package/dist/modules/order/manager.d.ts +4 -0
  50. package/dist/modules/order/manager.js +14 -1
  51. package/dist/modules/order/sync_engine.d.ts +19 -0
  52. package/dist/modules/order/sync_engine.js +284 -344
  53. package/dist/modules/order/utils/math.d.ts +22 -1
  54. package/dist/modules/order/utils/math.js +64 -1
  55. package/dist/modules/order/utils/order.d.ts +43 -58
  56. package/dist/modules/order/utils/order.js +220 -197
  57. package/dist/modules/order/utils/system.js +8 -1
  58. package/dist/modules/paths.d.ts +1 -0
  59. package/dist/modules/paths.js +1 -0
  60. package/dist/modules/version_notice.d.ts +165 -0
  61. package/dist/modules/version_notice.js +364 -0
  62. package/dist/pm2.js +9 -0
  63. package/dist/unlock.js +28 -0
  64. package/docs/BITSHARES_ONBOARDING.md +8 -1
  65. package/docs/COW_INVARIANTS.md +3 -2
  66. package/docs/DEXBOT_COMPARISON.md +4 -4
  67. package/docs/EVOLUTION.md +20 -19
  68. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  69. package/docs/GRID_PRICE_INVARIANT.md +149 -31
  70. package/docs/GRID_RECALCULATION.md +12 -0
  71. package/docs/README.md +3 -1
  72. package/docs/WORKFLOW.md +16 -5
  73. package/market_adapter/README.md +1 -1
  74. package/modules/README.md +18 -1
  75. package/package.json +13 -5
  76. package/scripts/README.md +28 -2
  77. package/scripts/clear-all.sh +13 -4
  78. package/scripts/clear-logs.sh +13 -4
  79. package/scripts/clear-market-adapter.sh +6 -0
  80. package/scripts/clear-orders.sh +5 -0
  81. package/scripts/lib/dexbot-paths.sh +108 -0
  82. package/tests/README.md +11 -3
  83. package/analysis/account_resolver.ts +0 -161
  84. package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
  85. package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
  86. package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
  87. package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
  88. package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
  89. package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
  90. package/analysis/analyze_dynamic_weight.ts +0 -243
  91. package/analysis/analyze_kalman.ts +0 -157
  92. package/analysis/analyze_regime.ts +0 -158
  93. package/analysis/analyze_regime_windows.ts +0 -470
  94. package/analysis/analyze_risk_profile.ts +0 -199
  95. package/analysis/analyze_trade_heatmap.ts +0 -362
  96. package/analysis/analyze_volatility.ts +0 -182
  97. package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
  98. package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
  99. package/analysis/bot_fitting/shared_utils.ts +0 -52
  100. package/analysis/bot_key_utils.ts +0 -426
  101. package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
  102. package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
  103. package/analysis/chain_pool.ts +0 -47
  104. package/analysis/chart_css.ts +0 -62
  105. package/analysis/chart_ui.ts +0 -105
  106. package/analysis/chart_utils.ts +0 -210
  107. package/analysis/fills_source.ts +0 -228
  108. package/analysis/grid_correction_check.ts +0 -786
  109. package/analysis/math_utils.ts +0 -53
  110. package/analysis/price_sources.ts +0 -136
  111. package/analysis/resolve_bot_accounts.ts +0 -199
  112. package/analysis/resolve_source.ts +0 -99
  113. package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
  114. package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
  115. package/analysis/trade_profitability.ts +0 -1335
  116. package/analysis/tradingview/analyze_tradingview.ts +0 -280
  117. package/analysis/tradingview/h-bts_tradingview.html +0 -1570
  118. package/analysis/tradingview/t-bts_tradingview.html +0 -1570
  119. package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
  120. package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
  121. package/analysis/trend_detection/hurst_analyzer.ts +0 -7
  122. package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
  123. package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
  124. package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
  125. package/analysis/trend_detection/package.json +0 -23
  126. package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
  127. package/analysis/trend_detection/regime_chart_generator.ts +0 -338
  128. package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
  129. package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
  130. package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
  131. package/analysis/tsconfig.json +0 -29
  132. package/claw/tests/package.json +0 -3
  133. package/claw/tests/test_claw_bridge.ts +0 -570
  134. package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
  135. package/claw/tests/test_claw_chain_layer.ts +0 -739
  136. package/claw/tests/test_claw_data_flow.ts +0 -525
  137. package/claw/tests/test_claw_domain_logic.ts +0 -471
  138. package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
  139. package/claw/tests/test_claw_mcp_transport.ts +0 -243
  140. package/claw/tests/test_claw_regressions.ts +0 -711
  141. package/claw/tests/test_claw_skill_generation.ts +0 -103
  142. package/claw/tests/test_claw_state_store.ts +0 -44
  143. package/claw/tests/test_dexbot_profiles.ts +0 -654
  144. package/claw/tests/test_memu_bridge.ts +0 -189
  145. package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
  146. package/claw/tests/test_position_health.ts +0 -343
  147. package/claw/tests/test_position_manager.ts +0 -429
  148. package/claw/tests/test_position_manager_watch_health.ts +0 -100
  149. package/claw/tests/test_short_mpa_strategy.ts +0 -232
  150. package/dist/analysis/account_resolver.d.ts.map +0 -1
  151. package/dist/analysis/account_resolver.js.map +0 -1
  152. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
  153. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
  154. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
  155. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
  156. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
  157. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
  158. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
  159. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
  160. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
  161. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
  162. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
  163. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
  164. package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
  165. package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
  166. package/dist/analysis/analyze_kalman.d.ts.map +0 -1
  167. package/dist/analysis/analyze_kalman.js.map +0 -1
  168. package/dist/analysis/analyze_regime.d.ts.map +0 -1
  169. package/dist/analysis/analyze_regime.js.map +0 -1
  170. package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
  171. package/dist/analysis/analyze_regime_windows.js.map +0 -1
  172. package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
  173. package/dist/analysis/analyze_risk_profile.js.map +0 -1
  174. package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
  175. package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
  176. package/dist/analysis/analyze_volatility.d.ts.map +0 -1
  177. package/dist/analysis/analyze_volatility.js.map +0 -1
  178. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
  179. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
  180. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
  181. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
  182. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
  183. package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
  184. package/dist/analysis/bot_key_utils.d.ts.map +0 -1
  185. package/dist/analysis/bot_key_utils.js.map +0 -1
  186. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
  187. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
  188. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
  189. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
  190. package/dist/analysis/chain_pool.d.ts.map +0 -1
  191. package/dist/analysis/chain_pool.js.map +0 -1
  192. package/dist/analysis/chart_css.d.ts.map +0 -1
  193. package/dist/analysis/chart_css.js.map +0 -1
  194. package/dist/analysis/chart_ui.d.ts.map +0 -1
  195. package/dist/analysis/chart_ui.js.map +0 -1
  196. package/dist/analysis/chart_utils.d.ts.map +0 -1
  197. package/dist/analysis/chart_utils.js.map +0 -1
  198. package/dist/analysis/fills_source.d.ts.map +0 -1
  199. package/dist/analysis/fills_source.js.map +0 -1
  200. package/dist/analysis/grid_correction_check.d.ts.map +0 -1
  201. package/dist/analysis/grid_correction_check.js.map +0 -1
  202. package/dist/analysis/math_utils.d.ts.map +0 -1
  203. package/dist/analysis/math_utils.js.map +0 -1
  204. package/dist/analysis/price_sources.d.ts.map +0 -1
  205. package/dist/analysis/price_sources.js.map +0 -1
  206. package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
  207. package/dist/analysis/resolve_bot_accounts.js.map +0 -1
  208. package/dist/analysis/resolve_source.d.ts.map +0 -1
  209. package/dist/analysis/resolve_source.js.map +0 -1
  210. package/dist/analysis/trade_profitability.d.ts.map +0 -1
  211. package/dist/analysis/trade_profitability.js.map +0 -1
  212. package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
  213. package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
  214. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
  215. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
  216. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
  217. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
  218. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
  219. package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
  220. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
  221. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
  222. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
  223. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
  224. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
  225. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
  226. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
  227. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
  228. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
  229. package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
  230. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
  231. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
  232. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
  233. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
  234. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
  235. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
  236. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
  237. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
  238. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
  239. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
  240. package/dist/bot.d.ts.map +0 -1
  241. package/dist/bot.js.map +0 -1
  242. package/dist/credential-daemon.d.ts.map +0 -1
  243. package/dist/credential-daemon.js.map +0 -1
  244. package/dist/dexbot.d.ts.map +0 -1
  245. package/dist/dexbot.js.map +0 -1
  246. package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
  247. package/dist/market_adapter/ama_signal_runner.js.map +0 -1
  248. package/dist/market_adapter/candle_utils.d.ts.map +0 -1
  249. package/dist/market_adapter/candle_utils.js.map +0 -1
  250. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
  251. package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
  252. package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
  253. package/dist/market_adapter/core/config_normalizers.js.map +0 -1
  254. package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
  255. package/dist/market_adapter/core/kibana_candles.js.map +0 -1
  256. package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
  257. package/dist/market_adapter/core/kibana_client.js.map +0 -1
  258. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
  259. package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
  260. package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
  261. package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
  262. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
  263. package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
  264. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
  265. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
  266. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
  267. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
  268. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
  269. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
  270. package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
  271. package/dist/market_adapter/core/strategies/ama.js.map +0 -1
  272. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
  273. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
  274. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
  275. package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
  276. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
  277. package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
  278. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
  279. package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
  280. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
  281. package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
  282. package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
  283. package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
  284. package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
  285. package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
  286. package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
  287. package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
  288. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
  289. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
  290. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
  291. package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
  292. package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
  293. package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
  294. package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
  295. package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
  296. package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
  297. package/dist/market_adapter/inputs/window_cache.js.map +0 -1
  298. package/dist/market_adapter/interval_utils.d.ts.map +0 -1
  299. package/dist/market_adapter/interval_utils.js.map +0 -1
  300. package/dist/market_adapter/log_format.d.ts.map +0 -1
  301. package/dist/market_adapter/log_format.js.map +0 -1
  302. package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
  303. package/dist/market_adapter/lp_chart_core.js.map +0 -1
  304. package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
  305. package/dist/market_adapter/lp_chart_runner.js.map +0 -1
  306. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
  307. package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
  308. package/dist/market_adapter/market_adapter.d.ts.map +0 -1
  309. package/dist/market_adapter/market_adapter.js.map +0 -1
  310. package/dist/market_adapter/test_helpers.d.ts.map +0 -1
  311. package/dist/market_adapter/test_helpers.js.map +0 -1
  312. package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
  313. package/dist/market_adapter/utils/adapter_client.js.map +0 -1
  314. package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
  315. package/dist/market_adapter/utils/atomic_write.js.map +0 -1
  316. package/dist/market_adapter/utils/chain.d.ts.map +0 -1
  317. package/dist/market_adapter/utils/chain.js.map +0 -1
  318. package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
  319. package/dist/market_adapter/utils/data_discovery.js.map +0 -1
  320. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
  321. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
  322. package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
  323. package/dist/market_adapter/utils/file_lock.js.map +0 -1
  324. package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
  325. package/dist/market_adapter/utils/native_history.js.map +0 -1
  326. package/dist/modules/account_bots.d.ts.map +0 -1
  327. package/dist/modules/account_bots.js.map +0 -1
  328. package/dist/modules/account_orders.d.ts.map +0 -1
  329. package/dist/modules/account_orders.js.map +0 -1
  330. package/dist/modules/authority_resolver.d.ts.map +0 -1
  331. package/dist/modules/authority_resolver.js.map +0 -1
  332. package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
  333. package/dist/modules/bitshares-native/chain_client.js.map +0 -1
  334. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
  335. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
  336. package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
  337. package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
  338. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
  339. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
  340. package/dist/modules/bitshares-native/index.d.ts.map +0 -1
  341. package/dist/modules/bitshares-native/index.js.map +0 -1
  342. package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
  343. package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
  344. package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
  345. package/dist/modules/bitshares-native/resolvers.js.map +0 -1
  346. package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
  347. package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
  348. package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
  349. package/dist/modules/bitshares-native/serial/index.js.map +0 -1
  350. package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
  351. package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
  352. package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
  353. package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
  354. package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
  355. package/dist/modules/bitshares-native/serial/types.js.map +0 -1
  356. package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
  357. package/dist/modules/bitshares-native/signing_client.js.map +0 -1
  358. package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
  359. package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
  360. package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
  361. package/dist/modules/bitshares-native/transport.js.map +0 -1
  362. package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
  363. package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
  364. package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
  365. package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
  366. package/dist/modules/bitshares_client.d.ts.map +0 -1
  367. package/dist/modules/bitshares_client.js.map +0 -1
  368. package/dist/modules/bot_defaults.d.ts.map +0 -1
  369. package/dist/modules/bot_defaults.js.map +0 -1
  370. package/dist/modules/bot_settings.d.ts.map +0 -1
  371. package/dist/modules/bot_settings.js.map +0 -1
  372. package/dist/modules/bots_file_lock.d.ts.map +0 -1
  373. package/dist/modules/bots_file_lock.js.map +0 -1
  374. package/dist/modules/broadcast_failure.d.ts.map +0 -1
  375. package/dist/modules/broadcast_failure.js.map +0 -1
  376. package/dist/modules/chain_keys.d.ts.map +0 -1
  377. package/dist/modules/chain_keys.js.map +0 -1
  378. package/dist/modules/chain_orders.d.ts.map +0 -1
  379. package/dist/modules/chain_orders.js.map +0 -1
  380. package/dist/modules/cli_colors.d.ts.map +0 -1
  381. package/dist/modules/cli_colors.js.map +0 -1
  382. package/dist/modules/cli_start_onboarding.d.ts.map +0 -1
  383. package/dist/modules/cli_start_onboarding.js.map +0 -1
  384. package/dist/modules/cli_start_output.d.ts.map +0 -1
  385. package/dist/modules/cli_start_output.js.map +0 -1
  386. package/dist/modules/config.d.ts.map +0 -1
  387. package/dist/modules/config.js.map +0 -1
  388. package/dist/modules/constants.d.ts.map +0 -1
  389. package/dist/modules/constants.js.map +0 -1
  390. package/dist/modules/cr_planner.d.ts.map +0 -1
  391. package/dist/modules/cr_planner.js.map +0 -1
  392. package/dist/modules/credential_policy.d.ts.map +0 -1
  393. package/dist/modules/credential_policy.js.map +0 -1
  394. package/dist/modules/credential_runtime.d.ts.map +0 -1
  395. package/dist/modules/credential_runtime.js.map +0 -1
  396. package/dist/modules/credential_session_cache.d.ts.map +0 -1
  397. package/dist/modules/credential_session_cache.js.map +0 -1
  398. package/dist/modules/credit_pricing.d.ts.map +0 -1
  399. package/dist/modules/credit_pricing.js.map +0 -1
  400. package/dist/modules/credit_runtime.d.ts.map +0 -1
  401. package/dist/modules/credit_runtime.js.map +0 -1
  402. package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
  403. package/dist/modules/crypto/browser_provider.js.map +0 -1
  404. package/dist/modules/crypto/index.d.ts.map +0 -1
  405. package/dist/modules/crypto/index.js.map +0 -1
  406. package/dist/modules/crypto/node_provider.d.ts.map +0 -1
  407. package/dist/modules/crypto/node_provider.js.map +0 -1
  408. package/dist/modules/crypto/provider.d.ts.map +0 -1
  409. package/dist/modules/crypto/provider.js.map +0 -1
  410. package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
  411. package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
  412. package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
  413. package/dist/modules/crypto/pure_scrypt.js.map +0 -1
  414. package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
  415. package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
  416. package/dist/modules/crypto/sync.d.ts.map +0 -1
  417. package/dist/modules/crypto/sync.js.map +0 -1
  418. package/dist/modules/daemon_node_health.d.ts.map +0 -1
  419. package/dist/modules/daemon_node_health.js.map +0 -1
  420. package/dist/modules/dexbot_class.d.ts.map +0 -1
  421. package/dist/modules/dexbot_class.js.map +0 -1
  422. package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
  423. package/dist/modules/dexbot_cow_runtime.js.map +0 -1
  424. package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
  425. package/dist/modules/dexbot_credential_client.js.map +0 -1
  426. package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
  427. package/dist/modules/dexbot_fill_runtime.js.map +0 -1
  428. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
  429. package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
  430. package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
  431. package/dist/modules/dexbot_startup_runtime.js.map +0 -1
  432. package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
  433. package/dist/modules/dexbot_state_recovery.js.map +0 -1
  434. package/dist/modules/env.d.ts.map +0 -1
  435. package/dist/modules/env.js.map +0 -1
  436. package/dist/modules/fund_registry.d.ts.map +0 -1
  437. package/dist/modules/fund_registry.js.map +0 -1
  438. package/dist/modules/general_settings.d.ts.map +0 -1
  439. package/dist/modules/general_settings.js.map +0 -1
  440. package/dist/modules/graceful_shutdown.d.ts.map +0 -1
  441. package/dist/modules/graceful_shutdown.js.map +0 -1
  442. package/dist/modules/grid_price_source.d.ts.map +0 -1
  443. package/dist/modules/grid_price_source.js.map +0 -1
  444. package/dist/modules/key_store.d.ts.map +0 -1
  445. package/dist/modules/key_store.js.map +0 -1
  446. package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
  447. package/dist/modules/launcher/adapter_requirement.js.map +0 -1
  448. package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
  449. package/dist/modules/launcher/bot_supervisor.js.map +0 -1
  450. package/dist/modules/launcher/child_env.d.ts.map +0 -1
  451. package/dist/modules/launcher/child_env.js.map +0 -1
  452. package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
  453. package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
  454. package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
  455. package/dist/modules/launcher/credential_daemon.js.map +0 -1
  456. package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
  457. package/dist/modules/launcher/credential_secret.js.map +0 -1
  458. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
  459. package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
  460. package/dist/modules/launcher/headless_password.d.ts.map +0 -1
  461. package/dist/modules/launcher/headless_password.js.map +0 -1
  462. package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
  463. package/dist/modules/launcher/launch_modes.js.map +0 -1
  464. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
  465. package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
  466. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
  467. package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
  468. package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
  469. package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
  470. package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
  471. package/dist/modules/launcher/runtime_entry.js.map +0 -1
  472. package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
  473. package/dist/modules/launcher/status_reporting.js.map +0 -1
  474. package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
  475. package/dist/modules/launcher/supervisor_control.js.map +0 -1
  476. package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
  477. package/dist/modules/market_adapter_whitelist.js.map +0 -1
  478. package/dist/modules/node_connect_policy.d.ts.map +0 -1
  479. package/dist/modules/node_connect_policy.js.map +0 -1
  480. package/dist/modules/node_failure_ledger.d.ts.map +0 -1
  481. package/dist/modules/node_failure_ledger.js.map +0 -1
  482. package/dist/modules/node_health_cache.d.ts.map +0 -1
  483. package/dist/modules/node_health_cache.js.map +0 -1
  484. package/dist/modules/node_manager.d.ts.map +0 -1
  485. package/dist/modules/node_manager.js.map +0 -1
  486. package/dist/modules/order/accounting.d.ts.map +0 -1
  487. package/dist/modules/order/accounting.js.map +0 -1
  488. package/dist/modules/order/async_lock.d.ts.map +0 -1
  489. package/dist/modules/order/async_lock.js.map +0 -1
  490. package/dist/modules/order/export.d.ts.map +0 -1
  491. package/dist/modules/order/export.js.map +0 -1
  492. package/dist/modules/order/format.d.ts.map +0 -1
  493. package/dist/modules/order/format.js.map +0 -1
  494. package/dist/modules/order/grid.d.ts.map +0 -1
  495. package/dist/modules/order/grid.js.map +0 -1
  496. package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
  497. package/dist/modules/order/grid_reconcile.js.map +0 -1
  498. package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
  499. package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
  500. package/dist/modules/order/index.d.ts.map +0 -1
  501. package/dist/modules/order/index.js.map +0 -1
  502. package/dist/modules/order/logger.d.ts.map +0 -1
  503. package/dist/modules/order/logger.js.map +0 -1
  504. package/dist/modules/order/logger_state.d.ts.map +0 -1
  505. package/dist/modules/order/logger_state.js.map +0 -1
  506. package/dist/modules/order/manager.d.ts.map +0 -1
  507. package/dist/modules/order/manager.js.map +0 -1
  508. package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
  509. package/dist/modules/order/processed_fill_store.js.map +0 -1
  510. package/dist/modules/order/strategy.d.ts.map +0 -1
  511. package/dist/modules/order/strategy.js.map +0 -1
  512. package/dist/modules/order/sync_engine.d.ts.map +0 -1
  513. package/dist/modules/order/sync_engine.js.map +0 -1
  514. package/dist/modules/order/utils/math.d.ts.map +0 -1
  515. package/dist/modules/order/utils/math.js.map +0 -1
  516. package/dist/modules/order/utils/order.d.ts.map +0 -1
  517. package/dist/modules/order/utils/order.js.map +0 -1
  518. package/dist/modules/order/utils/slot.d.ts.map +0 -1
  519. package/dist/modules/order/utils/slot.js.map +0 -1
  520. package/dist/modules/order/utils/system.d.ts.map +0 -1
  521. package/dist/modules/order/utils/system.js.map +0 -1
  522. package/dist/modules/order/utils/timeout.d.ts.map +0 -1
  523. package/dist/modules/order/utils/timeout.js.map +0 -1
  524. package/dist/modules/order/utils/validate.d.ts.map +0 -1
  525. package/dist/modules/order/utils/validate.js.map +0 -1
  526. package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
  527. package/dist/modules/order/utils/withPoolRef.js.map +0 -1
  528. package/dist/modules/order/working_grid.d.ts.map +0 -1
  529. package/dist/modules/order/working_grid.js.map +0 -1
  530. package/dist/modules/path_api.d.ts.map +0 -1
  531. package/dist/modules/path_api.js.map +0 -1
  532. package/dist/modules/paths.d.ts.map +0 -1
  533. package/dist/modules/paths.js.map +0 -1
  534. package/dist/modules/process_discovery.d.ts.map +0 -1
  535. package/dist/modules/process_discovery.js.map +0 -1
  536. package/dist/modules/runtime.d.ts.map +0 -1
  537. package/dist/modules/runtime.js.map +0 -1
  538. package/dist/modules/runtime_settings.d.ts.map +0 -1
  539. package/dist/modules/runtime_settings.js.map +0 -1
  540. package/dist/modules/settings_merge.d.ts.map +0 -1
  541. package/dist/modules/settings_merge.js.map +0 -1
  542. package/dist/modules/socket_json_client.d.ts.map +0 -1
  543. package/dist/modules/socket_json_client.js.map +0 -1
  544. package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
  545. package/dist/modules/storage/browser_adapter.js.map +0 -1
  546. package/dist/modules/storage/index.d.ts.map +0 -1
  547. package/dist/modules/storage/index.js.map +0 -1
  548. package/dist/modules/storage/node_adapter.d.ts.map +0 -1
  549. package/dist/modules/storage/node_adapter.js.map +0 -1
  550. package/dist/modules/storage/types.d.ts.map +0 -1
  551. package/dist/modules/storage/types.js.map +0 -1
  552. package/dist/modules/types.d.ts.map +0 -1
  553. package/dist/modules/types.js.map +0 -1
  554. package/dist/modules/utils/base58check.d.ts.map +0 -1
  555. package/dist/modules/utils/base58check.js.map +0 -1
  556. package/dist/modules/utils/build_dir.d.ts.map +0 -1
  557. package/dist/modules/utils/build_dir.js.map +0 -1
  558. package/dist/modules/utils/chain_logs.d.ts.map +0 -1
  559. package/dist/modules/utils/chain_logs.js.map +0 -1
  560. package/dist/modules/utils/errors.d.ts.map +0 -1
  561. package/dist/modules/utils/errors.js.map +0 -1
  562. package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
  563. package/dist/modules/utils/sanitize_key.js.map +0 -1
  564. package/dist/modules/utils/text_width.d.ts.map +0 -1
  565. package/dist/modules/utils/text_width.js.map +0 -1
  566. package/dist/modules/validate_profiles.d.ts.map +0 -1
  567. package/dist/modules/validate_profiles.js.map +0 -1
  568. package/dist/pm2.d.ts.map +0 -1
  569. package/dist/pm2.js.map +0 -1
  570. package/dist/scripts/analyze-credit.d.ts.map +0 -1
  571. package/dist/scripts/analyze-credit.js.map +0 -1
  572. package/dist/scripts/analyze-git.d.ts.map +0 -1
  573. package/dist/scripts/analyze-git.js.map +0 -1
  574. package/dist/scripts/analyze-orders.d.ts.map +0 -1
  575. package/dist/scripts/analyze-orders.js.map +0 -1
  576. package/dist/scripts/chart_command.d.ts.map +0 -1
  577. package/dist/scripts/chart_command.js.map +0 -1
  578. package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
  579. package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
  580. package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
  581. package/dist/scripts/diagnose-pool-history.js.map +0 -1
  582. package/dist/scripts/divergence-calc.d.ts.map +0 -1
  583. package/dist/scripts/divergence-calc.js.map +0 -1
  584. package/dist/scripts/dw.d.ts.map +0 -1
  585. package/dist/scripts/dw.js.map +0 -1
  586. package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
  587. package/dist/scripts/generate_lp_chart.js.map +0 -1
  588. package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
  589. package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
  590. package/dist/scripts/native_release_gates.d.ts.map +0 -1
  591. package/dist/scripts/native_release_gates.js.map +0 -1
  592. package/dist/scripts/print_grid.d.ts.map +0 -1
  593. package/dist/scripts/print_grid.js.map +0 -1
  594. package/dist/scripts/run-tests.d.ts.map +0 -1
  595. package/dist/scripts/run-tests.js.map +0 -1
  596. package/dist/scripts/runner.d.ts.map +0 -1
  597. package/dist/scripts/runner.js.map +0 -1
  598. package/dist/scripts/sync-version.d.ts.map +0 -1
  599. package/dist/scripts/sync-version.js.map +0 -1
  600. package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
  601. package/dist/scripts/test-credit-renewal.js.map +0 -1
  602. package/dist/scripts/tv.d.ts.map +0 -1
  603. package/dist/scripts/tv.js.map +0 -1
  604. package/dist/scripts/update.d.ts.map +0 -1
  605. package/dist/scripts/update.js.map +0 -1
  606. package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
  607. package/dist/scripts/update_dist_freshness.js.map +0 -1
  608. package/dist/scripts/validate_bots.d.ts.map +0 -1
  609. package/dist/scripts/validate_bots.js.map +0 -1
  610. package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
  611. package/dist/scripts/verify-browser-bundle.js.map +0 -1
  612. package/dist/unlock.d.ts.map +0 -1
  613. 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;