Exploring Market State Detection Through Moving Averages
Written on
Chapter 1: Introduction to Market Regime Detection
Identifying the current market state is crucial for determining whether to adopt a long or short position. While many of us often categorize the market as bullish or bearish based on intuition, there are various analytical methods to gain deeper insights. One effective approach is the use of moving averages, particularly when they are analyzed collectively. This article will delve into the process of constructing a moving average index that consolidates multiple moving averages to better interpret market trends.
I recently published a new book following the success of my previous work. This new edition includes advanced indicators and strategies for trend following, accompanied by a GitHub repository that hosts the regularly updated code. Additionally, it features original color schemes optimized for printing costs. If you're interested, you can check it out through the Amazon link below, or contact me on LinkedIn for the PDF version.
Chapter 2: Understanding Moving Averages
Moving averages serve as a means to confirm and leverage market trends. Their popularity as a technical indicator stems from their simplicity and effectiveness in enhancing analysis. These tools can assist in pinpointing support and resistance levels, setting stop-loss orders, and comprehending the overall market trend. Their versatility renders them an essential component of any trader’s toolkit.
For instance, the 200-period simple moving average of EUR/USD demonstrates how moving averages can provide dynamic support and resistance levels, allowing traders to make informed decisions regarding order placements.
Mathematically, the moving average is the sum of observations divided by the total number of observations. Its formula is as follows:
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 jump(Data, jump):
Data = Data[jump:, ]
return Data
def ma(Data, lookback, close, where):
Data = adder(Data, 1)
for i in range(len(Data)):
try:
Data[i, where] = (Data[i - lookback + 1:i + 1, close].mean())except IndexError:
passreturn Data
my_data = ma(my_data, 200, 3, 4)
Chapter 3: Creating the Global Moving Average Scanner
The Global Moving Average Scanner acts as an index comprising various moving averages. Its primary function is to illustrate how many moving averages lie above or below the current market price. A robust bullish trend is indicated when the market price exceeds its moving averages, whereas a strong bearish trend is signified when the market price falls below them.
We will implement a loop to compute moving averages ranging from 5 to 1000 periods, incrementing by 10.
# Adding one column for the GMAS
my_data = adder(my_data, 1)
# Where the first MA column will be
where = 4
# Looping around the data and creating moving averages
for i in range(5, 1000, 10):
my_data = ma(my_data, i, 3, where)
where = where + 1
# Cleaning the first NaN values
my_data = jump(my_data, 1000)
For instance, a value of 67 indicates that 67 out of 100 moving averages are positioned below the market, suggesting a bullish trend. This indicator, while simplistic, serves to gauge the direction and strength of the trend, revealing critical insights:
- A reading of 100 implies a strong bullish trend.
- A value surpassing 50 suggests bullish confirmation.
- A reading dropping below 50 indicates potential bearish confirmation.
- A value of 0 indicates a strong bearish trend.
The indicator should be utilized alongside other tools. For instance, a short-term RSI can be employed to monitor market drops while the Global Moving Average Index is at zero or crossing the 50 threshold.
To enhance visual interpretation, we can color-code the bars: green for values above 50, indicating a bullish state, and red for values below 50. Below is a function to implement this:
def ohlc_plot_bars(Data, window):
Chosen = Data[-window:, ]
for i in range(len(Chosen)):
plt.vlines(x=i, ymin=Chosen[i, 2], ymax=Chosen[i, 1], color='white', linewidth=1)
if Chosen[i, 4] > 50:
color_chosen = 'green'elif Chosen[i, 4] < 50:
color_chosen = 'red'else:
color_chosen = 'blue'plt.vlines(x=i, ymin=Chosen[i, 3], ymax=Chosen[i, 0], color=color_chosen, linewidth=1.00)
plt.grid()
Chapter 4: Conclusion and Future Prospects
Although moving averages are inherently lagging indicators, employing multiple averages can provide valuable confirmation. The good news is that by adjusting the lookback periods to fit your trading style, such as {20, 30, 60, 100, 200, 300, 500}, you can optimize this approach to better suit your strategy.
If you're intrigued by additional technical indicators and strategies, my latest book could be of interest.
Chapter 5: Supporting Humanitarian Causes Through NFTs
I have recently launched an NFT collection aimed at supporting various humanitarian and medical initiatives. The Society of Light is a series of limited collectibles designed to contribute positively to the world, with a percentage of proceeds directed towards the associated charity for each avatar. Here are some advantages of purchasing these NFTs:
- High-potential gain: By focusing the remaining sales proceeds on marketing and promoting The Society of Light, I aim to maximize their value in the secondary market. Remember, trading in this market also means a portion of royalties will benefit the same charity.
- Art collection and portfolio diversification: Owning a collection of avatars that embody goodwill is genuinely fulfilling. Investing can be about more than just personal gain; it can also encompass helping others and appreciating art.
- Flexibility in donations: This model allows for varying allocations to your favorite charities.
- Free copy of my book: Any NFT buyer will receive a complimentary PDF version of my latest book.
Explore the following videos for deeper insights into market trends:
The first video titled "How Triple Moving Averages Help Classify Market Regimes" discusses how combining moving averages can provide clarity on market phases.
The second video titled "How Algorithmic Traders Can Identify Market Trends" showcases how traders can utilize moving averages to spot emerging trends.