Auto Resistance/Support Break Detector

YungTraderFromMontana

Well-known member
I used the swing high low indicator and then added a cross confirmation between multiple lookbacks for a higher accuracy.
There are three inputs that are lookbacks and should be somewhat manually tweaked to fit a certain stock (similar to ATR mult. with supertrend). What usually works best from early testing is choosing the first lookback as a number 8- 15, second 5-8, and third 3-5.

Code:
def price = (open + close)/2;
def length = 1;
def displace = 0;
def SMA = Average(price[-displace], length);


#1

input LookbackPeriod1 = 8;
def FirstBar = BarNumber();
def Highest = fold i = 1
             to LookbackPeriod1 + 1
             with p = 1
             while p
             do high > GetValue(high, -i);
def A = if (FirstBar > LookbackPeriod1
            and high == Highest(high, LookbackPeriod1)
            and Highest)
            then high
            else Double.NaN;
def Lowest = fold j = 1
            to LookbackPeriod1 + 1
            with q = 1
            while q
            do low < GetValue(low, -j);
def B = if (FirstBar > LookbackPeriod1
            and low == Lowest(low, LookbackPeriod1)
            and Lowest)
            then low
            else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod1 = Highest(high, LookbackPeriod1);
def _lowInPeriod1 = Lowest(low, LookbackPeriod1);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod1] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod1];
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[-LookbackPeriod1] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod1];
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;
def lower_close1 = (sma crosses below Support1[1]);
def higher_close1 = (sma crosses above Resistance1[1]);
#---------------------------------------
def ph1 = Round(A, 2);

def pl1 = Round(B, 2);

#--------------------------------------------------------------
Resistance1.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance1.SetDefaultColor(Color.GREEN);

#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.DASHES);
Support1.SetDefaultColor(Color.RED);


def doublebreakup1 = higher_close1;
def doublebreakdown1 = lower_close1;





#2

input LookbackPeriod0 = 4;
def FirstBar0 = BarNumber();
def Highest0 = fold i0 = 1
             to LookbackPeriod0 + 1
             with p0 = 1
             while p0
             do high > GetValue(high, -i0);
def A0 = if (FirstBar0 > LookbackPeriod0
            and high == Highest(high, LookbackPeriod0)
            and Highest0)
            then high
            else Double.NaN;
def Lowest0 = fold j0 = 1
            to LookbackPeriod0 + 1
            with q0 = 1
            while q0
            do low < GetValue(low, -j0);
def B0 = if (FirstBar0 > LookbackPeriod0
            and low == Lowest(low, LookbackPeriod0)
            and Lowest0)
            then low
            else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod10 = Highest(high, LookbackPeriod0);
def _lowInPeriod10 = Lowest(low, LookbackPeriod0);
#--------------------------------------------------------------
def marketLow10 = if _lowInPeriod10 < _lowInPeriod10[-LookbackPeriod0] then _lowInPeriod1 else _lowInPeriod10[-LookbackPeriod0];
def _markedLow10 = low == marketLow10;
rec _lastMarkedLow10 = CompoundValue(1, if IsNaN(_markedLow10) then _lastMarkedLow10[1] else if _markedLow10 then low else _lastMarkedLow10[1], low);
#--------------------------------------------------------------
def marketHigh10 = if _highInPeriod10 > _highInPeriod10[-LookbackPeriod0] then _highInPeriod10 else _highInPeriod10[-LookbackPeriod0];
def _markedHigh10 = high == marketHigh10;
rec _lastMarkedHigh10 = CompoundValue(1, if IsNaN(_markedHigh10) then _lastMarkedHigh10[1] else if _markedHigh10 then high else _lastMarkedHigh10[1], high);
#--------------------------------------------------------------

def Resistance10 = _lastMarkedHigh10;
def Support10 = _lastMarkedLow10;
def lower_close0 = (sma crosses below Support10[1]);
def higher_close0 = (sma crosses above Resistance10[1]);
#---------------------------------------
def ph0 = Round(A, 2);

def pl0 = Round(B, 2);

def doublebreakup2 = higher_close0;
def doublebreakdown2 = lower_close0;



#3

input LookbackPeriod00 = 2;
def FirstBar00 = BarNumber();
def Highest00 = fold i00 = 1
             to LookbackPeriod00 + 1
             with p00 = 1
             while p00
             do high > GetValue(high, -i00);
def A00 = if (FirstBar00 > LookbackPeriod00
            and high == Highest(high, LookbackPeriod00)
            and Highest00)
            then high
            else Double.NaN;
def Lowest00 = fold j00 = 1
            to LookbackPeriod00 + 1
            with q00 = 1
            while q00
            do low < GetValue(low, -j00);
def B00 = if (FirstBar00 > LookbackPeriod00
            and low == Lowest(low, LookbackPeriod00)
            and Lowest00)
            then low
            else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod100 = Highest(high, LookbackPeriod00);
def _lowInPeriod100 = Lowest(low, LookbackPeriod00);
#--------------------------------------------------------------
def marketLow100 = if _lowInPeriod100 < _lowInPeriod100[-LookbackPeriod00] then _lowInPeriod100 else _lowInPeriod100[-LookbackPeriod00];
def _markedLow100 = low == marketLow100;
rec _lastMarkedLow100 = CompoundValue(1, if IsNaN(_markedLow100) then _lastMarkedLow100[1] else if _markedLow100 then low else _lastMarkedLow100[1], low);
#--------------------------------------------------------------
def marketHigh100 = if _highInPeriod100 > _highInPeriod100[-LookbackPeriod00] then _highInPeriod100 else _highInPeriod1[-LookbackPeriod00];
def _markedHigh100 = high == marketHigh100;
rec _lastMarkedHigh100 = CompoundValue(1, if IsNaN(_markedHigh100) then _lastMarkedHigh100[1] else if _markedHigh100 then high else _lastMarkedHigh100[1], high);
#--------------------------------------------------------------

def Resistance100 = _lastMarkedHigh100;
def Support100 = _lastMarkedLow100;
def lower_close00 = (sma crosses below Support100[1]);
def higher_close00 = (sma crosses above Resistance100[1]);
#---------------------------------------
def ph000 = Round(A, 2);

def pl000 = Round(B, 2);



def doublebreakup3 = higher_close00;
def doublebreakdown3 = lower_close00;
def twoathree = doublebreakup1 or doublebreakup2;
def twoofthree2 = doublebreakup1 or doublebreakup3;
def twoathree3 = doublebreakdown1 or doublebreakdown2;
def twoofthree3 = doublebreakdown1 or doublebreakdown3;

plot allbreakup = doublebreakup1 and doublebreakup2 and doublebreakup3;
plot allbreakdown = doublebreakdown1 and doublebreakdown2 and doublebreakdown3;
plot twoofthreeup = twoofthree2 and twoofthree2;
plot twoofthreedown = twoathree3 and twoofthree3;
plot slippedthroughthecracksup = twoofthreeup and (price[1] < resistance1 and price > resistance1);
plot slippedthroughthecracksdown = twoofthreedown and (price[1] > support1) and (price < support1);

input BuyEntry = 3;
input SellEntry = 3;

def QB = Highest(high, BuyEntry);
def QS = Lowest(low, SellEntry);
plot trueqb = qb[1];
plot trueqs = qs[1];

Here's a chart of /gc with 10,5,4 settings. https://tos.mx/AEctufx
It works on anything stocks, forex, futures etc
 
Last edited by a moderator:

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

I used the swing high low indicator and then added a cross confirmation between multiple lookbacks for a higher accuracy.
There are three inputs that are lookbacks and should be somewhat manually tweaked to fit a certain stock (similar to ATR mult. with supertrend). What usually works best from early testing is choosing the first lookback as a number 8- 15, second 5-8, and third 3-5.

Here's a chart of /gc with 10,5,4 settings. https://tos.mx/AEctufx.
It works on anything stocks, forex, futures etc
Hey Montana, can you explain what that feature do again. I found it a little abstract in what you found in this setup.
 
@television 16 @Pharmd2Retire I liked the high low swing indicator but it had a good deal of false signals. By using different lookbacks (3 instead of 1) it essentially gives three different perspectives. If all of these align the signal is accurate and therefore I made an indicator using three different lookbacks instead of one that looks for a breakout on all lookbacks.
If you aren't sure what the lookback is it is essentially how far back the study looks at highs and lows of the candles. The shorter the lookback the more quickly it updates a support and resistance. The longer it is the opposite.


Here's a picture with marked entrances
 
Very nice @YungTraderFromMontana
What is slippedthroughthecracksup evaluating?

Also, I didn't realize this, but it seems like this redraws at some point? It was 10:00am, and I saw a green up arrow with price through the resistance. I checked another chart, then came back to the chart a few minutes later and the resistance had been redrawn higher and the arrow was gone. Is that how it normally works?
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
340 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