• Get $40 off VIP by signing up for a free account! Sign Up

Heiken Ashi Pivot "Strategy" for ThinkOrSwim


New member
Hi everyone. I've been playing around with this Heiken Ashi alerting script from mobius. I'm not having any luck getting it to plot on my charts. Am I missing something simple in my chart setup or is it something in the code? Appreciate any help or if it is working on others ToS charts. thanks.

# Heiken Ashi Pivot "Strategy"
# Mobius
# V01.08.2018
# Entries marked by arrows. Risk would be prior pivot lines or whatever your comfortable with. Target would be breach of next pivot generated. Needs some more work.

def x = barNumber();
def nan = Double.NaN;
def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and
          getTime() <= RegularTradingEnd(getYYYYMMDD());
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = Round((CompoundValue(1, HAopen[1] + HAclose[1], open[1] + close)/2) / TickSize(), 0) * TickSize();
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
haclose = (HAopen + HAhigh + HAlow + HAclose[1]) / 4;
AssignPriceColor(if HAclose > HAopen
                 then color.green
                 else color.red);
def up = if HAclose crosses above HAopen
         then HAclose + TickSize()
         else up[1];
def upX = if HAclose crosses above HAopen
          then x
          else nan;
plot upLine = if x >= highestAll(upX)
              then highestAll(if isNaN(close[-1])
                              then up
                              else nan)
              else nan;
plot upArrow = if close crosses above upLine
               then low - TickSize()
               else nan;
def dn = if HAclose crosses below HAopen
         then low - TickSize()
         else dn[1];
def dnX = if HAclose crosses below HAopen
          then x
          else nan;
plot dnLine = if x >= highestAll(dnX)
              then highestAll(if isNaN(close[-1])
                              then dn
                              else nan)
              else nan;
plot dnArrow = if close crosses below dnLine
               then high + TickSize()
               else nan;
# End Code HA Pivot Strategy
addOrder(OrderType.BUY_AUTO, RTH and HAclose crosses above up, up, name = "BTO " + HAopen[-1]);
addOrder(OrderType.Sell_Auto, RTH and HAclose crosses below dn, dn, name = "STO " + HAopen[-1]);
addOrder(OrderType.Sell_To_Close, !RTH and RTH[1], name = "EOD-S");
addOrder(OrderType.Buy_To_Close, !RTH and RTH[1], name = "EOD-B");
# End Code
Worked for me on the daily chart. The obvious question is: did you add this as a strategy?

Because I keep making that same mistake :)
This^^ Be sure you go to "Create" to post the code while on the strategy tab and not the study tab or it won't show up
Is there a reason this does not work on a Daily chart only lower time frames?
can you explain what this strategy is? thanks
The code in the top post is a chopped up version of Mobius's Trend Pivots. Here is a working one:

If you are just looking for the HA flip. Here are a dozen flavor of scanners:

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
132 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.