feat: add configurable SMA window for trend confirmation#13
Conversation
📝 WalkthroughWalkthroughAdds a configurable SMA window: a Streamlit sidebar selector threads ChangesConfigurable SMA Window
Trade Data Updates
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant Sidebar
participant App as app.py
participant Cached as _analyze_cached
participant Trader as analyze_symbols
participant Strategy as calculate_orb_signal
Sidebar->>App: select sma_window
App->>Cached: call with sma_window (cached, TTL 8s)
Cached->>Trader: analyze_symbols(..., sma_window)
Trader->>Strategy: calculate_orb_signal(..., sma_window)
Strategy-->>Trader: TradeSignal using SMA(sma_window)
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
strategy.py (1)
179-184: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove debug print / fix misleading unit.
print(f"SMA Window: {sma_window} minutes")is a leftover debug artifact that fires on every signal calculation for every symbol — with auto-refresh this spams stdout. Also,sma_windowis a candle/bar count, not "minutes" (unlikeorb_window), so the message is misleading.🧹 Proposed fix
def _trend_sma(data: pd.DataFrame, sma_window: int) -> float: close = data["Close"].dropna() - print(f"SMA Window: {sma_window} minutes") if close.empty: return 0.0 window = min(sma_window, len(close)) return float(close.tail(window).mean())🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@strategy.py` around lines 179 - 184, The _trend_sma function in strategy.py contains a leftover debug print that spams stdout on every signal calculation and uses the wrong unit label for sma_window. Remove the print(f"SMA Window: ...") line entirely from _trend_sma, and if any logging is needed, make it optional and describe sma_window as a bar/candle count rather than minutes. Keep the rest of the window calculation logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@strategy.py`:
- Around line 179-184: The _trend_sma function in strategy.py contains a
leftover debug print that spams stdout on every signal calculation and uses the
wrong unit label for sma_window. Remove the print(f"SMA Window: ...") line
entirely from _trend_sma, and if any logging is needed, make it optional and
describe sma_window as a bar/candle count rather than minutes. Keep the rest of
the window calculation logic unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e0b5db26-d33e-40f5-8421-e4eb31277427
⛔ Files ignored due to path filters (3)
__pycache__/strategy.cpython-314.pycis excluded by!**/*.pyc__pycache__/trader.cpython-314.pycis excluded by!**/*.pyclogs/trades.csvis excluded by!**/*.csv
📒 Files selected for processing (4)
app.pydata/trades.jsonstrategy.pytrader.py
Summary
This PR adds a configurable SMA Window setting to the Streamlit sidebar, allowing users to customize the trend confirmation period used by the ORB strategy without modifying the source code.
Previously, the SMA window was hardcoded to 5 candles.
Changes Made
UI (Streamlit)
Added a new SMA Window selector under Strategy Settings.
Available options:
The default value remains 5 to preserve existing behavior.
Analysis Pipeline
Passed the selected SMA window through the analysis flow:
Strategy Logic
Updated the SMA calculation to use the user-selected window instead of the hardcoded value.
Previous implementation:
New implementation:
Example
Default
The strategy computes the moving average using the latest 5 candles.
Custom
The strategy computes the moving average using the latest 20 candles, resulting in a slower trend filter that may change BUY/SELL/HOLD decisions.
Benefits
Testing
Verified that:
Closes #12
Summary by CodeRabbit
New Features
Performance
Data Updates