Repaints Heikin Ashi Hull TMO ZigZag Chart Setup

Repaints
Buy/Cover Short:
1. Hull MA 31 -> Color change
2. Buy signal from the ZigZag indicator (BonBon's shared code)
3. TMO bouncing off from the green zone
4. All the Levels are green (15,30 and 60)

Sell or Short:
1. Hull MA 31 -> Color change
2. Sell signal from the ZigZag indicator (BonBon's shared code)
3. TMO rejected from the red zone
4. All the Levels are red (15,30 and 60)

Targets are fib levels and Stop Loss the previous candle high
 
@BonBon Use this for wedges

Ruby:
##ASPA TRADER Projection Pivots for HA Candles

declare Once_Per_Bar;

input n = 21;
input showLines = no;
input showValues = no;
input showBarNumbers = no;

input period = 50;
input candleSmoothing = {default Valcu, Vervoort};
input movingAverageType = {default TEMA, Exponential, Weighted, Hull, Variable, SIMPLE};

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Simple:
    openMA = compoundValue(1, Average(open, period), open);
    closeMA = compoundValue(1, Average(close, period), close);
    highMA = compoundValue(1, Average(high, period), high);
    lowMA = compoundValue(1, Average(low, period), low);
case Exponential:
    openMA = compoundValue(1, ExpAverage(open, period), open);
    closeMA = compoundValue(1, ExpAverage(close, period), close);
    highMA = compoundValue(1, ExpAverage(high, period), high);
    lowMA = compoundValue(1, ExpAverage(low, period), low);
case Weighted:
    openMA = compoundValue(1, WMA(open, period), open);
    closeMA = compoundValue(1, WMA(close, period), close);
    highMA = compoundValue(1, WMA(high, period), high);
    lowMA = compoundValue(1, WMA(low, period), low);
Case Hull:
    openMA = compoundValue(1, HullMovingAvg(open, period), open);
    closeMA = compoundValue(1,  HullMovingAvg(close, period), close);
    highMA = compoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = compoundValue(1,  HullMovingAvg(low, period), low);
case variable:
    openMA = compoundValue(1, VariableMA(open, period), open);
    closeMA = compoundValue(1, VariableMA(close, period), close);
    highMA = compoundValue(1, VariableMA(high, period), high);
    lowMA = compoundValue(1, VariableMA(low, period), low);
case TEMA:
    openMA = compoundValue(1, TEMA(open, period), open);
    closeMA = compoundValue(1, TEMA(close, period), close);
    highMA = compoundValue(1, TEMA(high, period), high);
    lowMA = compoundValue(1, TEMA(low, period), low);
}


   def h = highMA;
   def l = lowMA;
   def bar = barNumber();
   def PH;
   def PL;
   def hh = fold i = 1 to n + 1
            with p = 1
            while p
            do h > getValue(h, -i);
       PH = if (bar > n and
                h == highest(h, n) and
                hh)
            then h
            else double.NaN;
   def ll = fold j = 1 to n + 1
            with q = 1
            while q
            do l < getValue(low, -j);
       PL = if (bar > n and
                l == lowest(l, n) and
                ll)
            then l
            else double.NaN;
   def PHBar = if !isNaN(PH)
               then bar
               else PHBar[1];
   def PLBar = if !isNaN(PL)
               then bar
               else PLBar[1];
   def PHL = if !isNaN(PH)
             then PH
             else PHL[1];
   def priorPHBar = if PHL != PHL[1]
                    then PHBar[1]
                    else priorPHBar[1];
   def PLL = if !isNaN(PL)
             then PL
             else PLL[1];
   def priorPLBar = if PLL != PLL[1]
                    then PLBar[1]
                    else priorPLBar[1];
   def HighPivots = bar >= highestAll(priorPHBar);
   def LowPivots = bar >= highestAll(priorPLBar);
   def FirstRpoint = if HighPivots
                     then bar - PHBar
                     else 0;
   def PriorRpoint = if HighPivots
                     then bar - PriorPHBar
                     else 0;
   def RSlope = (getvalue(PH, FirstRpoint) - getvalue(PH, PriorRpoint))
                       / (PHBar - PriorPHBar);
   def FirstSpoint = if LowPivots
                     then bar - PLBar
                     else 0;
   def PriorSpoint = if LowPivots
                     then bar - PriorPLBar
                     else 0;
   def SSlope = (getvalue(PL, FirstSpoint) - getvalue(PL, PriorSpoint))
                   / (PLBar - PriorPLBar);
   def RExtend = if bar == highestall(PHBar)
                 then 1
                 else RExtend[1];
   def SExtend = if bar == highestall(PLBar)
                 then 1
                 else SExtend[1];

  plot pivotHigh = if HighPivots
                   then PH
                   else double.NaN;
       pivotHigh.SetDefaultColor(GetColor(1));
       pivotHigh.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
       pivotHigh.setHiding(!showValues);
  plot pivotHighLine = if PHL > 0 and
                          HighPivots
                       then PHL
                       else double.NaN;
       pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);
       pivotHighLine.setHiding(!showLines);
  plot RLine = pivotHigh;
       RLine.enableApproximation();
       RLine.SetDefaultColor(GetColor(7));
       RLine.SetStyle(Curve.FIRM);
  plot RExtension = if RExtend
                    then (bar - PHBar) * RSlope + PHL
                    else double.NaN;
       RExtension.SetStyle(Curve.FIRM);
       RExtension.SetDefaultColor(GetColor(7));
  plot pivotLow = if LowPivots
                  then PL
                  else double.NaN;
       pivotLow.setDefaultColor(GetColor(4));
       pivotLow.setPaintingStrategy(PaintingStrategy.VALUES_BELOW);
       pivotLow.setHiding(!showValues);
  plot pivotLowLine = if PLL > 0 and
                         LowPivots
                      then PLL
                      else double.NaN;
       pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);
       pivotLowLine.setHiding(!showLines);
  plot SupportLine = pivotLow;
       SupportLine.enableApproximation();
       SupportLine.SetDefaultColor(GetColor(7));
       SUpportLine.SetStyle(Curve.FIRM);
  plot SupportExtension = if SExtend
                          then (bar - PLBar) * SSlope + PLL
                          else double.NaN;
       SupportExtension.SetDefaultColor(GetColor(7));
       SupportExtension.SetStyle(Curve.FIRM);
  plot BN = bar;
       BN.SetDefaultColor(GetColor(0));
       BN.setHiding(!showBarNumbers);
       BN.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
  plot PivotDot = if !isNaN(pivotHigh)
                  then pivotHigh
                  else if !isNaN(pivotLow)
                  then pivotLow
                  else double.NaN;
       pivotDot.SetDefaultColor(GetColor(7));
     

# End Code Projection Pivots
 
Modified Support and Resistance

Ruby:
## ProjectionPivots_v03_JQ
## 03.04.2019
## Original Code and Concept by Mobius:
# V01.08.2012 Projection Pivots
# mobius

# Notes:
# 03.04.2019 added linits on extensions
# 03.05.2019 adjusted limits on extensions by adding user input upper and lower extenion percent limits

#declare Once_Per_Bar;


## Inputs
input period = 50;
input n = 21;
input showLines = yes;
input showValues = no;
input showBarNumbers = no;
input ExtensionLengthBars = 20; # added to control length of Entension
input UpperExtensionPercentLimit = 5;
input LowerExtensionPercentLimit = 5;
input DisplayLabel = no;  ##  JQ 7.8.2018 added
    addlabel (DisplayLabel, "Projection Pivots n:" + n + " " , color.WHITE);  ##  JQ 7.8.2018 added

  
# Universal Header _v030429019 _JQ
#     code from various sources including Mobius, NoLongerNube and others
# Comment out unnecessary portions to preserve tos memory and enhance speed

# Universal Definitions using Padawan variable naming convention (JQ) v03.04.2019
# iData Definitions

input movingAverageType = {default TEMA, Exponential, Weighted, Hull, Variable, SIMPLE};

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Simple:
    openMA = compoundValue(1, Average(open, period), open);
    closeMA = compoundValue(1, Average(close, period), close);
    highMA = compoundValue(1, Average(high, period), high);
    lowMA = compoundValue(1, Average(low, period), low);
case Exponential:
    openMA = compoundValue(1, ExpAverage(open, period), open);
    closeMA = compoundValue(1, ExpAverage(close, period), close);
    highMA = compoundValue(1, ExpAverage(high, period), high);
    lowMA = compoundValue(1, ExpAverage(low, period), low);
case Weighted:
    openMA = compoundValue(1, WMA(open, period), open);
    closeMA = compoundValue(1, WMA(close, period), close);
    highMA = compoundValue(1, WMA(high, period), high);
    lowMA = compoundValue(1, WMA(low, period), low);
Case Hull:
    openMA = compoundValue(1, HullMovingAvg(open, period), open);
    closeMA = compoundValue(1,  HullMovingAvg(close, period), close);
    highMA = compoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = compoundValue(1,  HullMovingAvg(low, period), low);
case variable:
    openMA = compoundValue(1, VariableMA(open, period), open);
    closeMA = compoundValue(1, VariableMA(close, period), close);
    highMA = compoundValue(1, VariableMA(high, period), high);
    lowMA = compoundValue(1, VariableMA(low, period), low);
case TEMA:
    openMA = compoundValue(1, TEMA(open, period), open);
    closeMA = compoundValue(1, TEMA(close, period), close);
    highMA = compoundValue(1, TEMA(high, period), high);
    lowMA = compoundValue(1, TEMA(low, period), low);
}


    def vHigh = highMA;  # creates the variable vHigh.  Use of the variable reduce data calls to tos iData server
#    def initHigh =  CompoundValue(1, highMA, highMA);  # creates and initialized variable for High
    def vLow = lowMA;
#    def initLow = CompoundValue(1, lowMA, lowMA);
    def vOpen = openMA;
#    def initOpen = CompoundValue(1, openMA, openMA);
    def vClose = closeMA;
#    def initClose = CompoundValue(1, closeMA, closeMA);
    def vVolume = volume;
#    def initVolume = CompoundValue(1, volume, volume);
    def nan = Double.NaN;
# Bar Time & Date 
    def bn = BarNumber();
    def currentBar = HighestAll(if !IsNaN(vHigh) then bn else nan);
#    def Today = GetDay() ==GetLastDay();
#    def time = GetTime();
#    def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
    # def globeX_v2 = if time crosses below RegularTradingEnd(GetYYYYMMDD()) then bn else GlobeX[1];
#    def RTS  = RegularTradingStart(GetYYYYMMDD());
#    def RTE  = RegularTradingEnd(GetYYYYMMDD());
#    def RTH = GetTime() > RegularTradingStart(GetYYYYMMDD());
#    def RTH_v2 = if time crosses above RegularTradingStart(GetYYYYMMDD()) then bn else RTH[1];

# bars that start and end the sessions  #(borrowed from nube)
#    def rthStartBar    = CompoundValue(1,
#                         if   !IsNaN(vClose)
#                         &&   time crosses above RegularTradingStart(GetYYYYMMDD())
#                         then bn
#                         else rthStartBar[1], 0);
#    def rthEndBar      = CompoundValue(1,
#                         if   !IsNaN(vClose)
#                         &&   time crosses above RegularTradingEnd(GetYYYYMMDD())
#                         then bn
#                         else rthEndBar[1], 1);
#    def globexStartBar = CompoundValue(1,
#                         if   !IsNaN(vClose)
#                         &&   time crosses below RegularTradingEnd(GetYYYYMMDD())
#                         then bn
#                         else globexStartBar[1], 1);
#    def rthSession = if   bn crosses above rthStartBar #+ barsExtendedBeyondSession
#                     then 1
#                     else if   bn crosses above rthEndBar #+ barsExtendedBeyondSession
#                          then 0
#                     else rthSession[1];


# Bubble Locations
    def x_AxisLastExpansionBar = BarNumber() == HighestAll(BarNumber());  #corrected 11.12.2018 (JQ)   
        # syntax: addChartBubble(x_AxisLastExpansionBar, y-axis coordinate," text", Color.LIME); #verified 12.25.2018 (JQ)



def PH;
   def PL;
   def hh = fold i = 1 to n + 1
            with p = 1
            while p
            do vHigh > getValue(vHigh, -i);
       PH = if (bn > n and
                vHigh == highest(vHigh, n) and
                hh)
            then vHigh
            else double.NaN;
   def ll = fold j = 1 to n + 1
            with q = 1
            while q
            do vLow < getValue(lowMA, -j);
       PL = if (bn > n and
                vLow == lowest(vLow, n) and
                ll)
            then vLow
            else double.NaN;
   def PHBar = if !isNaN(PH)
               then bn
               else PHBar[1];
   def PLBar = if !isNaN(PL)
               then bn
               else PLBar[1];
   def PHL = if !isNaN(PH)
             then PH
             else PHL[1];
   def priorPHBar = if PHL != PHL[1]
                    then PHBar[1]
                    else priorPHBar[1];
   def PLL = if !isNaN(PL)
             then PL
             else PLL[1];
   def priorPLBar = if PLL != PLL[1]
                    then PLBar[1]
                    else priorPLBar[1];
   def HighPivots = bn >= highestAll(priorPHBar);
   def LowPivots = bn >= highestAll(priorPLBar);
   def FirstRpoint = if HighPivots
                     then bn - PHBar
                     else 0;
   def PriorRpoint = if HighPivots
                     then bn - PriorPHBar
                     else 0;
   def RSlope = (getvalue(PH, FirstRpoint) - getvalue(PH, PriorRpoint))
                       / (PHBar - PriorPHBar);
   def FirstSpoint = if LowPivots
                     then bn - PLBar
                     else 0;
   def PriorSpoint = if LowPivots
                     then bn - PriorPLBar
                     else 0;
   def SSlope = (getvalue(PL, FirstSpoint) - getvalue(PL, PriorSpoint))
                   / (PLBar - PriorPLBar);
   def RExtend = if bn == highestall(PHBar)
                 then 1
                 else RExtend[1];
   def SExtend = if bn == highestall(PLBar)
                 then 1
                 else SExtend[1];

  plot pivotHigh = if HighPivots
                   then PH
                   else double.NaN;
       pivotHigh.SetDefaultColor(GetColor(1));
       pivotHigh.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
       pivotHigh.setHiding(!showValues);
      
  plot pivotHighLine = if PHL > 0 and
                          HighPivots
                       then PHL
                       else double.NaN;
       pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);  # Mobius original was DASHES
       pivotHighLine.setDefaultColor(color.uptick);  ##  JQ 7.8.2018 added
       pivotHighLine.setHiding(!showLines);
 
  plot RLine = pivotHigh;
       RLine.enableApproximation();
       RLine.SetDefaultColor(Color.LIGHT_GRAY);
       RLine.SetStyle(Curve.Short_DASH);

# Added code to limit resistance estension line (JQ 03.04.2019)
  def calc_ResistanceExtension = if RExtend
                    then (bn - PHBar) * RSlope + PHL
                    else double.NaN;
  plot line_ResistanceExtension = if bn <= (Currentbar + ExtensionLengthBars)
                                   and calc_ResistanceExtension[1] >=  (lowestall(vLow) * (1-(lowerExtensionPercentLimit/100)))
                                   and calc_ResistanceExtension[1] <= (Highestall(vHigh) * (1 + (upperExtensionPercentLimit/100)))
                               then calc_ResistanceExtension else double.nan;
       line_ResistanceExtension.SetStyle(Curve.Short_DASH);
       line_ResistanceExtension.SetDefaultColor(color.LIGHT_GRAY); #was 7
       line_ResistanceExtension.setLineWeight(1); 



# Low Plots
  plot pivotLow = if LowPivots
                  then PL
                  else double.NaN;
       pivotLow.setDefaultColor(GetColor(4));
       pivotLow.setPaintingStrategy(PaintingStrategy.VALUES_BELOW);
       pivotLow.setHiding(!showValues);
 
  plot pivotLowLine = if PLL > 0 and
                         LowPivots
                      then PLL
                      else double.NaN;
       pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);  # Mobius original was DASHES
       pivotLowLine.setDefaultColor(color.DOWNTICK);#  #  JQ 7.8.2018 added
       pivotLowLine.setHiding(!showLines);

  plot SupportLine = pivotLow;
       SupportLine.enableApproximation();
       SupportLine.SetDefaultColor(color.LIGHT_GRAY);
       SUpportLine.SetStyle(Curve.Short_DASH);

# Added code to limit support estension line (JQ 03.04.2019)
  def calc_SupportExtension = if SExtend
                          then (bn - PLBar) * SSlope + PLL
                          else double.NaN;
  plot line_SupportExtension = if bn <= (Currentbar + ExtensionLengthBars)
                                   and calc_SupportExtension[1] >= (lowestall(vLow) * (1-(lowerExtensionPercentLimit/100)))
                                   and calc_SupportExtension[1] <= (Highestall(vHigh) * (1 + (upperExtensionPercentLimit/100)))
                               then calc_supportExtension else double.nan;
       line_SupportExtension.SetDefaultColor(color.LIGHT_GRAY); #was 7
       line_SupportExtension.SetStyle(Curve.Short_DASH);
       line_SupportExtension.setLineWeight(1);

  plot BarNumbersBelow = bn;
       BarNumbersBelow.SetDefaultColor(GetColor(0));
       BarNumbersBelow.setHiding(!showBarNumbers);
       BarNumbersBelow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

  plot PivotDot = if !isNaN(pivotHigh)
                  then pivotHigh
                  else if !isNaN(pivotLow)
                  then pivotLow
                  else double.NaN;
       pivotDot.SetDefaultColor(GetColor(7));
       pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
       pivotDot.SetLineWeight(3);
      



# End Code
 

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
491 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