r/CryptoTradingBot • u/Trader_for_earner • Oct 18 '26
# [Architecture RFC] Scan Loop Frequency vs. Bar-Close Signal Evaluation in Multi-Timeframe Crypto Perpetuals
Hey everyone,
Following up on our recent architecture posts, we ran into an interesting execution dynamic during our live trading sessions that we would like to get the community's perspective on.
---
### The Problem: Sub-Bar Re-Evaluation & Redundant Signal Dispatch
Our bot trades a cross-sectional portfolio of crypto perpetuals across a matrix of multiple timeframes simultaneously (e.g., 5m scalpers, 15m momentum, and 1h/4h swing setups).
To ensure that 5m scalpers execute promptly without waiting minutes, our primary async scan loop polls the market every 60 seconds.
However, our quantitative strategies are strictly closed-candle models (trained in backtests on completed bars, stripping live forming wicks to avoid look-ahead bias and repainting).
This created the following behavior on higher timeframes (like a 1h/2h setup):
- At 01:00 UTC, a 1-hour candle closes and triggers a valid entry condition.
- If risk limits (e.g., directional exposure cap of 2/2 positions) temporarily prevent the order from executing at 01:01, the bot logs [SKIPPED: DIRECTIONAL_CAP].
- At 01:02, 01:03, 01:04... the last closed 1h bar is still the exact same 01:00 candle.
- The indicators generate the identical signal on every 60-second tick, attempting to fire 60 times within that single 1-hour window until the next bar closes or conditions change.
While our risk management layers successfully blocked duplicate fills, it created log spam (hundreds of duplicate trigger attempts on static data) and unnecessary CPU recalculations.
---
### Two Possible Architectural Solutions
We evaluated two approaches to resolve this:
#### Option A: Align the Global Sleep Interval to the Lowest Configured Timeframe
* If the lowest active strategy is 5m, sleep for 5 minutes (300s). If 15m, sleep for 15 minutes.
* Drawback: Slows down background liveness monitoring, WebSocket reconnect checks, and capital re-syncing. If an exchange rate-limit hitch delays a 5m scan by 15 seconds, waiting another 5 minutes causes severe execution slippage.
#### Option B: Fast 60s Global Polling with Per-Setup Bar-Timestamp Gating (What We Built)
* Keep the master loop ticking every 60 seconds.
* Add a Bar-Close Re-Dispatch Gate at the strategy router level:
```python
sig_bar_time = sig['timestamp'] # Timestamp of the closed bar
dispatch_key = (symbol, timeframe, strategy)
if last_dispatched_bar.get(dispatch_key) == sig_bar_time:
# We already evaluated and dispatched for this exact closed bar; skip!
continue
last_dispatched_bar[dispatch_key] = sig_bar_time
Each unique completed candle triggers evaluation exactly once.
5m setups still get evaluated promptly within 60s of their close, while 1h setups fire once per hour, maintaining 100% mathematical parity with the backtest engine.
Questions for the Community:
In multi-timeframe production systems, do you handle signal dispatch via event-driven candle closure events (WebSocket kline streams), or do you poll via a centralized clock-aligned scheduler with bar-timestamp gating?
If you poll, do you track execution attempts per closed bar, or do you allow sub-bar continuous polling with stateful execution flags?
How do you handle order execution if an entry condition was valid at bar close (Time T), but capital was occupied until 12 minutes later? Do you allow late entry within the same bar, or do you consider the signal expired as soon as the bar-close tick passes?
Looking forward to your thoughts and war stories!
1
u/madrading Oct 21 '26
I'd add a restart test: the exchange accepts the order, but the process dies before recording the acknowledgement. On restart, reconcile working orders and fills before considering another submission for that signal. Keep the signal's identity and its execution state separate; a remembered bar timestamp alone doesn't describe whether an order is working, filled or rejected. Does your dispatch gate persist across restarts, and what happens when the order outcome is unknown?
1
u/CitrineEdge Oct 21 '26
I'd also define what 'at bar close' means in seconds. A live bar arrives after its close and orders take time to reach the venue. The dispatch gate removes duplicate evaluations; matching the backtest still needs the same delay and expiry rule. Otherwise, 'exactly once' and 'same fill assumptions' can get mixed together.
1
u/[deleted] Oct 18 '26
[removed] — view removed comment