Implement RSI Pullback Trading Strategy with Backtesting Engine #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a complete Python implementation of a trend-following RSI pullback strategy for swing trading, including backtesting engine, performance analysis, and signal scanning capabilities.
Strategy Implementation
Core Modules (9 files):
indicators.py- EMA, RSI (Wilder's method), ATR, volume ratiosentry_signals.py- Multi-condition validation: trend filter (200 EMA) + RSI pullback (35-45 zone) + volume confirmation (≥80% avg)exit_signals.py- Priority-based exits: stop loss (1.5×ATR) > profit target (2R) > trend break > trailing stop > time stopposition_manager.py- Position sizing (1% portfolio risk), max 5 concurrent positions, partial exits (50% at 2R)backtest_engine.py- Day-by-day simulation with mark-to-market equity trackingperformance_analyzer.py- Metrics: win rate, profit factor, R-multiple, CAGR, Sharpe/Sortino/Calmar ratios, drawdown analysisscanner.py- Real-time signal detection across instrument universeconfig.py- All parameters configurable (RSI thresholds, ATR multipliers, risk limits, etc.)Usage
Additional Components
test_strategy.py- Unit tests for indicators, signals, position management (5 suites, all passing)data_integration.py- Integration examples: PostgreSQL, Yahoo Finance, CSV, MongoDB, Kite APImain.py- Demo with synthetic dataREADME.mdandSUMMARY.mdTotal: 2,766 LOC across 15 files
Original prompt
RSI Pullback Strategy - Detailed Pseudocode
Strategy Overview
Name: Trend + RSI Pullback with Volume Confirmation
Type: Swing Trading (3 days to 3 months)
Universe: Nifty 500 liquid stocks
Timeframe: Daily bars
1. INITIALIZATION & PARAMETERS
2. DATA LOADING & PREPROCESSING
3. INDICATOR CALCULATIONS
4. ENTRY SIGNAL DETECTION