TheoTrade Projection Pivots

Chuck

Moderator
Staff member
Lxry7Uf.png
Code:
# V01.08.2012 TheoTrade Projection Pivots
# mobius

declare Once_Per_Bar;

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

   def h = high;
   def l = low;
   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.Short_DASH);
  plot RExtension = if RExtend
                    then (bar - PHBar) * RSlope + PHL
                    else double.NaN;
       RExtension.SetStyle(Curve.Short_DASH);
       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.Short_DASH);
  plot SupportExtension = if SExtend
                          then (bar - PLBar) * SSlope + PLL
                          else double.NaN;
       SupportExtension.SetDefaultColor(GetColor(7));
       SupportExtension.SetStyle(Curve.Short_DASH);
  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));
       pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
       pivotDot.SetLineWeight(3);

# End Code TheoTrade Projection Pivots
 
Top