Pivot Point Indicator

aaronmib

New member
I am looking for an indicator that is like the image below with pivot lines extending off the pivot high or pivot low (ignore the three hand drawn objects). I would like the lines coming off the pivot highs to extend to the right until the next pivot high starts. Same for pivot lows. I found the attached code on this site and it is really close to what I want, but the horizontal line coming off the pivot point extends all the way to the right of the chart. Does anyone know where I can find code for the image below or how to modify code to truncate the line when the next pivot starts
WAS07WZ.png


Code:
# Pivot_Array (***Please copy and paste this name to study name above***)
# Mobius
# V01.09.13.2017
#hint: Plots the most recent 4 resistance pivots and support pivots. \n For scanning: Find the study in list of studies then select either BearScan or BullScan as the left side entry in the Scan Wizard and equal to as the center definition and close price as the right side entry.

# User Inputs
input n = 7; #hint n: periods used for pivot calculations.

# Internal Script Reference
script LinePlot {
    input BarID = 0;
    input Value = 0;
    input BarOrigin = 0;
    def ThisBar = HighestAll(BarOrigin);
    def ValueLine = if BarOrigin == ThisBar
                then Value
                else Double.NaN;
    plot P = if ThisBar - BarID <= BarOrigin
             then HighestAll(ValueLine)
             else Double.NaN;
}
# Variables
def o = open;
def h = high;
def l = low;
def c = close;
def bar = BarNumber();
def BBar = bar == HighestAll(bar);
# Parent High
def ParentHigh = HighestAll(h);
def ParentHBarOrigin = if h == ParentHigh
                       then bar
                       else ParentHBarOrigin[1];
def ParentHBarID = bar - HighestAll(ParentHBarOrigin);
# R1
def hh = fold i = 1 to n + 1
         with p = 1
         while p
         do h > GetValue(h, -i);
def PivotH = if (bar > n and
                 h == Highest(h, n) and
                 hh)
            then h
            else Double.NaN;
def PHValue = if !IsNaN(PivotH)
              then PivotH
              else PHValue[1];
def PHBarOrigin = if !IsNaN(PivotH)
                  then bar
                  else PHBarOrigin[1];
def PHBarID = bar - PHBarOrigin;
# R2
def R2PHValue = if PHBarOrigin != PHBarOrigin[1]
              then PHValue[1]
              else R2PHValue[1];
def R2PHBarOrigin = if PHBarOrigin != PHBarOrigin[1]
                  then PHBarOrigin[1]
                  else R2PHBarOrigin[1];
def R2PHBarID = bar - R2PHBarOrigin;
# R3
def R3PHValue = if R2PHBarOrigin != R2PHBarOrigin[1]
              then R2PHValue[1]
              else R3PHValue[1];
def R3PHBarOrigin = if R2PHBarOrigin != R2PHBarOrigin[1]
                  then R2PHBarOrigin[1]
                  else R3PHBarOrigin[1];
def R3PHBarID = bar - R3PHBarOrigin;
# R4
def R4PHValue = if R3PHBarOrigin != R3PHBarOrigin[1]
              then R3PHValue[1]
              else R4PHValue[1];
def R4PHBarOrigin = if R3PHBarOrigin != R3PHBarOrigin[1]
                  then R3PHBarOrigin[1]
                  else R4PHBarOrigin[1];
def R4PHBarID = bar - R4PHBarOrigin;

# Parent Low
def ParentLow = LowestAll(l);
def ParentLBarOrigin = if l == ParentLow
                       then bar
                       else ParentLBarOrigin[1];
def ParentLBarID = bar - HighestAll(ParentLBarOrigin);
# S1
def ll = fold j = 1 to n + 1
         with q = 1
         while q
         do l < GetValue(l, -j);
def PivotL = if (bar > n and
                 l == Lowest(l, n) and
                 ll)
             then l
             else Double.NaN;
def PLValue = if !IsNaN(PivotL)
              then PivotL
              else PLValue[1];
def PLBarOrigin = if !IsNaN(PivotL)
                  then bar
                  else PLBarOrigin[1];
def PLBarID = bar - PLBarOrigin;
# S2
def S2PLValue = if PLBarOrigin != PLBarOrigin[1]
              then PLValue[1]
              else S2PLValue[1];
def S2PLBarOrigin = if PLBarOrigin != PLBarOrigin[1]
                  then PLBarOrigin[1]
                  else S2PLBarOrigin[1];
def S2PLBarID = bar - S2PLBarOrigin;
def S2BarID = barnumber();

# S3
def S3PLValue = if S2PLBarOrigin != S2PLBarOrigin[1]
              then S2PLValue[1]
              else S3PLValue[1];
def S3PLBarOrigin = if S2PLBarOrigin != S2PLBarOrigin[1]
                  then S2PLBarOrigin[1]
                  else S3PLBarOrigin[1];
def S3PLBarID = bar - S3PLBarOrigin;
# S4
def S4PLValue = if S3PLBarOrigin != S3PLBarOrigin[1]
              then S3PLValue[1]
              else S4PLValue[1];
def S4PLBarOrigin = if S3PLBarOrigin != S3PLBarOrigin[1]
                  then S3PLBarOrigin[1]
                  else S4PLBarOrigin[1];
def S4PLBarID = bar - S4PLBarOrigin;

# Plots
plot PR1 = LinePlot(BarID = ParentHBarID,
                    Value = ParentHigh,
                    BarOrigin = HighestAll(ParentHBarOrigin));
     PR1.SetDefaultColor(Color.GREEN);
#addChartBubble(Bar == HighestAll(ParentHBarOrigin), ParentHigh, "High", color.yellow, 1);


plot R1 = LinePlot(BarID = PHBarID,
                   Value = PHValue,
                   BarOrigin = PHBarOrigin);
     R1.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(PHBarOrigin), PHvalue, "R1", color.green, 1);



plot R2 = LinePlot(BarID = R2PHBarID,
                   Value = R2PHValue,
                   BarOrigin = R2PHBarOrigin);
     R2.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R2PHBarOrigin), PHvalue, "R2", color.green, 1);
plot R3 = LinePlot(BarID = R3PHBarID,
                   Value = R3PHValue,
                   BarOrigin = R3PHBarOrigin);
     R3.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R3PHBarOrigin), PHvalue, "R3", color.green, 1);
plot R4 = LinePlot(BarID = R4PHBarID,
                   Value = R4PHValue,
                   BarOrigin = R4PHBarOrigin);
     R4.SetDefaultColor(Color.GREEN);
addChartBubble(Bar == HighestAll(R4PHBarOrigin), PHvalue, "R4", color.green, 1);

plot PS1 = LinePlot(BarID = ParentLBarID,
                   Value = ParentLow,
                   BarOrigin = HighestAll(ParentLBarOrigin));
     PS1.SetDefaultColor(Color.RED);


plot S1 = LinePlot(BarID = PLBarID,
                   Value = PLValue,
                   BarOrigin = PLBarOrigin);
     S1.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(PLBarOrigin), PLvalue, "S1", color.red, 0);

plot S2 = LinePlot(BarID = S2PLBarID,
                    Value = S2PLValue,
                    BarOrigin = S2PLBarOrigin);
     S2.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S2PLBarOrigin), PLvalue, "S2", color.red, 0);

plot S3 = LinePlot(BarID = S3PLBarID,
                   Value = S3PLValue,
                   BarOrigin = S3PLBarOrigin);
     S3.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S3PLBarOrigin), PLvalue, "S3", color.red, 0);



plot S4 = LinePlot(BarID = S4PLBarID, Value = S4PLValue, BarOrigin = S4PLBarOrigin);
     S4.SetDefaultColor(Color.RED);
addChartBubble(Bar == HighestAll(S4PLBarOrigin), PLvalue, "S4", color.red, 0);

# Signals
def UpSignal;
def DnSignal;
if close crosses above R4
{
    UpSignal = low;
}
else if close crosses above R3
{
    UpSignal = low;
}
else if close crosses above R2
{
    UpSignal = low;
}
else if close crosses above R1
{
    UpSignal = low;
}
else
{
    UpSignal = UpSignal[1];
}
plot UpArrows = if low == UpSignal
                then low
                else double.nan;
     UpArrows.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
     UpArrows.SetDefaultColor(Color.CYAN);
if close crosses below S1
{
    DnSignal = high;
}
else if close crosses below S2
{
    DnSignal = high;
}
else if close crosses below S3
{
    DnSignal = high;
}
else if close crosses below S4
{
    DnSignal = high;
}
else
{
    DnSignal = DnSignal[1];
}
plot DnArrow = if high == DnSignal
               then high
               else double.nan;
DnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
DnArrow.SetDefaultColor(Color.YELLOW);
plot BearScan = if (close crosses below S1) OR
                   (close crosses below S2)
                then close
                else double.nan;
plot BullScan = if (close crosses above R1) OR
                   (close crosses above R2)
                then close
                else double.nan;
# End Code Fractal Array
 
Solution
This is the modified code that I use, highly modified based on existing code... The lower image has mid bands turned off...

Ruby:
# Support_and_Resistance_Lite
# Modified version of: Programmatic Support and Resistance for Thinkorswim
# https://usethinkscript.com/threads/programmatic-support-and-resistance-for-thinkorswim.55/
# Modified for personal use by rad14733
# v1.0 : 2022-05-31 : Initial release
# v1.1 : 2023-02-09 : Modified to use GlobalColors and added Support and Resistance price labels
# v1.2 : 2023-02-13 : Added S/R midLine and deadZone squeeze cloud
# v1.3 : 2023-12-21 : Added QtrLines between MidLine and Support/Resistance

declare upper;

DefineGlobalColor("SRdiffUp", Color.UPTICK);
DefineGlobalColor("SRdiffDn"...
This is the modified code that I use, highly modified based on existing code... The lower image has mid bands turned off...

Ruby:
# Support_and_Resistance_Lite
# Modified version of: Programmatic Support and Resistance for Thinkorswim
# https://usethinkscript.com/threads/programmatic-support-and-resistance-for-thinkorswim.55/
# Modified for personal use by rad14733
# v1.0 : 2022-05-31 : Initial release
# v1.1 : 2023-02-09 : Modified to use GlobalColors and added Support and Resistance price labels
# v1.2 : 2023-02-13 : Added S/R midLine and deadZone squeeze cloud
# v1.3 : 2023-12-21 : Added QtrLines between MidLine and Support/Resistance

declare upper;

DefineGlobalColor("SRdiffUp", Color.UPTICK);
DefineGlobalColor("SRdiffDn", Color.DOWNTICK);
DefineGlobalColor("SRdiffNeutral", Color.LIGHT_GRAY);
DefineGlobalColor("Resistance", Color.MAGENTA);
DefineGlobalColor("MidLine", Color.CYAN);
DefineGlobalColor("Support", Color.VIOLET);
DefineGlobalColor("QtrLines", Color.DARK_ORANGE);

input LookbackPeriod = 5;
input dzAtrLength = 14;
input dzAtrMult = 3.00;
input showDzCloud = yes;
input showMidLine = yes;
input showQtrLines = yes;
input showValues = yes;
input showSRdiff = yes;


def _highInPeriod = Highest(high, LookbackPeriod);
def _lowInPeriod = Lowest(low, LookbackPeriod);

def marketLow = if _lowInPeriod < _lowInPeriod[-LookbackPeriod] then _lowInPeriod else _lowInPeriod[-LookbackPeriod];
def _markedLow = low == marketLow;

rec _lastMarkedLow = CompoundValue(1, if IsNaN(_markedLow) then _lastMarkedLow[1] else if _markedLow then low else _lastMarkedLow[1], low);

def marketHigh = if _highInPeriod > _highInPeriod[-LookbackPeriod] then _highInPeriod else _highInPeriod[-LookbackPeriod];
def _markedHigh = high == marketHigh;

rec _lastMarkedHigh = CompoundValue(1, if IsNaN(_markedHigh) then _lastMarkedHigh[1] else if _markedHigh then high else _lastMarkedHigh[1], high);

plot Resistance = _lastMarkedHigh;
Resistance.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance.SetDefaultColor(GlobalColor("Resistance"));
Resistance.SetLineWeight(2);

plot Support = _lastMarkedLow;
Support.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support.SetDefaultColor(GlobalColor("Support"));
Support.SetLineWeight(2);

plot MidLine = if showMidLine then (Resistance + Support) / 2 else Double.NaN;
MidLine.SetDefaultColor(GlobalColor("MidLine"));
MidLine.SetLineWeight(2);

AddLabel(showValues, "Res: " + Round(Resistance, 2), GlobalColor("Resistance"));

AddLabel(showValues, "Mid: " + Round(MidLine, 2), GlobalColor("MidLine"));

AddLabel(showValues, "Sup: " + Round(Support, 2), GlobalColor("Support"));

def SRdiff = Round(Resistance - Support, 2);

AddLabel(showSRdiff, "SRdiff: " + Round(SRdiff, 2), if SRdiff > SRdiff[1] then GlobalColor("SRdiffUp") else if SRdiff < SRdiff[1] then GlobalColor("SRdiffDn") else GlobalColor("SRdiffNeutral"));

def dzCloud = if SRdiff < Round(ATR(dzAtrLength), 1) * dzAtrMult and between(close, Support, Resistance) then 1 else 0;

AddCloud(if dzCloud and showDzCloud then Resistance else Double.NaN, if dzCloud then Support else Double.NaN, GlobalColor("SRdiffDn"), Color.CURRENT);

# Quarter Lines
plot UpperMidLine = if showQtrLines then (Resistance + MidLine) / 2 else Double.NaN;
UpperMidLine.SetDefaultColor(GlobalColor("QtrLines"));
UpperMidLine.SetLineWeight(2);

plot LowerMidLine = if showQtrLines then (Support + MidLine) / 2 else Double.NaN;
LowerMidLine.SetDefaultColor(GlobalColor("QtrLines"));
LowerMidLine.SetLineWeight(2);

# END - Support_and_Resistance_Lite

1715707049559.png


1715707144691.png
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
323 Online
Create Post

Similar threads

Similar threads

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