Moving Average (MA) Heiken Ashi Trend Strategy for ThinkorSwim

Lesnewby

Member
Moving Average (MA) Heiken Ashi Trend Strategy for ThinkorSwim

Good morning, hope you are safe and well! Yes if you could share I would try it and give you some feedback!
Here is something that may interest you, it is a Strategy that I use with Expected Moves for SPY, QQQ, and IWM. I trigger a buy order on the second green bar, on the HA (Heiken-Ashi) candle without a tail. The exit is same on the 2nd red bar. I developed this with Pete Hahan, and paid him for the modifications so I can share. I only use the long order side and I only trade options on these signals.
Let me know what you think and how we can improve this!

Leslie (Lesnewby)
Code:
#start
#Software modified by Pete Hahn for #L.J.Jedrychowski

# Leslie Jedrychowski V 7.0 2grn HA bars after a HA red bar.

#---------- Strategy Inputs
input tradeSize = 100;
#---------- Moving Average Inputs
input maLengthOne = 20;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 100;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;

#---------- Moving Average Section
plot maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
plot maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);

#---------- Heiken-Ashi Candles Section
def haClose = ohlc4;
def haOpen = if haOpen[1] == 0 then haClose[1] else (haOpen[1] + haClose[1]) / 2;
def haHigh = Max(high, Max(haClose, haOpen));
def haLow = Min(low, Min(haClose, haOpen));
def greenCandle = haClose > haOpen;
def redCandle = haClose < haOpen;
def trendUp = greenCandle and greenCandle[1] and !greenCandle[2];
def trendDown = redCandle and redCandle[1] and !redCandle[2];

#---------- Strategy Orders Section
# Long order
AddOrder(OrderType.BUY_TO_OPEN, trendUp[-1], close[-1], tradeSize, Color.CYAN, Color.CYAN, "LE");
AddOrder(OrderType.SELL_TO_CLOSE, trendDown[-1], close[-1], tradeSize, Color.MAGENTA, Color.MAGENTA, "LX");

#Short order
#AddOrder(OrderType.SELL_TO_OPEN, trendDown[-1], close[-1], tradeSize, Color.CYAN, Color.CYAN, "HA 2 Bar SE");
#AddOrder(OrderType.BUY_TO_CLOSE, trendUp[-1], close[-1], tradeSize, Color.MAGENTA, Color.MAGENTA, "HA 2 Bar SX");
#end


LJJ
 
Last edited by a moderator:
Good morning, hope you are safe and well! Yes if you could share I would try it and give you some feedback!
Here is something that may interest you, it is a Strategy that I use with Expected Moves for SPY, QQQ, and IWM. I trigger a buy order on the second green bar, on the HA (Heiken-Ashi) candle without a tail. The exit is same on the 2nd red bar. I developed this with Pete Hahan, and paid him for the modifications so I can share. I only use the long order side and I only trade options on these signals.
Let me know what you think and how we can improve this!

Leslie (Lesnewby)

#start
#Software modified by Pete Hahn for #L.J.Jedrychowski

# Leslie Jedrychowski V 7.0 2grn HA bars after a HA red bar.

#---------- Strategy Inputs
input tradeSize = 100;
#---------- Moving Average Inputs
input maLengthOne = 20;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 100;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;

#---------- Moving Average Section
plot maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
plot maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);

#---------- Heiken-Ashi Candles Section
def haClose = ohlc4;
def haOpen = if haOpen[1] == 0 then haClose[1] else (haOpen[1] + haClose[1]) / 2;
def haHigh = Max(high, Max(haClose, haOpen));
def haLow = Min(low, Min(haClose, haOpen));
def greenCandle = haClose > haOpen;
def redCandle = haClose < haOpen;
def trendUp = greenCandle and greenCandle[1] and !greenCandle[2];
def trendDown = redCandle and redCandle[1] and !redCandle[2];

#---------- Strategy Orders Section
# Long order
AddOrder(OrderType.BUY_TO_OPEN, trendUp[-1], close[-1], tradeSize, Color.CYAN, Color.CYAN, "LE");
AddOrder(OrderType.SELL_TO_CLOSE, trendDown[-1], close[-1], tradeSize, Color.MAGENTA, Color.MAGENTA, "LX");

#Short order
#AddOrder(OrderType.SELL_TO_OPEN, trendDown[-1], close[-1], tradeSize, Color.CYAN, Color.CYAN, "HA 2 Bar SE");
#AddOrder(OrderType.BUY_TO_CLOSE, trendUp[-1], close[-1], tradeSize, Color.MAGENTA, Color.MAGENTA, "HA 2 Bar SX");
#end


LJJ
Hi Lensnewby, I tried to load this on my TOS and could not see anything showing the study??? Can you show us what it is supposed to look like??? I tried several different time frames... Thanks.
 
@JoeSD
This is a strategy so you need to create a new strategy and not a study. No autotrading in ToS, however it does give you an indication of a P and L, so you can get a report on how well the indicators work. On the Heiken-Ashi 2Grn/2Red strategy, I also use volume, MA crossovers and stochastics slow to confirm trades.
 
Last edited by a moderator:
We would like to see this strategy to enter, buy to open, on the 1st Green Heiken Ashi Bar and Sell to close on the first Red Heiken Ashi Bar and only do this if the MACD (Value) Fast line is above the MACD (Average) Slow line. I would also like to exit on the 5th consecutive Green HA bar or on the first Red HA bar if we have fewer than 5 consecutive Green HA bars. We should be able to change the number of bars to close.
See below, the results are impressive on a one year one day time scale even with my erroneous script. The red markers show where entries should not have happened.

#!st Green and MACD fast above slow (Value > Average)
#LJJ 2022 1115

def haClose = ohlc4;
def haOpen = if haOpen[1] == 0 then haClose[1] else (haOpen[1] + haClose[1]) / 2;
def haHigh = Max(high, Max(haClose, haOpen));
def haLow = Min(low, Min(haClose, haOpen));
def haColor = haClose > haOpen;
def trendUp = haColor and !haColor[1];

def trendDown = !haColor and haColor[1];


AddOrder(OrderType.BUY_to_OPEN, trendUp, MACD()."Value" is greater than MACD()."Avg" , tickColor = GetColor(0), arrowColor = GetColor(0), name = "LE");
AddOrder(OrderType.SELL_to_CLOSE, trendDown, MACD()."Value" is less than MACD()."Avg", tickColor = GetColor(1), arrowColor = GetColor(1), name = "LX");

LfaOsoD.jpg


IUr9o66.jpg


Any help would be very much appreciated!
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
370 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