Mastering the Q-Stick Indicator: Coding and Application Insights
Written on
Chapter 1: Understanding the Q-Stick Indicator
As we continue to innovate, develop, and back-test various technical indicators, our primary aim remains the same: to discover a balanced approach that enables us to achieve steady and reliable returns over time. Navigating through intricate market conditions can be challenging, but with commitment and discipline, success is attainable. In this article, we will explore the Q-Stick indicator, a contrarian oscillator designed to forecast market reversals.
Recently, I published a new book following the success of my earlier work, "Trend Following Strategies in Python." This new release includes a variety of advanced contrarian indicators and strategies, along with a GitHub page for ongoing code updates. If you're interested, you can purchase the PDF version for 9.99 EUR via PayPal. Please ensure you include your email address in the payment note to receive the file at the correct location. Once acquired, remember to download it via Google Drive.
Section 1.1: The Role of Exponential Moving Averages
Moving averages play a critical role in confirming trends and capitalizing on them. They are among the most recognized technical indicators, primarily due to their simplicity and consistent effectiveness in enhancing analytical insights. These averages help identify support and resistance levels, set targets, and gain a clearer understanding of market trends. Their adaptability makes them a vital component of any trader's toolkit.
Here’s a look at the EURUSD hourly data with a 200-hour simple moving average.
Mathematically, a moving average is calculated by dividing the total sum of observations by the number of observations. In practice, it acts as a dynamic support and resistance tool, guiding where to place trades when the market approaches these levels. Below is an example code for implementing a moving average:
# The function to add a number of columns inside 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
# The function to delete a number of columns starting from an index
def deleter(Data, index, times):
for i in range(1, times + 1):
Data = np.delete(Data, index, axis=1)return Data
# The function to delete a number of rows from the beginning
def jump(Data, jump):
Data = Data[jump:, ]
return Data
# Example of adding 3 empty columns to an array
my_ohlc_array = adder(my_ohlc_array, 3)
# Example of deleting the 2 columns after the column indexed at 3
my_ohlc_array = deleter(my_ohlc_array, 3, 2)
# Example of deleting the first 20 rows
my_ohlc_array = jump(my_ohlc_array, 20)
The OHLC acronym stands for Open, High, Low, and Close, which is a standard format for historical data.
The following code applies the moving average function on the 'my_data' array for a lookback period of 200, focusing on the column containing closing prices. The calculated moving average will be stored in an additional column.
my_data = ma(my_data, 200, 3, 4)
Unlike the simple moving average, which gives equal weight to all observations, the exponential moving average (EMA) assigns greater weight to more recent data points. This makes it more responsive to current market conditions. The formula is as follows:
The smoothing factor is commonly set to 2. Increasing the smoothing factor (alpha) further emphasizes recent observations. Below is the Python function for calculating the EMA:
def ema(Data, alpha, lookback, what, where):
alpha = alpha / (lookback + 1.0)
beta = 1 - alpha
# First value is a simple SMA
Data = ma(Data, lookback, what, where)
# Calculating first EMA
Data[lookback + 1, where] = (Data[lookback + 1, what] * alpha) + (Data[lookback, where] * beta)
# Calculating the rest of EMA
for i in range(lookback + 2, len(Data)):
try:
Data[i, where] = (Data[i, what] * alpha) + (Data[i - 1, where] * beta)except IndexError:
pass
return Data
We will utilize the EMA to compute the Q-Stick Indicator, emphasizing the concepts rather than the specific coding details. Most of my strategies can be found within my published works. The key takeaway is to grasp the techniques and strategies effectively.
Recently, I joined forces with Lumiwealth to offer a variety of courses on algorithmic trading, blockchain, and machine learning. I highly recommend checking out their detailed, hands-on courses.
Section 1.2: The Q-Stick Indicator Explained
The Q-Stick Indicator, created by Tushar Chande, assesses momentum by evaluating the difference between closing and opening prices, followed by a smoothing process. It resembles the rate of change indicator but incorporates a smoothing factor to reduce the impact of outliers. The formula can be expressed as follows:
The default lookback period for the Q-Stick is typically set to 14, meaning we will compute the difference between closing and opening prices for each period and then apply a 14-period exponential moving average.
Here's how the Q-Stick Indicator can be coded in Python:
def q_stick(Data, ema_lookback, opening, close, where):
for i in range(len(Data)):
Data[i, where] = Data[i, close] - Data[i, opening]Data = ema(Data, 2, ema_lookback, where, where + 1)
return Data
The 'Data' variable refers to the OHLC array you are working with, while 'ema_lookback' indicates the chosen lookback period. The 'opening' and 'closing' variables refer to the respective columns in the OHLC array, and 'where' determines the placement of the Q-Stick values.
While the Q-Stick Indicator is effective, it is unbounded, necessitating a strategy for trading it, such as employing moving average crosses or neutrality surpass methods.
To gain insight into the current market landscape, consider my weekly market sentiment report. This report evaluates the positioning and predicts future trends across major markets using both straightforward and complex models.
Chapter 2: Conclusion and Best Practices
In summary, my objective is to contribute positively to the realm of objective technical analysis by promoting transparent methodologies that should be back-tested prior to implementation. This approach aims to dispel the notion of technical analysis being subjective or lacking scientific foundation.
Medium offers a wealth of engaging articles. After reading numerous pieces, I felt inspired to begin writing my own. If you're interested, consider joining Medium using my referral link at no extra cost to you.
Whenever you encounter a trading technique or strategy, I recommend following these steps:
- Maintain a critical mindset and eliminate emotional biases.
- Conduct back-testing using realistic simulation and conditions.
- If you identify potential, optimize the strategy and run a forward test.
- Always factor in transaction costs and simulate slippage in your tests.
- Incorporate risk management and position sizing in your evaluations.
Finally, even after taking these precautions, remain vigilant and monitor your strategy closely, as market dynamics can shift, potentially rendering your approach unprofitable.
In this video, viewers will learn about technical indicators using Python, focusing on practical coding examples to enhance their trading strategies.
This video demonstrates how to utilize the new "Qgrid" indicator on standard candlestick charts, providing insights into its application and effectiveness.