charmingcompanions.com

Detecting Market Regimes Using the Vertical Horizontal Filter

Written on

Chapter 1: Understanding Market Regimes

In the world of trading, a significant portion of time is devoted to answering the perennial question: "What will the market do next? Will it range or trend?" Discovering this answer is akin to finding a holy grail; if we can predict market movements, we can select the most suitable strategies accordingly.

Many effective trading strategies falter when market regimes shift, rendering previous approaches ineffective. For instance, consider a scenario where the market is expected to remain stagnant. A strategy focused on buying at lows and selling at highs would perform well. However, if the market suddenly trends in one direction, that same strategy may struggle to yield profits.

I've recently published a new book following the success of my last one. This latest edition includes sophisticated trend-following indicators and strategies, complete with a dedicated GitHub repository for ongoing code updates. The book has also been optimized for printing, retaining its original design. If this piques your interest, check out the link to purchase it on Amazon, or reach out to me on LinkedIn for a PDF version.

What is a Market Regime?

Markets typically exhibit either trending or ranging behavior. To maximize profitability, it's crucial to apply the appropriate strategy at the right time. Mean-reversion strategies thrive in sideways markets, while trend-following strategies excel in upward or downward trends.

For example, in a bullish market, the likelihood of upward movement is higher than downward, making trend-following strategies more effective. Conversely, in such a scenario, mean-reversion strategies tend to falter, as they may continuously signal bearish trends while the market rises.

As a reminder, a bullish market indicates an upward trend, whereas a bearish market reflects a downward trend.

The Vertical Horizontal Filter's Role

The Vertical Horizontal Filter (VHF), introduced by Adam White, serves as a tool to gauge the strength of market trends. This indicator helps traders identify which strategies to employ based on market conditions.

To calculate the VHF, follow these steps:

  1. Compute the absolute price differences between consecutive periods. For instance, if the current price is $99 and the previous price was $100, the absolute difference is $1.
  2. Determine the maximum and minimum values within a specified lookback period. For a lookback period of 5, subtract the highest closing price from the lowest closing price during that timeframe.
  3. Divide the result of step 1 by the result of step 2 to obtain the VHF.

How To Develop Regime Filters For Crypto Trading Strategies - YouTube

This video elaborates on how to create regime filters specifically for crypto trading strategies, providing insights into effective market analysis.

Creating the Vertical Horizontal Filter

Here's a Python implementation of the functions needed to manipulate your data for the VHF:

# Function to add multiple columns to an array

def adder(Data, times):

for i in range(1, times + 1):

new_col = np.zeros((len(Data), 1), dtype=float)

Data = np.append(Data, new_col, axis=1)

return Data

# Function to remove columns from a specific index

def deleter(Data, index, times):

for i in range(1, times + 1):

Data = np.delete(Data, index, axis=1)

return Data

# Function to jump a number of rows at the start

def jump(Data, jump):

Data = Data[jump:,]

return Data

For instance, to add three empty columns:

my_ohlc_array = adder(my_ohlc_array, 3)

To eliminate two columns after the third indexed column:

my_ohlc_array = deleter(my_ohlc_array, 3, 2)

And to remove the first twenty rows:

my_ohlc_array = jump(my_ohlc_array, 20)

Note: OHLC stands for Open, High, Low, and Close, representing standard historical data.

Implementing the Vertical Horizontal Filter

Now, let's create the Vertical Horizontal Filter using the following function:

def vertical_horizontal_indicator(Data, lookback, what, where):

Data = adder(Data, 10)

for i in range(len(Data)):

Data[i, where] = Data[i, what] - Data[i - 1, what]

Data = jump(Data, 1)

Data[:, where] = abs(Data[:, where])

for i in range(len(Data)):

Data[i, where + 1] = Data[i - lookback + 1:i + 1, where].sum()

for i in range(len(Data)):

try:

Data[i, where + 2] = max(Data[i - lookback + 1:i + 1, what]) - min(Data[i - lookback + 1:i + 1, what])

except ValueError:

pass

Data = jump(Data, lookback)

Data[:, where + 3] = Data[:, where + 2] / Data[:, where + 1]

Data = deleter(Data, where, 3)

return Data

The challenge lies in utilizing this indicator effectively for trading. The premise is that increasing values signify a trending market (either bullish or bearish), while declining values indicate a ranging market. However, identifying your own thresholds and limits is essential.

Market Regime Filters for Trading Strategy - YouTube

This video discusses market regime filters tailored for trading strategies, offering guidance on effectively navigating market conditions.

Analyzing the Vertical Horizontal Filter

The chart below illustrates the hourly EUR/USD with a 60-period Vertical Horizontal Filter. Notably, as the indicator rises, it correlates with a trending market, suggesting a potential strategy based on these values.

The following signals can be derived:

  • When the indicator is below its moving average, the market regime appears unclear or ranging.
  • When the indicator is above its moving average, the market is considered to be trending.

def signal(Data, indicator, indicator_ma, signal):

Data = adder(Data, 10)

for i in range(len(Data)):

if Data[i, indicator] > Data[i, indicator_ma]:

Data[i, signal] = 1

return Data

If you're intrigued by additional technical indicators and strategies, my book may be of interest.

One Last Note

I have recently launched an NFT collection aimed at supporting various humanitarian and medical initiatives. The Society of Light is a limited collection designed to contribute to charitable causes with each sale directing a portion of the proceeds to the respective charity.

Benefits of these NFTs include:

  • High potential returns: Focusing on marketing and promotion should enhance their value in the secondary market, with royalties also benefiting charities.
  • Art collection and diversification: Owning avatars representing good deeds can be fulfilling. Investing can serve altruistic purposes alongside financial gain.
  • Flexible donations: Allocate funds to your chosen causes easily.
  • Free PDF copy of my book: Buyers of any NFT will receive a complimentary copy of my latest publication linked in this article.

Click here to support a cause and purchase an NFT.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Embracing Questions: Why Asking Helps You Grow

Discover the importance of asking questions and overcoming the fear of judgment to enhance personal growth.

Conquer Anxiety and Stress: 5 Effective Strategies to Try

Explore five powerful techniques to manage anxiety and stress, enhancing your mental well-being and productivity.

Is AI Taking Over the Role of Human Photographers?

Exploring the impact of AI on photography and whether it can replace human professionals.