OPEN-SOURCE SCRIPT

Trend Pullback Re-Entry Strategy [Jayadev Rana]

810
OVERVIEW

Trend Pullback Re-Entry Strategy is a trend-following strategy that does not buy strength. It waits for an established trend, waits for a counter-trend dip inside it, and enters only when price shows that the dip is over. The aim is to join a trend at a better price than a breakout entry would give, with a stop that sits just beyond the pullback itself.

HOW IT WORKS

The logic has three stages that must occur in order.

1. Trend regime. An uptrend requires the fast EMA above the slow EMA and the slow EMA higher than it was a set number of bars ago. A downtrend is the mirror image. When neither is true the strategy does nothing.

2. Pullback. A short-length RSI measures the depth of the counter-trend move. In an uptrend the RSI must fall to the Pullback Depth level or lower; in a downtrend it must rise to 100 minus that level or higher. This registers a pullback and starts a short countdown.

3. Trigger. Within the Trigger Window, a bar must close above the previous bar's high (uptrend) or below the previous bar's low (downtrend). This is the evidence that the pullback has ended. If the trigger does not arrive within the window, the setup expires.

Orders are placed on the close of the trigger bar and fill on the next bar open.

EXITS

- Initial stop: beyond the lowest low (for longs) or highest high (for shorts) of the pullback window, plus an ATR buffer.
- Trailing stop: once in a trade, the stop trails each new close by an ATR multiple and never moves against the trade. There is no fixed profit target; the trade stays open until the stop is reached.

POSITION SIZING

Quantity is set so that a stop-out at the initial stop loses the chosen percentage of current equity. Because the initial stop is tied to the pullback extreme, shallow pullbacks produce larger positions and deep pullbacks smaller ones, with the same amount at risk. Position notional is capped by the Maximum Leverage input.

STRATEGY PROPERTIES USED

Initial capital 10,000. Commission 0.05 percent per order. Slippage 2 ticks. No pyramiding. Margin 100 percent on both sides, maximum leverage 1. Risk per trade 0.5 percent of equity. Signals are evaluated on closed bars; calculations do not use intrabar data or higher-timeframe requests.

DEFAULT SETTINGS

The default values were chosen with a parameter search on BTCUSDT on the 1-hour timeframe using the properties above. The history was split into an earlier and a later segment and only settings that were acceptable in both segments were considered. Other symbols and timeframes will usually need different values. A parameter search always carries a risk of fitting to the tested history, so results on the tested market are likely to look better than results on new data.

DASHBOARD

Current regime, whether a pullback is armed and waiting for its trigger, and the pullback RSI value.

LIMITATIONS

- The strategy depends on the trend continuing after the pullback. When a pullback is the start of a reversal, the trade is stopped out; this is the normal losing trade for this approach.
- The EMA regime filter reacts slowly. After a trend ends, the filter can stay in the old regime for some time and allow entries in the wrong direction.
- Very strong trends may never pull back deep enough to register, so the strategy can miss the cleanest moves entirely.
- Backtests assume fills at the next bar open with fixed slippage. Real fills, funding costs on leveraged instruments, and gaps are not modeled.
- Settings tuned on past data can stop working when market behavior changes.

This script is for analysis and education. It does not provide financial advice, and past performance does not guarantee future results.

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.