5.3 KiB
Real Bars vs Fake Bars Trend Analyzer (Streamlit)
A Python web app that implements the Real Bars vs Fake Bars strategy:
- Classifies each closed bar against the prior bar as
real_bull,real_bear, orfake - Ignores fake bars for trend sequence logic
- Starts/continues trend on 2+ same-direction real bars
- Reverses trend only after 2 consecutive real bars of the opposite direction
Features
- Symbol/timeframe/period inputs (Yahoo Finance via
yfinance) - Optional wick filtering (use previous candle body range)
- Optional volume filter (minimum Volume vs Volume-SMA)
- Trend events table (starts and reversals)
- Chart visualization (candles + real-bar markers + trend-colored volume)
- Market session gap handling for stocks via
Hide market-closed gaps (stocks):1d: removes weekend spacing- intraday: removes weekends and closed-hour overnight spans
- Session alerts for newly detected trend events
- Export classified data to CSV
- Export chart to PDF (via Plotly + Kaleido)
- Lightweight backtest snapshot (signal at trend changes, scored by next-bar direction)
Project Structure
app.py: Streamlit entrypoint and UI orchestrationmanesh_trader/constants.py: intervals, periods, trend labelsmanesh_trader/models.py: data models (TrendEvent)manesh_trader/data.py: market data fetch and live-bar safeguardmanesh_trader/strategy.py: bar classification and trend detection logicmanesh_trader/analytics.py: backtest snapshot metricsmanesh_trader/charting.py: Plotly chart constructionmanesh_trader/exporting.py: export DataFrame transformationrequirements.txt: dependencies
Onboarding
See ONBOARDING.md for a complete step-by-step tutorial.
Xcode macOS Shell
An Xcode-based desktop shell lives in ManeshTraderMac/.
It provides a native window that starts/stops an embedded local backend executable and renders the UI in WKWebView (no external browser).
Backend source of truth stays at project root (app.py, manesh_trader/), and packaging compiles those files into ManeshTraderBackend inside the app bundle.
See ManeshTraderMac/README.md for setup and run steps.
Setup
Easiest (one command)
./run.sh
macOS Double-Click Launcher
Double-click Run ManeshTrader.command in Finder.
If macOS blocks first launch, run once in Terminal:
xattr -d com.apple.quarantine "Run ManeshTrader.command"
macOS App Wrapper (.app)
Build a native .app launcher:
./scripts/create_mac_app.sh
This creates ManeshTrader.app in the project root. You can double-click it or move it to /Applications.
Build a distributable installer DMG:
./scripts/create_installer_dmg.sh
Output: ManeshTrader-YYYYMMDD-HHMMSS.dmg in project root.
Self-Contained macOS App (WKWebView + Embedded Backend)
Build an installable app where all backend logic ships inside ManeshTraderMac.app:
./scripts/build_selfcontained_mac_app.sh
This outputs dist-mac/<timestamp>/ManeshTraderMac.app.
Then package that app as DMG:
APP_BUNDLE_PATH="dist-mac/<timestamp>/ManeshTraderMac.app" ./scripts/create_installer_dmg.sh
Note: for easiest install on other Macs, use Apple code signing + notarization before sharing publicly.
Standalone Streamlit App (Alternative)
This older path builds a standalone Streamlit wrapper app:
./scripts/build_standalone_app.sh
Output: dist-standalone/<timestamp>/dist/ManeshTrader.app
Optional with Make
make run
make build-mac-selfcontained
Manual
- Create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Run the app:
streamlit run app.py
- Open the local URL printed by Streamlit (usually
http://localhost:8501).
Usage
- Set
Symbol(examples:AAPL,MSFT,BTC-USD,ETH-USD). - Choose
TimeframeandPeriod. - Optionally adjust filters:
Use previous body range (ignore wicks)Enable volume filterHide market-closed gaps (stocks)
- Review:
- Current trend status
- Real/fake bar counts
- Trend events and chart markers
- Export results from the Export section.
Strategy Logic Implemented
For closed bar i and previous closed bar i-1:
- Real Bullish Bar:
close[i] > high[i-1](or previous body high if wick filter enabled) - Real Bearish Bar:
close[i] < low[i-1](or previous body low if wick filter enabled) - Fake Bar: otherwise (inclusive range)
Trend state machine:
- Two consecutive real bullish bars => bullish trend active
- Two consecutive real bearish bars => bearish trend active
- Active trend persists until two consecutive real bars in opposite direction
- Single opposite real bar is treated as noise/fluke and does not reverse trend
Notes
- The app is analysis-only; no order execution.
- Yahoo Finance interval availability depends on symbol and lookback window.
- "Ignore potentially live last bar" is enabled by default to reduce incomplete-bar bias.
- Gap-hiding behavior is currently optimized for regular U.S. stock sessions; exchange holidays/half-days may still show occasional spacing.
Troubleshooting
- If data fetch fails, verify symbol spelling and use a compatible interval/period combination.
- If PDF export is unavailable, ensure
kaleidois installed in the same environment.