So, a few weeks ago, Bridegewater posted about doing a strategy of weekly Heikin-Ashi candles closing in relation to 7 EMA, using Stockcharts and the ticker QQQ. Just recently, he posted using it on Saul’s stocks. Had previously started running some backtesting in Excel. Still working on somethings, but now seemed a good time to throw it out for general review.
This is not intended to be a “how-to” thread nor a specific endorsement of Excel backtesting. It is intended to introduce some of the uses and outcomes of such testing, as well as provide more specific information as to specifically using EMA-Wkly HA crosses. I am going to break this up into a series of posts (although keeping it all on one thread). I’m also NOT an Excel guru and may have made mistakes that I’ve not detected, so please do your own due diligence before adapting anything and please share any thoughts or issues that you see.
I’m using Excel 365 with the basic structure of the Workbook containing a worksheet of the raw data and separate worksheets for calculations. The raw data is downloaded from Yahoo Historical data as weekly data. This is the OHLC for the week’s data as tabulated by Yahoo. NOTE: I used “Max” data range so this uses typically about 20 years of action (depending upon stock) so it covers a huge variation in stock and market conditions and reaction. The Heikin-Ashi candle values are calculated in the workbook directly from the raw data, as are the moving averages. Since all these calculations refer directly to the raw data worksheet, this allows me to simply replace the raw data in the single worksheet to generate evaluation of a different ticker. Each ticker has a separate workbook. I had previously a few years ago generated the core workbook and calculations for the HA candles and EMAs but double checked them here with candle values in TOS and Stockcharts. It is interesting that those values are not always the same between TOS and Stockcharts. My excel values are typically spot on or very close to TOS. Stockcharts seems to have more variation (via smoothing or adjusted closes?) but it’s all within reason.
Calculating the buy/sell signals is from the basic formula:
=IF(AND(E4>F4,E3<=F3),“Buy”,IF(AND(E4<F4,E3>=F3),“Sell”,“”)) where E=Close value of the weekly HA Candle and F= EMA value.
Data are collated and tabulated using the FILTER command for date and values, filtered by “Buy” or “Sell” result from the above formula. Standard formulas for EMA’s, Heikin Ashi candles, etc are from Investopedia and Stockcharts. Note, I commonly include additional “IF” functions in many of the calculations so that if there is no further raw data or subsequent data then the value is blank. This eliminates subsequent Div/0 and other common results that create errors further down the chain. Here’s a couple screen shots to give you an idea of the end results. You are not suppose to be able to read detail necessarily, it’s just to get the gestalt of what is involved and shows up.
The end calculations are in conditionally formatted cells showing green cell color for positive and red for negative. You can visually get an impression of the results above. I did tabulate the results in total as well broken down by the trades per year in conditionally formatted cells.
I think the first striking thing is the number of red cells, certainly makes the point that you don’t expect all trades to be positive when strictly using just EMA/HA Close data.
There are multiple variables to work through including optimal MA, form of MA and Buy/Sell timing. One of the first issues I addressed was the Trade timing, meaning do you buy/sell just before the close on the last moments for the candle (meaning Friday dependent upon the apparent candle close relative to the MA) or do you buy the open of the next candle, meaning Monday morning. There’s also the variation of combinations. For simplicity, I first looked at the HA candle close relative to the 7 EMA for QQQ, as initially suggested by Bridgewater. Here are the results, note that SCC=Same Candle Close (Friday’s) and NCO=Next Candle Open (Monday’s) for example so that SCC/SCC is buying and selling on the apparent close on Friday for both. Again, remember the total P/L is the sum over the entire duration of the data (often 20 years or more) so Average P/L is the better comparison between stocks. For 7 EMA crossovers of the weekly HA close:
The ”Whipsaw” calculations are referring to a Buy-Sell or Sell-Buy interval of <10 days (next candle) or <15 days (two candles) for Buy-Buy. Total whipsaws are total trades of one candle duration.
It’s interesting that the NCO trades are slightly better, although there is not a huge difference. Remember, backtesting is specific for an individual ticker and you can not directly assume every ticker will respond exactly the same. It does give you an indication of how things will likely respond but it’s up to you to form your plan and approach. Personally, I will lean towards making SCC decisions, but it’s nice to know that should those decisions be delayed that I am unlikely risking a significant loss of potential profit.
The next issue is what is the optimal EMA. I used these worksheets and formulas to compare QQQ weekly Heikin-Ashi candle closes to various EMA’s. I chose 3, 5, 8, 13, 21, 34 and 55 as they are Fibonacci numbers. I’m showing data for both same candle close price and next candle open price out of curiosity.
The change in qualitative variation is interesting, but not surprising that the shorter EMA’s had more trades with more whipsaw. There is certainly a trend for longer periods to do better in overall P/L. Clearly 21 and 34 EMA’s did much better than the shorter 7 EMA, with longer duration trades, fewer negative trades, less whipsaw.
- Using the weekly Heikin-Ashi candle close compared to the 7 EMA is a reasonable indicator of when to buy or sell. Is it absolute? Certainly not, but it appears to provide a positive ratio of profit versus loss to make money.
- The data clearly does emphasize the common accepted perspective that you will always have losing trades but you can still make a good profit if you manage them. Supports the adage of cutting losers and letting winners run.
- Surprisingly, to me, it appears that while using HA candles (that do NOT show gaps and are calculated) it does not apparently influence the P/L much whether you work to close at the end of Friday or the beginning of Monday. The SCC compared to NCO data. It certainly makes me more comfortable knowing that I
- Longer length EMA’s did significantly better than the shorter EMA’s such as the suggested 7 EMA.
What does this EMA-HA Close crossover tell you? Not much more about a stock than it has moved into an uptrend or a down-trend. It gives no indication as to the strength of the move nor anticipated duration. Understand the limits. The following graphically shows you the difference.
Wkly Heikin-Ashi with 13 EMA
21 EMA
34 EMA
The trend is your friend until it ends with a bend.
The interesting thing is to look at some other moving averages as well as different equities. QQQ is a relatively lower volatile equity. I have some other data, but won’t have time to post until later.
Happy hunting,
Lakedog