Heikin Ashi "Just Assume Seven" Strategy For ThinkOrSwim

Inspired by this post on twitter, here is the "Just Assume Seven" strategy.

The author assumes that when the color changes on a Heikin Ashi 30 minute chart, you can assume that there will be at least seven bars in that direction. He is obviously not claiming that this is any kind of guarantee, but feel that it is common enough to base a strategy on. I am not familiar with his exit or trade management strategies, so I coded up something simple, using these rules:

1. Enter a Long position when the heikin ashi chart changes to green
2. Hold the long position until either:
a) the heikin ashi turns red, or
b) the current bar closes lower than the previous bar, and there have been at least seven bars in the same direction.

The rules are reversed for short entries. The user can vary the number of bars to hold the trade and watch for a lower close.

dw7VWR1.png


Here are the results of a 180 day backtest of the strategy. Obviously the strategy isn't tradeable as it is currently written, but I thought it might provide a framework that could be the basis of something more profitable.

bzHTkke.png


JBSjwGR.png


2GoaNO8.png



Code:
#HeikinAshi_Assume_Seven
#Author @dublin_capital
#Version History 202005301044ds
#2020-05-30

#based on a 2020-05-30 tweet from @RealBrianWatt, suggesting that you can assume 7 candles on a 30 minute Heikin Ashi chart

input barStop = 7;

def heikinAshiClose = (open + high + low + close) / 4;

rec heikinAshiOpen = CompoundValue(1, (heikinAshiOpen[1] + heikinAshiClose[1]) / 2, (open[1] + close[1]) / 2);

def difference = heikinAshiClose - heikinAshiOpen;

def longSignal = difference > 0 and difference[1] <= 0;
def shortSignal = difference < 0 and difference[1] >= 0;


def barNumberLong = CompoundValue(1, if difference > 0 then barNumberLong[1] + 1 else 0, 0);
def barNumberShort = CompoundValue(1, if difference < 0 then barNumberShort[1] + 1 else 0, 0);

plot barsUp = if barNumberLong > 0 then barNumberLong else Double.NaN;
barsUp.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
barsUp.SetDefaultColor(Color.DARK_GREEN);

plot barsDown = if barNumberShort > 0 then barNumberShort else Double.NaN;
barsDown.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
barsDown.SetDefaultColor(Color.DARK_RED);

AddOrder(OrderType.BUY_AUTO, longSignal, tickcolor = Color.DARK_GREEN, arrowcolor = Color.DARK_GREEN, name = "LONG");
AddOrder(OrderType.SELL_TO_CLOSE, barNumberLong > barStop - 1 and close < close[1], tickcolor = Color.DARK_GREEN, arrowcolor = Color.DARK_GREEN, name = "CLOSE");

AddOrder(OrderType.SELL_AUTO, shortSignal, tickcolor = Color.DARK_RED, arrowcolor = Color.DARK_RED, name = "SHORT");
AddOrder(OrderType.BUY_TO_CLOSE, barNumberShort > barStop - 1 and close > close[1], tickcolor = Color.DARK_RED, arrowcolor = Color.DARK_RED, name = "CLOSE");


AddLabel(yes, if difference > 0 then "Consecutive Bars Up: " + barsUp else if difference < 0 then "Consecutive Bars Down: " + barsDown else "0", if difference > 0 then color.DARK_GREEN else if difference < 0 then color.DARK_RED else color.GRAY);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

What the data shows is that this works on the S&P,NASDAQ (probably Russell and Dow as well), and of course VIX since it works as an inverse to the previous mentions in a way.But of course nothing else, which would be for many reasons, mainly is that the other assets are too volatile and oscillate in value greatly throughout the day, especially oil, currencies and bonds. The second step to this analysis is to take the net positives and expand their analysis back several years to test viability for them alone. Probably test in 3-5 year groupings as the market conditions vary greatly over x years depending on when you backtest, and odds are conditions will change again in the next couple years. So testing many years back in small groupings could show you what conditions lead to this strategies viability
 
I originally posted this strategy as a response to a tweet that suggested that this was a viable strategy (since deleted). I had hoped to prove them correct and automate things for them, but it just isn't tradeable based on the rules that they shared. Even if profitable, I don't trade any strategies that have a commission % "in the red". Too fragile, and will eventually break down.

I still thought I would share the code - maybe it will help someone solve a different problem or provide something to build on.

@tradebyday did a great job explaining an approach that might help someone turn a bad strategy into something worthwhile. Great advice.
 
I originally posted this strategy as a response to a tweet that suggested that this was a viable strategy (since deleted). I had hoped to prove them correct and automate things for them, but it just isn't tradeable based on the rules that they shared. Even if profitable, I don't trade any strategies that have a commission % "in the red". Too fragile, and will eventually break down.

I still thought I would share the code - maybe it will help someone solve a different problem or provide something to build on.

@tradebyday did a great job explaining an approach that might help someone turn a bad strategy into something worthwhile. Great advice.


Just a quick question for something related I am working on.

In your code above, which parts define the following?
  • Heiken Ashi OPEN
  • Heiken Ashi CLOSE
I like to look at regular candles during the day, but would like to have a label on my Intraday chart that tells me what is happening on a Heiken Ashi without having to switchover and look at it.

Any help greatly appreciated.
 
This is just one of many pattern trading strategies. I haven't done much research, let alone any backtesting, on any of these, but identifying patterns that could work (or has worked) for certain securities may be totally flawed for others. Just like we wouldn't use seasonal strategies for wheat/corn/ags with gold and forex. If the ES shows consistent profitability with this as opposed to the metals/currencies/energy then maybe someone might want to do additional research on this strategy exclusively for the indexes. Maybe they'll also find that it works great on the SPY in addition to the ES...or maybe not so great. But I will say that I can't see this working with the smaller time frames.
 
Inspired by this post on twitter, here is the "Just Assume Seven" strategy.

The author assumes that when the color changes on a Heikin Ashi 30 minute chart, you can assume that there will be at least seven bars in that direction. He is obviously not claiming that this is any kind of guarantee, but feel that it is common enough to base a strategy on. I am not familiar with his exit or trade management strategies, so I coded up something simple, using these rules:

1. Enter a Long position when the heikin ashi chart changes to green
2. Hold the long position until either:
a) the heikin ashi turns red, or
b) the current bar closes lower than the previous bar, and there have been at least seven bars in the same direction.

The rules are reversed for short entries. The user can vary the number of bars to hold the trade and watch for a lower close.

dw7VWR1.png


Here are the results of a 180 day backtest of the strategy. Obviously the strategy isn't tradeable as it is currently written, but I thought it might provide a framework that could be the basis of something more profitable.

bzHTkke.png


JBSjwGR.png


2GoaNO8.png



Code:
#HeikinAshi_Assume_Seven
#Author @dublin_capital
#Version History 202005301044ds
#2020-05-30

#based on a 2020-05-30 tweet from @RealBrianWatt, suggesting that you can assume 7 candles on a 30 minute Heikin Ashi chart

input barStop = 7;

def heikinAshiClose = (open + high + low + close) / 4;

rec heikinAshiOpen = CompoundValue(1, (heikinAshiOpen[1] + heikinAshiClose[1]) / 2, (open[1] + close[1]) / 2);

def difference = heikinAshiClose - heikinAshiOpen;

def longSignal = difference > 0 and difference[1] <= 0;
def shortSignal = difference < 0 and difference[1] >= 0;


def barNumberLong = CompoundValue(1, if difference > 0 then barNumberLong[1] + 1 else 0, 0);
def barNumberShort = CompoundValue(1, if difference < 0 then barNumberShort[1] + 1 else 0, 0);

plot barsUp = if barNumberLong > 0 then barNumberLong else Double.NaN;
barsUp.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
barsUp.SetDefaultColor(Color.DARK_GREEN);

plot barsDown = if barNumberShort > 0 then barNumberShort else Double.NaN;
barsDown.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
barsDown.SetDefaultColor(Color.DARK_RED);

AddOrder(OrderType.BUY_AUTO, longSignal, tickcolor = Color.DARK_GREEN, arrowcolor = Color.DARK_GREEN, name = "LONG");
AddOrder(OrderType.SELL_TO_CLOSE, barNumberLong > barStop - 1 and close < close[1], tickcolor = Color.DARK_GREEN, arrowcolor = Color.DARK_GREEN, name = "CLOSE");

AddOrder(OrderType.SELL_AUTO, shortSignal, tickcolor = Color.DARK_RED, arrowcolor = Color.DARK_RED, name = "SHORT");
AddOrder(OrderType.BUY_TO_CLOSE, barNumberShort > barStop - 1 and close > close[1], tickcolor = Color.DARK_RED, arrowcolor = Color.DARK_RED, name = "CLOSE");


AddLabel(yes, if difference > 0 then "Consecutive Bars Up: " + barsUp else if difference < 0 then "Consecutive Bars Down: " + barsDown else "0", if difference > 0 then color.DARK_GREEN else if difference < 0 then color.DARK_RED else color.GRAY);
In using your strategy, the chart type on TOS should be set as "Heikin Ashi"? or just as usual "Candle Trend"
 
@Dublin_Capital what software or Excel spreadsheet are you using to backtest? It looks pretty robust and am curious if this is a manual tracking process or somehow you have automated it? I have been searching for a while for a good back testing software to pair with TOS but have been relatively unsuccessful so far. Thanks!
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
405 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top