Auto Pivot Points Support & Resistance Indicator for ThinkorSwim

@jrchezz Happy Birthday

Hello, Horserider - I'm providing the code for the Support Resistance that I would like to start trading with but only after some testing. I'm hoping you could insert an alert for when the LowSwing and HighSwing Up/Down Arrows appear. Take care partner, Jr.
Code:
declare upper;
input LookbackPeriod = 5;
input HideCurrentTF = no;
input HideTimeFrame2 = no;
input HideTimeFrame3 = no;
input TimeFrame2 = {default "15 MIN", "1 MIN", "2 MIN", "3 MIN", "4 MIN", "5 MIN", "10 MIN", "20 MIN", "30 MIN", "1 HOUR", "2 HOURS", "4 HOURS", DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH, "OPT EXP"};
input TimeFrame3 = {default "30 MIN", "1 MIN", "2 MIN", "3 MIN", "4 MIN", "5 MIN", "10 MIN", "15 MIN", "20 MIN", "1 HOUR", "2 HOURS", "4 HOURS", DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH, "OPT EXP"};
input HideSwings = no;
input SwingsLagBar = 1;
#--------------------------------------------------------------
def _highInPeriod1 = Highest(high, LookbackPeriod);
def _lowInPeriod1 = Lowest(low, LookbackPeriod);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod];
def _markedLow1 = low == marketLow1;
rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow1[1] else if _markedLow1 then low else _lastMarkedLow1[1], low);
#--------------------------------------------------------------
def marketHigh1 = if _highInPeriod1 > _highInPeriod1[-LookbackPeriod] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod];
def _markedHigh1 = high == marketHigh1;
rec _lastMarkedHigh1 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh1[1] else if _markedHigh1 then high else _lastMarkedHigh1[1], high);
#--------------------------------------------------------------
plot Resistance1 = _lastMarkedHigh1;
plot Support1 = _lastMarkedLow1;
#--------------------------------------------------------------
Resistance1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance1.SetDefaultColor(Color.GREEN);
Resistance1.SetHiding(HideCurrentTF);
#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support1.SetDefaultColor(Color.RED);
Support1.SetHiding(HideCurrentTF);
#--------------------------------------------------------------
def LowSwingForw = Lowest(low, SwingsLagBar)[-SwingsLagBar];
def LowSwingBack = Lowest(low, LookbackPeriod)[1];
def SwingLow = if low < LowSwingForw and low <= LowSwingBack then 1 else 0;
plot LowSwing = if SwingLow then low else Double.NaN;
#--------------------------------------------------------------
def HighSwingForw = Highest(high, SwingsLagBar)[-SwingsLagBar];
def HighSwingBack = Highest(high, LookbackPeriod)[1];
def SwingHigh = if high > HighSwingForw and high >= HighSwingBack then 1 else 0;
plot HighSwing = if SwingHigh then high else Double.NaN;
#--------------------------------------------------------------
HighSwing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
HighSwing.SetLineWeight(5);
HighSwing.SetDefaultColor(Color.RED);
HighSwing.SetHiding(HideSwings);
LowSwing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
LowSwing.SetLineWeight(5);
LowSwing.SetDefaultColor(Color.GREEN);
LowSwing.SetHiding(HideSwings);
#--------------------------------------------------------------
Alert(HighSwing, "SupRes : Swing High", Alert.BAR, Sound.Bell);
Alert(LowSwing, "SupRes : Swing Low", Alert.BAR, Sound.Bell);
#--------------------------------------------------------------
AddLabel(HighSwing, "SupRes : Swing High", Color.RED);
AddLabel(LowSwing, "SupRes : Swing Low", Color.GREEN);
#--------------------------------------------------------------
def _highInPeriod2 = Highest(high(period = TimeFrame2), LookbackPeriod);
def _lowInPeriod2 = Lowest(low(period = TimeFrame2), LookbackPeriod);
#--------------------------------------------------------------
def marketLow2 = if _lowInPeriod2 < _lowInPeriod2[-LookbackPeriod] then _lowInPeriod2 else _lowInPeriod2[-LookbackPeriod];
def _markedLow2 = low(period = TimeFrame2) == marketLow2;
rec _lastMarkedLow2 = CompoundValue(1, if IsNaN(_markedLow2) then _lastMarkedLow2[1] else if _markedLow2 then low(period = TimeFrame2) else _lastMarkedLow2[1], low(period = TimeFrame2));
#--------------------------------------------------------------
def marketHigh2 = if _highInPeriod2 > _highInPeriod2[-LookbackPeriod] then _highInPeriod2 else _highInPeriod2[-LookbackPeriod];
def _markedHigh2 = high(period = TimeFrame2) == marketHigh2;
rec _lastMarkedHigh2 = CompoundValue(1, if IsNaN(_markedHigh2) then _lastMarkedHigh2[1] else if _markedHigh2 then high(period = TimeFrame2) else _lastMarkedHigh2[1], high(period = TimeFrame2));
#--------------------------------------------------------------
plot Resistance2 = _lastMarkedHigh2;
plot Support2 = _lastMarkedLow2;
#--------------------------------------------------------------
Resistance2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance2.SetDefaultColor(Color.GREEN);
Resistance2.SetHiding(HideTimeFrame2);
#--------------------------------------------------------------
Support2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support2.SetDefaultColor(Color.RED);
Support2.SetHiding(HideTimeFrame2);
#--------------------------------------------------------------
def _highInPeriod3 = Highest(high(period = TimeFrame3), LookbackPeriod);
def _lowInPeriod3 = Lowest(low(period = TimeFrame3), LookbackPeriod);
#--------------------------------------------------------------
def marketLow3 = if _lowInPeriod3 < _lowInPeriod3[-LookbackPeriod] then _lowInPeriod3 else _lowInPeriod3[-LookbackPeriod];
def _markedLow3 = low(period = TimeFrame3) == marketLow3;
rec _lastMarkedLow3 = CompoundValue(1, if IsNaN(_markedLow3) then _lastMarkedLow3[1] else if _markedLow3 then low(period = TimeFrame3) else _lastMarkedLow3[1], low(period = TimeFrame3));
#--------------------------------------------------------------
def marketHigh3 = if _highInPeriod3 > _highInPeriod3[-LookbackPeriod] then _highInPeriod3 else _highInPeriod3[-LookbackPeriod];
def _markedHigh3 = high(period = TimeFrame3) == marketHigh3;
rec _lastMarkedHigh3 = CompoundValue(1, if IsNaN(_markedHigh3) then _lastMarkedHigh3[1] else if _markedHigh3 then high(period = TimeFrame3) else _lastMarkedHigh3[1], high(period = TimeFrame3));
#--------------------------------------------------------------
plot Resistance3 = _lastMarkedHigh3;
plot Support3 = _lastMarkedLow3;
#--------------------------------------------------------------
Resistance3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance3.SetDefaultColor(Color.GREEN);
Resistance3.SetHiding(HideTimeFrame3);
#--------------------------------------------------------------
Support3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support3.SetDefaultColor(Color.RED);
Support3.SetHiding(HideTimeFrame3);
 
@jrchezz All you need to do is to just append the following two statements to the end of your study and you'll have the alerts for the arrows all set to go

Code:
Alert(HighSwing, "High Swing", Alert.BAR, Sound.Ring);
Alert(LowSwing, "Low Swing", Alert.BAR, Sound.Bell);
 
Pivot Study with Audible Alarms for Buy/Sell.... this is a mobious study, and definitely worth a try it also paints buy/sell wedges.

Code:
# Mobius
####EVANB ADDED CODE AT THE BOTTOM
# V01.08.2012

input n = 1;
input showLines = yes;
input showValues = Yes;
input showBarNumbers = no;

# 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;
}
   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 PriorPH = if PHL != PHL[1]
                 then PHL[1]
                 else PriorPH[1];
   def PLL = if !isNaN(PL)
             then PL
             else PLL[1];
   def PriorPLBar = if PLL != PLL[1]
                    then PLBar[1]
                    else priorPLBar[1];
   def PriorPL = if PLL != PLL[1]
                 then PLL[1]
                 else PriorPL[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 PriorPHLine = LinePlot(PriorRPoint, PriorPH, PriorPHBar);
       PriorPHLine.SetStyle(Curve.Firm);
       PriorPHLine.SetDefaultColor(Color.Red);
  plot PivotHighLine = LinePlot(FirstRPoint, PH, PHBar);
       PivotHighLine.SetStyle(Curve.Firm);
       PivotHighLine.SetDefaultColor(Color.Red);
  plot pivotHigh = if HighPivots
                   then PH
                   else double.NaN;
       pivotHigh.SetDefaultColor(GetColor(1));
       pivotHigh.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
       pivotHigh.setHiding(!showValues);
  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 PriorPLLine = LinePlot(PriorSPoint, PriorPL, PriorPLBar);
       PriorPLLine.SetStyle(Curve.Firm);
       PriorPLLine.SetDefaultColor(Color.Green);
  plot PivotLowLine = LinePlot(FirstSPoint, PL, PLBar);
       PivotLowLine.SetStyle(Curve.Firm);
       PivotLowLine.SetDefaultColor(Color.Green);
  plot pivotLow = if LowPivots
                   then PL
                   else double.NaN;
       pivotLow.SetDefaultColor(GetColor(1));
       pivotLow.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
       pivotLow.setHiding(!showValues);
  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);


### EvanB #######
    plot buy = close[1] > pivotHighLine and high>high[1];
           buy.setPaintingstrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
           buy.SetDefaultColor(Color.green);

    plot sell = close[1] < pivotlowline  and low < low[1];      
       sell.setPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
        sell.SetDefaultColor(Color.pink);
plot bo = close>open and high>high[1] and close > rextension;
bo.setPaintingstrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
           bo.SetDefaultColor(Color.green);
plot bd = close<open and low<low[1] and close < supportextension;
bd.setPaintingstrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
           bd.SetDefaultColor(Color.pink);

Alert(condition = buy, text = "Buy", "alert type" = Alert.BAR, sound = Sound.Ding);
Alert(condition = sell, text = "Sell", "alert type" = Alert.BAR, sound = Sound.Ding);
Alert(condition = bo, text = "Breakout", "alert type" = Alert.BAR, sound = Sound.Ring);
Alert(condition = bd, text = "Breakdown", "alert type" = Alert.BAR, sound = Sound.Ring);
 
Last edited by a moderator:
0taUKis.png


I've also added crossed above and same results

I got it figured out...Needed to to pivot high line...Not pivot high
 
Last edited by a moderator:
@jonamez82 It will not if you just copy and paste the script over to TradingView. You would need to convert it. However, based on what I see over at TradingView, they already have plenty of auto support and resistance indicators.
 
This is amazing!! I have one question: Does this show support resistance lines before price reaches it like pivot points or does it place the lines after price touches it?
 
@Kapitalk12 I think so. I don't actively use it, so I can't confirm. You should add it to your chart and watch how it behaves during market hours to make sure.
 
Is there anyway to make this script work on different timeframes? For example, it would be amazing to be able to see the 5min plots of this script on the 1min chart. I was looking through the code but I couldnt really see any adjustable settings, thanks for any help!
 
Is there anyway to make this script work on different timeframes? For example, it would be amazing to be able to see the 5min plots of this script on the 1min chart. I was looking through the code but I couldnt really see any adjustable settings, thanks for any help!

See if this helps. This is the study in the first post now with multi-timeframe capability.

The chart displayed below has a 1min chart, 1min and 5min versions of the script below.

Capture.jpg
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 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 = yes;    #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 agg = AggregationPeriod.MIN;

def vHigh = high(period = agg);  # creates the variable vHigh.  Use of the variable reduce data calls to tos iData server
#    def initHigh =  CompoundValue(1, high, high);  # creates and initialized variable for High
def vLow = low(period = agg);
#    def initLow = CompoundValue(1, low, low);
def vOpen = open(period = agg);
#    def initOpen = CompoundValue(1, open, open);
def vClose = close(period = agg);
#    def initClose = CompoundValue(1, close, close);
def vVolume = volume(period = agg);
#    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(low, -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
 
I am new to this forum and please excuse if this has been discussed or shared in another thread. I have tried searching extensively here but couldn't find anything specific to this requirement.

I need help with creating a custom scan for "break and retest" or "price near specific <plot>" of price close for the plots defined in this code.

Example - Scan setup: For any specific timeframe scan using Auto Pivot Points Support & Resistance Indicator study and based on the nearest plot (pivot high or low line)

Bullish:
(a) if price breaks prior high resistance and retests that same prior high as support which is now the pivot high line plot as per this study
(b) if price drops "near" the prior high which is the pivot high line as per this study

Bearish:
(a) if price breaks prior low support and retests that same prior low as resistance which is now the pivot low line plot as per this study
(b) if price rises "near" the prior low which the pivot low line as per this study

For the "near" variable I am looking for something similar to this scan setup for near 52 week high if that better illustrates my requirement here.
High == Highest(High(period = "DAY"), 252)

I also see some redirection to post #86 but I could not find a solution to this requirement, may be I didn't know how to. Any guidance if this solution was already provided would be great.

Thank you all, this is an amazing community and I am learning every day from all your support on these invaluable threads.
I have come up with the following scan criteria to support the requirements quoted, can the experts here please validate this or if there is a better way to achieve this. Constructive feedback is welcome, since this my first time with code here and I have no coding experience, just put together what I have learnt from this community.

Scan criteria #1:
Code:
#Bullish
#Code Below price is within 'x' Percent of prior high
def asr = My_Auto_Support_Resistance()."pivotHighLine";
def percent = asr * 0.01;
plot scan = AbsValue(close - asr) <= percent;

In addition to this, I have added two more scan criteria to filter out target stocks

Scan criteria #2:
Code:
#Price low is above the prior high to make sure the price has not breached the prior high
low is greater than or equal to My_Auto_Support_Resistance()."pivotHighLine"

Scan criteria #3:
Code:
#Ensure last candle is a green candle for retest and go confirmation
close is greater than open

Another tip could be adding a scan criteria for Engulfing Bullish candle for power breakout after test.

Also, flip the code for Bearish scans.
 
Last edited:

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