Finding The Optimal Period

About the Author Curtis White

Curtis is a market enthusiast and programmer who enjoys predicting markets, developing trading systems, and tape reading. He offers a blog at BeyondBacktesting.com where he shares his original ideas for developing and enhancing trading systems. He is a creative,synthesis thinker who likes to combine ideas and techniques from a broad palette. One of his core goals is the creation of graybox systems, software, and decision support tools for enhancing the capabilities of high performance discretionary traders.

  • Bruce Berger says:

    Thanks for sharing this. I was wondering if you could clarify something. What are the buy/sell thresholds you used on the adaptive RSI approach? Your base case is a two-period RSI with longs taken below 30 and exits above 70. I don’t believe you explicitly said what they are. If you did, I apologize for missing it. Thanks.

  • Curtis says:

    The buy/sell thresholds are exactly the same. The adaptive approach dynamically changes the period (lookback) from 2 to 14 based 90 day lookback. To understand what the algo is doing, imagine adjusting your RSI lookback every day from 2 to 14 with the goal of finding the one that is most well-balanced, i.e. one that isn’t stuck in overbought or oversold conditions.

  • DaveM says:

    I have worked with RSI quite a bit, never thought to record the results. My idea would be to work with the highest win percentage and lowest equity drawdown. I suggest that changing the period beyond 14 might give some nice results also.
    Thanks for the insights.

  • Cameron Osborne says:

    Great analysis. I did something very similar for tracking the “RSI Trend” over a lookback of 55 periods. The analysis gave a result of 1 for instances where the RSI was over 69, and 1 when under 31. An RSI calculation was performed:

    N1 = 2… 14
    N2 = 55

    r = rsi(src, N1)

    // Normalize extreme levels
    OB = r > 69 ? 1 : 0
    OS = r < 31 ? 1 : 0

    // Average gain, average loss
    avgU = (avgU[1] * (N2 – 1) + OB) / N2
    avgD = (avgD[1] * (N2 – 1) + OS) / N2

    // RSI calculation of the trend
    rTrend = (100 – 100 / (1 + avgU / avgD)) / 100

    The result shows when the normal RSI of period N2 is spending most of its time near extreme levels. This helped, for example, filter out short trades when the "RSI Trend" was above say, 70. When the RSI Trend is above 70, the vast majority of the time when the normal RSI breached oversold (< 30), there was an immediate snap back up.

    Great work, I will research this further on intraday testing in Trading View.

  • Bard says:

    Hi Curtis,

    Thanks for an interesting article. What would easy language code look like to sum the amount of time that the RSI spends above 80 and below 20, and take the difference?

    I was curious to know which period (2…14) in the first table produced the $82,812? Ditto for both columns (30/70 and 20/80) in the second table for the Emini?

    Cheers
    Bard

  • >