avatarSofien Kaabar, CFA

Summary

The article introduces the Directional Probability Index (DPI), a novel trading indicator designed to estimate market direction by measuring the likelihood of bullish or bearish regimes and detecting potential market reversals.

Abstract

The Directional Probability Index (DPI) is presented as a tool for traders to gauge the market's current regime and predict possible inflection points. It calculates the probability of a market trend by analyzing the frequency of closing prices above the opening prices over a specified period, typically 13 periods. The DPI serves a dual purpose: it aids in regime detection, identifying whether the market is in a bullish or bearish phase, and it also acts as an indicator of potential market reversals by highlighting statistical extremes. The article further elaborates on the practical application of the DPI, providing Python code for its calculation and the generation of trading signals. It suggests that a DPI above 50% indicates a bullish regime, while a reading below 50% suggests a bearish regime. Additionally, when the DPI approaches 80% or higher, it may signal an overheated bullish stance likely to correct, whereas a DPI nearing 20% or lower could indicate an extreme bearish stance that might reverse with a bullish reaction. The author also promotes their new book, which includes advanced trend-following strategies and continuously updated code on GitHub, and invites readers to subscribe to a daily newsletter for more trading insights.

Opinions

  • The author emphasizes the importance of understanding how indicators are calculated to tweak them and be aware of their limitations.
  • The DPI is touted as a simple yet effective indicator that can help traders find good trading opportunities.
  • The author advocates for using the DPI as both a regime detection tool and a reversal indicator, suggesting it can provide a statistical edge in trading.
  • The article encourages readers to engage in back-testing and to develop their own intuition and strategies rather than copying others, promoting the concept of "Objective Technical Analysis" based on hard data.
  • The author expresses a belief in the potential of their NFT collection, "The Society of Light," to support humanitarian and medical causes, offering portfolio diversification and potential financial gain for buyers, along with a free copy of their book.

The Directional Probability Index — Estimating the Direction of the Market.

Creating a Simple Measure that Shows the Next Likely Direction.

This article discusses a simple indicator used to detect the current regime and to give contrarian signals. It is important to understand how to use indicators and how they are calculated in order to tweak them and know their limitations.

I have just released a new book after the success of my previous one “The Book of Trading Strategies”. It features advanced trend-following indicators and strategies with a GitHub page dedicated to the continuously updated code. Also, this book features the original colors after having optimized for printing costs. If you feel that this interests you, feel free to visit the below Amazon link, or if you prefer to buy the PDF version, you could contact me on LinkedIn.

Creating the Directional Probability Index Step-By-Step

The index is a simple calculation that will be transformed into a two-in-one indicator which has the following goals:

  • Regime detection.
  • Inflection point detection.

The first step is to calculate the percentage of times when the close price was higher than the open and divide it by a lookback period which is by default 13.

This gives us a sort of probability of the current regime. As simplistic as it may be, some times these types of methods help us find good opportunities.

def adder(Data, times):
    
    for i in range(1, times + 1):
    
        new = np.zeros((len(Data), 1), dtype = float)
        Data = np.append(Data, new, axis = 1)
    return Data
def deleter(Data, index, times):
    
    for i in range(1, times + 1):
    
        Data = np.delete(Data, index, axis = 1)
    return Data
def directional_probability_index(Data, lookback, open_column, close_column, where):
    
    # Adding a few columns
    Data = adder(Data, 3)
    
    # Calculating the DPI
    for i in range(len(Data)):
        
        if Data[i, close_column] > Data[i, open_column]:
            
            Data[i, where] = 1
            
    for i in range(len(Data)):
        
        Data[i, where + 1] = Data[i - lookback + 1:i + 1, where].sum()
        
    Data[:, where + 2] = (Data[:, where + 1] / lookback) * 100
    
    Data = deleter(Data, where, 2)
    
    return Data
Hourly EURUSD values with the 13-period DPI.

Whenever the DPI is showing a value greater than 50%, we can consider the market to be in a bullish regime and whenever it is showing a value lower than 50%, we can consider the market to be in a bearish regime. One more utility, is that we can also use it as a reversal indicator through the concept of statistical extremes. Whenever the DPI approaches 80%, we like to think that the bullish stance is overheating and might correct and whenever the DPI approaches 20%, we can expect that the bearish stance is at its extreme and might correct with a bullish reaction.

If you want to see more articles, consider subscribing to my DAILY Newsletter (A Free Plan is Available) via the below link. It features my Medium articles, more trading strategies, coding lessons related to research and analysis, also, subscribers get a free PDF copy of my first book. You can expect 5–7 articles per week with your paid subscription and 1–2 articles per week with the free plan. This would help me continue sharing my research. Thank you!

Using the Directional Probability Index

Having discussed the two ways of using the DPI, we will now proceed into applying them. We will understand at each time step, what the current regime is and whether we expect a reaction or not. Let us first code the signal function for the reactions:

  • A long (Buy) signal is generated whenever the 13-period DPI is at 20% or lower.
  • A short (Sell) signal is generated whenever the 13-period DPI is at 80% or higher.
def signal(Data, indicator_column, buy, sell):
    
    Data = adder(Data, 10)
        
    for i in range(len(Data)):
            
        if Data[i, indicator_column] < 20 and Data[i - 1, indicator_column] > 20 and Data[i - 2, indicator_column] > 20: 
               
               Data[i, buy] = 1
        elif Data[i, indicator_column] > 80 and Data[i - 1, indicator_column] < 80  and Data[i - 2, indicator_column] < 80: 
               
               Data[i, sell] = -1
               
    return Data
my_data = directional_probability_index(my_data, 13, 0, 3, 4)        
my_data = signal(my_data, 4, 6, 7)

Now, we will color-code the charts following these rules:

  • The bar is colored in blue if the current 13-period DPI is showing a reading above 50%.
  • The bar is colored in brown if the current 13-period DPI is showing a reading below 50%.
Signal chart on the GBPUSD.
def ohlc_plot_candles(Data, window):
      
    Chosen = Data[-window:, ]
    
    for i in range(len(Chosen)):
        
        plt.vlines(x = i, ymin = Chosen[i, 2], ymax = Chosen[i, 1], color = 'black', linewidth = 1)  
        
        if Chosen[i, 4] > 50:
            color_chosen = 'blue'
            plt.vlines(x = i, ymin = Chosen[i, 0], ymax = Chosen[i, 3], color = color_chosen, linewidth = 3)
        if Chosen[i, 4] < 50:
            color_chosen = 'brown'
            plt.vlines(x = i, ymin = Chosen[i, 3], ymax = Chosen[i, 0], color = color_chosen, linewidth = 3)  
            
    plt.grid()
def signal_chart(Data, close, what_bull, what_bear, window = 500):   
     
    Plottable = Data[-window:, ]
    
    fig, ax = plt.subplots(figsize = (10, 5))
    
    ohlc_plot_candles(Data, window)
    for i in range(len(Plottable)):
        
        if Plottable[i, what_bull] == 1:
            
            x = i
            y = Plottable[i, close]
        
            ax.annotate(' ', xy = (x, y), 
                        arrowprops = dict(width = 9, headlength = 11, headwidth = 11, facecolor = 'green', color = 'green'))
        
        elif Plottable[i, what_bear] == -1:
            
            x = i
            y = Plottable[i, close]
        
            ax.annotate(' ', xy = (x, y), 
                        arrowprops = dict(width = 9, headlength = -11, headwidth = -11, facecolor = 'red', color = 'red'))
Signal chart on the EURUSD.

The above chart shows the indicator applied to a clean chart. The bars in blue indicate a bullish regime and when we encounter a red arrow, it means that we expect a reaction to the downside. The bars in brown indicate a bearish regime and when we encounter a green arrow, it means that we expect a reaction to the upside.

If you are also interested by more technical indicators and strategies, then my book might interest you:

Conclusion

Remember to always do your back-tests. You should always believe that other people are wrong. My indicators and style of trading may work for me but maybe not for you.

I am a firm believer of not spoon-feeding. I have learnt by doing and not by copying. You should get the idea, the function, the intuition, the conditions of the strategy, and then elaborate (an even better) one yourself so that you back-test and improve it before deciding to take it live or to eliminate it. My choice of not providing specific Back-testing results should lead the reader to explore more herself the strategy and work on it more.

Medium is a hub to many interesting reads. I read a lot of articles before I decided to start writing. Consider joining Medium using my referral link!

To sum up, are the strategies I provide realistic? Yes, but only by optimizing the environment (robust algorithm, low costs, honest broker, proper risk management, and order management). Are the strategies provided only for the sole use of trading? No, it is to stimulate brainstorming and getting more trading ideas as we are all sick of hearing about an oversold RSI as a reason to go short or a resistance being surpassed as a reason to go long. I am trying to introduce a new field called Objective Technical Analysis where we use hard data to judge our techniques rather than rely on outdated classical methods.

One Last Word

I have recently started an NFT collection that aims to support different humanitarian and medical causes. The Society of Light is a set of limited collectibles which will help make the world slightly better as each sale will see a percentage of it sent directly to the charity attributed to the avatar. As I always say, nothing better than a bullet list to outline the benefits of buying these NFT’s:

  • High-potential gain: By concentrating the remaining sales proceedings on marketing and promoting The Society of Light, I am aiming to maximize their value as much as possible in the secondary market. Remember that trading in the secondary market also means that a portion of royalties will be donated to the same charity.
  • Art collection and portfolio diversification: Having a collection of avatars that symbolize good deeds is truly satisfying. Investing does not need to only have selfish needs even though there is nothing wrong with investing to make money. But what about investing to make money, help others, and collect art?
  • Donating to your preferred cause(s): This is a flexible way of allocating different funds to your charities.
  • A free copy of my book in PDF: Any buyer of any NFT will receive a free copy of my latest book shown in the link of the article.
Click here to buy Silver and support his cause against Polio.
Finance
Trading
Cryptocurrency
Bitcoin
Data Science
Recommended from ReadMedium