Backtesting strategy 9.1 Larry Williams
When it comes to trading strategies, Larry Williams is a name that stands out. Renowned for his expertise in the financial markets, Williams has developed numerous successful trading approaches. One of his notable contributions is the Setup 9.1, a strategy that is centered around the utilization of one exponential moving average (EMA) and gained popularity among traders seeking a systematic approach to identify potential trading opportunities. In this article, we will delve into the details of Setup 9.1 and explore its key principles and application.
Understanding Setup 9.1:
Setup 9.1 centers around the concept of the EMA turning point and its relationship with price action. By monitoring the EMA’s behavior and confirmation through candlestick closes, traders can align themselves with potential trend reversals and capitalize on subsequent price movements.
Key Principles of Setup 9.1:
1. Exponential Moving Average: The strategy involves utilizing a single 9 period EMA, or on the trader’s preferences and timeframe. The EMA acts as a trend indicator, providing a smoothed line that reflects the underlying price direction.
2. EMA Turning Point: Setup 9.1 looks for a turning point in the EMA, indicating a potential change in the prevailing trend. When the EMA starts to slope upward, it suggests a bullish shift, signaling a potential buying opportunity. Conversely, when the EMA turns downward, it indicates a bearish shift, signaling a potential selling opportunity.
3. Candlestick Confirmation: The strategy seeks confirmation through candlestick closes. A buy signal is triggered when the price closes one tick above the candlestick that marks the turning point of the EMA, validating the potential trend reversal. Conversely, a sell signal is triggered when the price closes one tick below the candlestick that marks the EMA turning down.
4. Stop Levels: A buy stop-loss order is typically placed below the low of candlestick that marks the turning point of the EMA and a sell stop-loss is placed above the high of candlestick that marks the turning point of the EMA.
In order to automate this task I will use Python which is a popular programming language widely used for data analysis, including financial and stock market analysis. It provides a rich ecosystem of libraries and tools for data manipulation, visualization, and statistical calculations.
One easy way to run it without install or setup anything complex is to use Google Colab. It is a free cloud-based platform that provides a Jupyter Notebook environment, allowing you to run Python code directly in your browser without any setup or installation. It offers access to powerful hardware resources, such as GPUs and TPUs, and allows collaboration with others in real-time.
Go to the Google Colab website (https://colab.research.google.com) and sign in with your Google account and create a New Notebook.
In the first cell of the notebook, import the necessary libraries for working with stock data, such as pandas, backtesting and yfinance. For example:
One function calculates EMA and another defines entry and exit point for Setup 9.1.
Now let´s define our asset / stock and params to backtest it.
The backtest results on the Nasdaq index showed a 3.14% return over a period of 3 years using Setup 9.1 strategy, whereas a simple buy and hold approach yielded a higher return of 15.11%. However, when applying the same strategy to the IBOV index, a return of 14.59% was achieved, outperforming the buy and hold approach which resulted in a capital decrease of 7.2%.
NASDAQ
IBOV
The complete code for the 9.1 strategy can be accessed on this gist: SETUP9.1.ipynb. Further optimizations can be explored to enhance the performance of the strategy and achieve improved results. These optimization techniques will be covered in a separate article for a comprehensive understanding of maximizing the strategy’s potential. Stay tuned for the upcoming article.