Heiken Ashi Pivot "Strategy" for ThinkOrSwim

borntostun

New member
Lifetime
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.

Code:
# 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;
     upLine.SetDefaultColor(Color.Green);
plot upArrow = if close crosses above upLine
               then low - TickSize()
               else nan;
     upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
     upArrow.SetLineWeight(3);
     upArrow.SetDefaultColor(Color.Green);
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;
     dnLine.SetDefaultColor(Color.Red); 
plot dnArrow = if close crosses below dnLine
               then high + TickSize()
               else nan;
     dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
     dnArrow.SetLineWeight(3);
     dnArrow.SetDefaultColor(Color.Red);           
# 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
 

mfsteve

Member
VIP
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 :)
 

wtf_dude

Active member
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
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
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:
https://usethinkscript.com/threads/trend-pivot-indicator-by-mobius-for-thinkorswim.1631/

If you are just looking for the HA flip. Here are a dozen flavor of scanners:
https://usethinkscript.com/threads/heiken-ashi-scan.7501/
 

Similar threads

Top