Select Page

Buy the dip.

The practice is deceptively simple.

In theory, you simply buy when prices retrace the predominant trend and wait for reinstitution of the trend.

In practice, it’s rarely that simple.

It can be difficult to distinguish a retracement (dip) from a reversal in real-time, and accurately project dip’s end-point.

What to Do?

In this article, we’re going to backtest a “buy the dip” script using retracement percentages.

As I mentioned in this article, I still believe using the retracement tool complements a discretionary system better than a mechanical system.

Adequate scripts/indicators can be written using the Pivot Highs and Pivot Lows indicator, or something similar; however, the indicator struggles when a trend persists and sessions begin to fall out of the lookback period.

When this occurs, the lowest low within the lookback period is accounted for as opposed to the starting price of the current leg-up/leg-down.

This sequence can be difficult for a mechanical system with precisely defined rules, while a discretionary system doesn’t suffer.

To be fair, we shouldn’t try to “call the bottom” of a dip. We should require precise conditions to be satisfied and “buy the dip” after prices move a specified percentage against the trend while the conditions are satisfied.

A mechanical retracement buying/selling strategy can work fine when applied within its scope.

Let’s backtest one!

Backtesting a Sample Retracement Buying/Selling System

Our sample system backtest will account for the highest high and lowest low over the previous 25 sessions. For long entry, when prices retrace 50% from the highest high over 25 sessions, relative to the lowest low; a position will be entered. Prices must close above the 200-day SMA, and the 50-day SMA must trend above the 200-day SMA for a long position to execute. 

For a bearish retracement, the highest high is subtracted from the lowest low and the result is multiplied by .50. The highest high is then added to the result.

((lowest low of n sessions – highest high of n sessions) * R%) + highest high of n sessions


Lowest low = lowest price over previous n sessions (25 for our backtest)

Highest high = highest price over previous n sessions (25 for our backtest)

R% = retracement percentage we want to buy/sell at

For example, if the highest high is 105 and the lowest low 100, the system executes the following calculation.

100 – 105 = -5

-5 * . 33 = -1.65

-1.65 + 105 = 103.35

-5* .50 = -2.5

-2.5 + 105 = 102.5

-5 * .66 = -3.3

-3.3 + 105 = 101.7

Therefore, a 33% retracement from the highest high, relative to the lowest low, is $103.35, a 50% retracement is $102.5, and a 66% retracement is $101.7.

The final calculation for a 33% retracement looks like this,

((100 – 105) * .33) + 105 = 103.35

A bullish retracement is calculated a bit differently.

((highest high of n sessions – lowest low of n sessions) * R%) + lowest low of n sessions

For example, say the highest high is 105 and the lowest low 100

((105 – 100) * .33) + 100 = $101.65

With this formula, a 50% bullish retracement would be $102.50, and a 66% bullish retracement would be 103.30.

Those of you looking to implement a discretionary system don’t need to worry about the formula. In simple terms, the formula is just telling the computer how to calculate retracement percentages.

There’s one more condition we’re adding to entry criteria.


1 – (lowest low) / (highest high)


Lowest low = lowest price over previous n sessions (25 for our backtest)

Highest high = highest price over previous n sessions (25 for our backtest)

Entry criteria (Long Position)

  1. Close > 200 day SMA

The close price is greater than the 200-day SMA.

2. 50-day SMA > 200-day SMA

The 50-day SMA is trending above the 200-day SMA.

3. The $VIX high price for the session < 30

The $VIX high price for the session is less than 30.


  1. 1 – (lowest low) / (highest high) >= 0.03

There is at least a 3% spread between the lowest low over 25 sessions and highest high over 25 sessions. This condition increases the chance of entry during a trend retracement and not a sideways market. We could require a larger spread between the lowest low and highest high; our 3% spread condition is likely ineffective for securities that experience strong price moves consistently.

When these conditions are satisfied, a long signal is generated when,

3. Low price of a session crosses under the 50% retracement level

((lowest low of n sessions – highest high of n sessions) * .50) + highest high of n sessions – when prices retrace 50% from the highest high a long position will be opened.

Exit Criteria (From Long Position)

  1. A 10% profit is achieved


2. Prices move 5% against our position


If prices move 5% against our position, the backtest will look to close the position when close > high[1] (the close price of a session is greater than the high price of the session preceding it).

We don’t immediately close for a loss if prices move 5% against us. Instead, we look to exit when the close price of a session is greater than the high price of the session before it. This will help to mitigate losses for losing position.

Figure 1.1 Buy the Dip Backtest

Buy the Dip Backtest

Figure 1.2 Buy the Dip Backtest

Buy the Dip Backtest

Figure 1.3 Buy the Dip Backtest

Buy the Dip Backtest

Figure 1.4 Buy the Dip Backtest

Buy the Dip Backtest

Figure 1.5 Buy the Dip Backtest

Figure 1.6 Buy the Dip Backtest

The strategy certainly isn’t perfect; we’d like to observe more trades before making a statistical inference on viability.

We decrease the lookback period to increase the number of trades executed. For instance, we could implement a 10 session lookback period, and enter long when prices retrace 50% from the highest, relative to lowest low, and only when the highest high of the previous 10 sessions is greater than the highest high of the last block.

Additionally, we could use an RSI SMA to distinguish trending markets from flat markets, and only enter long when the RSI SMA is greater than, or equal to, a specified measurement during the 50% retracement.

You can modify the strategy/code and certainly build something viable.

Figure 1.7 Buy the Dip Modified Backtest

A screenshot of a computer

Description automatically generated with medium confidence

Figure 1.6 shows performance test results when applying a 100 session lookback period.

Important Notes

Our strategy looks to buy bearish retracements.

The 50 and 200 SMA conditions attempt to filter flat/descending markets.

We might not know for certain if the “dip” will transition to a reversal; however, our stop-loss criteria will protect us should adverse circumstances materialize.

The Truth About Retracement Percentages

Buying/selling at retracement levels is an adequate strategy. However, we shouldn’t implement the method trying to time the next swing of the predominant trend. There are times when prices retrace within the 33-66% range and immediately continue trending thereafter. Despite this, it’s difficult to project the exact retracement percentage prices will retrace before continuing the trend, and prices might fluctuate within the retracement range for longer than anticipated.

Buying/selling within the retracement range is an optimal approach for lower-risk entry points when momentum trading i.e., holding for a few weeks or longer. Swing-traders and day-traders can benefit from trading the range, but if prices hover within the range and don’t extend the predominant trend shortly after – the position might be held longer than expected.

There might be securities which commonly retrace 66% before trend continuation, but the retracement itself isn’t necessarily reflective of the trend exhausting. Backtesting alleviates these headaches. If you aren’t backtesting, it’s best to start with a hard level and consistently apply it. Before doing so you should manually backtest your strategy on the security you wish to trade. If your strategy consists of buying a 66% retracement, but prices for the security are retracing 50% at most, you should manually backtest the stock while hypothetically buying at 50%, with supplementary conditional requirements, and record the results. You must ascertain whether your system has a positive expected outcome before using it.

You can use the “Bar Replay” feature on TradingView (free account) for manual backtesting. The feature omits a specified number of sessions. After clicking “play” the sessions will generate or “playback” and you can hypothetically trade them.

Try to objectify your trading!

Join our Discord server! We will help you build a mechanical trading system and backtest it! We will send you the code; you can backtest the system on ANY stock at ANY time!

The servers getting a bit large.

Make sure to join before we are forced to close off access for a bit!

Courses Archive – Kioseff Trading

Check out our Youtube Channel for trading systems with code access! (You can backtest the systems at any time AND set alerts)

Kioseff Trading – YouTube

Follow our twitter!

Kioseff Trading (@KioseffTrading) / Twitter

-Kioseff Trading

Legal Disclaimer: The information contained in the article is not intended as, and shall not be understood or construed as, financial advice. The author is  not an attorney, accountant, or financial advisor, nor are they holding themselves out to be, and the information contained in this article is not a substitute for a professional who is aware of the circumstances and facts of your personal financial situation. 

The author does not have a position for the discussed securities and does not plan to open a position for the discussed securities. 

Losses can exceed investment. Any stock mentioned throughout the article does not constitute advice or a recommendation. Any losses incurred that are due to error, accident, malfunction, or any loss due to any reason is not the legal responsibility or fault of the author. 

The article reflects an expressed opinion from the author. 

© Kioseff Trading. All rights reserved. No portion of this article, or any content on the website, may be redistributed or passed as one’s own without express permission from the author