OPEN-SOURCE SCRIPT
Modular Trend Pullback Strategy

This strategy focuses on trading pullbacks within established trends. Instead of entering immediately when a trend forms, it waits for a temporary retracement and then looks for confirmation before placing a trade. The goal is to improve entry timing while keeping risk controlled.
Core Idea
Markets often move in waves. During a strong trend, price tends to retrace toward a short-term average before continuing in the dominant direction. This script attempts to participate in those continuation moves.
How It Works
1. Trend Identification
Two exponential moving averages (EMAs) define direction.
2. Pullback Condition
This avoids chasing extended moves.
3. Break Confirmation
After a pullback, the strategy waits for price to break the previous candle’s high (for longs) or low (for shorts).
This acts as confirmation that momentum is returning in the direction of the trend.
4. Risk Management
Stop-loss and take-profit levels are based on ATR (Average True Range), allowing exits to adapt to current volatility.
A configurable risk-reward ratio defines profit targets.
Key Features
Suitable Market Conditions
This type of approach generally performs best in:
It may underperform in sideways or low-volatility markets.
Notes
This script is intended for research and testing purposes. Results will vary depending on symbol, timeframe, and market regime. Always evaluate performance across multiple market conditions before considering live execution.
Core Idea
Markets often move in waves. During a strong trend, price tends to retrace toward a short-term average before continuing in the dominant direction. This script attempts to participate in those continuation moves.
How It Works
1. Trend Identification
Two exponential moving averages (EMAs) define direction.
- Fast EMA above Slow EMA → bullish environment
- Fast EMA below Slow EMA → bearish environment
2. Pullback Condition
- In an uptrend, price must retrace below the fast EMA.
- In a downtrend, price must retrace above the fast EMA.
This avoids chasing extended moves.
3. Break Confirmation
After a pullback, the strategy waits for price to break the previous candle’s high (for longs) or low (for shorts).
This acts as confirmation that momentum is returning in the direction of the trend.
4. Risk Management
Stop-loss and take-profit levels are based on ATR (Average True Range), allowing exits to adapt to current volatility.
A configurable risk-reward ratio defines profit targets.
Key Features
- Non-repainting logic
- Entries only when flat (no stacking positions)
- ATR-based dynamic stop and target levels
- Commission and slippage included for more realistic backtests
- Structured, modular logic for easier testing and adjustment
Suitable Market Conditions
This type of approach generally performs best in:
- Trending environments
- Instruments with sustained directional movement
- Timeframes where pullbacks are clearly visible
It may underperform in sideways or low-volatility markets.
Notes
This script is intended for research and testing purposes. Results will vary depending on symbol, timeframe, and market regime. Always evaluate performance across multiple market conditions before considering live execution.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.