Repaints MTF Support & Resistance Zones For ThinkOrSwim

Repaints
I'm also liking this script when I've hated most support and resistance scripts.

I like the settings on this to be pivot lookback of 50 and the cloud size to be 6.2 to create "zones of interest". I took a practice short today off of one of these levels and it worked out really well. I'll keep this on one of my charts for awhile to see how it works in the long term. I appreciate the fact that even though it's multi-timeframe, it paints the zone in time before the price retests the area in a lot of cases. Good stuff.

Now, if only I knew the best indictors to pair with this to better time a trade =/

Any suggestions would be helpful

View attachment 20605
Hey there,
Just finding this script, and wanted to know if you've been having continued success with it or made any new modifiers? Thanks
 
Hey Clark, I have the code from the indicator above. Essentially, the goal is to replicate what you have from a multi-timeframe standpoint, but to go farther back than 1-2 days. This indicator allows you to adjust the loopback to show you key time frame specific SR zones from as far back as a few days or weeks.

Here is the publication link to TV: https://www.tradingview.com/script/DrcEUv8C-Support-Resistance-Channels-Zones-Multi-Time-Frame/

Code is below:
Code:
//@version=5
indicator("Support Resistance Channels/Zones Multi Time Frame", "SRMTF", overlay = true)
TF = input.timeframe(defval = 'D', title = "Higher Time Frame")
prd = input.int(defval = 5, title="Pivot Period", minval = 1, maxval = 30, tooltip="Used while calculating Pivot Points, checks left&right bars")
loopback = input.int(defval = 250, title = "Loopback Period", minval = 50, maxval = 400, tooltip="While calculating S/R levels it checks Pivots in Loopback Period")
ChannelW = input.float(defval = 6, title = "Maximum Channel Width %", minval = 1, maxval = 15, tooltip="Calculated using Highest/Lowest levels in 300 bars")
minstrength = input.int(defval = 2, title = "Minimum Strength", minval = 1, tooltip = "Channel must contain at least X Pivot Points")
maxnumsr = input.int(defval = 6, title = "Maximum Number of S/R", minval = 1, maxval = 10, tooltip = "Maximum number of Support/Resistance Channels to Show") - 1
showsrfit = input.bool(defval = true, title = "Show S/Rs that fits the Chart")
showtable = input.bool(defval = true, title = "Show S/R channels in a table")
tableposy = input.string(defval='bottom', title='Chart Location', options=['bottom', 'middle', 'top'], inline='chartpos')
tableposx = input.string(defval='left', title='', options=['left', 'center', 'right'], inline='chartpos')
res_col = input(defval = color.new(color.red, 75), title = "Resistance Color")
sup_col = input(defval = color.new(color.lime, 75), title = "Support Color")
inch_col = input(defval = color.new(color.gray, 75), title = "Color When Price in Channel")

get_highlow()=>
var hlmatrix = matrix.new<float>(loopback, 2, 0.)
if barstate.islast // use less memory
for x = 0 to loopback - 1
matrix.set(hlmatrix, x, 0, high[x])
matrix.set(hlmatrix, x, 1, low[x])
hlmatrix
hlmatrix = request.security(syminfo.tickerid, TF, get_highlow(), lookahead = barmerge.lookahead_on)


if na(hlmatrix)
runtime.error('You should choose Time Frame wisely')
if matrix.rows(hlmatrix) < prd * 10
runtime.error('There is not enough candles on Time Frame you choose. You better choose Time Frame wisely')

get_pivotvals(hlmatrix)=>
highs = matrix.col(hlmatrix, 0)
lows = matrix.col(hlmatrix, 1)
pivotvals = array.new_float(0)
for x = prd to array.size(highs) - prd - 1
if array.get(highs, x) >= array.max(array.slice(highs, x - prd, x + prd + 1))
array.push(pivotvals, array.get(highs, x))
if array.get(lows, x) <= array.min(array.slice(lows, x - prd, x + prd + 1))
array.push(pivotvals, array.get(lows, x))
pivotvals

//find/calculate SR channel/strength by using pivot points
get_sr_vals(pivotvals, cwidth, ind)=>
float lo = array.get(pivotvals, ind)
float hi = lo
int numpp = 0
for y = 0 to array.size(pivotvals) - 1
float cpp = array.get(pivotvals, y)
float wdth = cpp <= hi ? hi - cpp : cpp - lo
if wdth <= cwidth // fits the max channel width?
if cpp <= hi
lo := math.min(lo, cpp)
else
hi := math.max(hi, cpp)

numpp := numpp + 20 // each pivot point added as 20
[hi, lo, numpp]

var suportresistance = array.new_float(20, 0) // min & max levels * 10

// Change the location of the array elements
changeit(suportresistance, x, y)=>
tmp = array.get(suportresistance, y * 2)
array.set(suportresistance, y * 2, array.get(suportresistance, x * 2))
array.set(suportresistance, x * 2, tmp)
tmp := array.get(suportresistance, y * 2 + 1)
array.set(suportresistance, y * 2 + 1, array.get(suportresistance, x * 2 + 1))
array.set(suportresistance, x * 2 + 1, tmp)

// get related S/R level
get_level(suportresistance, ind)=>
float ret = na
if ind < array.size(suportresistance)
if array.get(suportresistance, ind) != 0
ret := array.get(suportresistance, ind)
ret

// get the color of elated S/R level
get_color(suportresistance, ind)=>
color ret = na
if ind < array.size(suportresistance)
if array.get(suportresistance, ind) != 0
ret := array.get(suportresistance, ind) > close and array.get(suportresistance, ind + 1) > close ? res_col :
array.get(suportresistance, ind) < close and array.get(suportresistance, ind + 1) < close ? sup_col :
inch_col
ret

// find and use highest/lowest on current chart if "Show S/Rs that fits the Chart" enabled
var times = array.new_float(0)
array.unshift(times, time)
visibleBars = 1
if time == chart.right_visible_bar_time
visibleBars := array.indexof(times, chart.left_visible_bar_time) + 1
chart_highest = ta.highest(visibleBars)
chart_lowest = ta.lowest(visibleBars)
// use 5% more
chart_highest += (chart_highest - chart_lowest) * 0.05
chart_lowest -= (chart_highest - chart_lowest) * 0.05

// alerts
resistancebroken = false
supportbroken = false

// calculate S/R on last bar
if barstate.islast
pivotvals = get_pivotvals(hlmatrix)

//calculate maximum S/R channel width
prdhighest = array.max(pivotvals)
prdlowest = array.min(pivotvals)
cwidth = (prdhighest - prdlowest) * ChannelW / 100

supres = array.new_float(0) // number of pivot, strength, min/max levels
stren = array.new_float(10, 0)
// get levels and strengs
for x = 0 to array.size(pivotvals) - 1
[hi, lo, strength] = get_sr_vals(pivotvals, cwidth, x)
array.push(supres, strength)
array.push(supres, hi)
array.push(supres, lo)


// chech last 500 bars on curent time frame and add each OHLC to strengh
for x = 0 to array.size(pivotvals) - 1
h = array.get(supres, x * 3 + 1)
l = array.get(supres, x * 3 + 2)
s = 0
for y = 0 to 499
if (high[y] <= h and high[y] >= l) or
(low[y] <= h and low[y] >= l) or
(open[y] <= h and open[y] >= l) or
(close[y] <= h and close[y] >= l)
s := s + 1
array.set(supres, x * 3, array.get(supres, x * 3) + s)

//reset SR levels
array.fill(suportresistance, 0)
// get strongest SRs
src = 0
for x = 0 to array.size(pivotvals) - 1
stv = -1. // value
stl = -1 // location
for y = 0 to array.size(pivotvals) - 1
if array.get(supres, y * 3) > stv and array.get(supres, y * 3) >= minstrength * 20
stv := array.get(supres, y * 3)
stl := y
if stl >= 0
//get sr level
hh = array.get(supres, stl * 3 + 1)
ll = array.get(supres, stl * 3 + 2)
array.set(suportresistance, src * 2, hh)
array.set(suportresistance, src * 2 + 1, ll)
array.set(stren, src, array.get(supres, stl * 3))

// make included pivot points' strength zero
for y = 0 to array.size(pivotvals) - 1
if (array.get(supres, y * 3 + 1) <= hh and array.get(supres, y * 3 + 1) >= ll) or
(array.get(supres, y * 3 + 2) <= hh and array.get(supres, y * 3 + 2) >= ll)
array.set(supres, y * 3, -1)

src += 1
if src >= 10
break

// sort S/R according to their strengths
for x = 0 to 8
for y = x + 1 to 9
if array.get(stren, y) > array.get(stren, x)
tmp = array.get(stren, y)
array.set(stren, y, array.get(stren, x))
changeit(suportresistance, x, y)

var srtable = table.new(position = tableposy + '_' + tableposx, columns = 5, rows= 11, frame_width = 1, frame_color = color.gray, border_width = 1, border_color = color.gray)
if showtable
table.cell(srtable, 0, 0, text = "TF:" + str.tostring(TF) + " Sorted by the Strength", text_color = color.rgb(0, 0, 250), bgcolor = color.yellow)
table.merge_cells(srtable, 0, 0, 3, 0)

// show S/R channels and tables if enabled
var srchannels = array.new_box(10)
rowindex = 1
for x = 0 to math.min(9, maxnumsr)
box.delete(array.get(srchannels, x))
srcol = get_color(suportresistance, x * 2)
if not na(srcol)
if not showsrfit or (get_level(suportresistance,x * 2 + 1) <= chart_highest and get_level(suportresistance,x * 2) >= chart_lowest)
array.set(srchannels, x,
box.new(left = bar_index - 300, top = get_level(suportresistance,x * 2), right = bar_index + 1, bottom = get_level(suportresistance,x * 2 + 1),
border_color = srcol,
border_width = 1,
extend = extend.both,
bgcolor = srcol))
if showtable
srtext = srcol == res_col ? "Resistance" : "Support"
bgcol = srcol == res_col ? color.rgb(200, 0, 0) : color.rgb(0, 200, 0)
txtcol = srcol == res_col ? color.white: color.black
table.cell(table_id = srtable, column = 0, row = rowindex, text = str.tostring(rowindex), text_color = txtcol, bgcolor = bgcol)
table.cell(table_id = srtable, column = 1, row = rowindex, text = srtext, text_color = txtcol, bgcolor = bgcol)
table.cell(table_id = srtable, column = 2, row = rowindex, text = str.tostring(math.round_to_mintick(get_level(suportresistance,x * 2 + 1))), text_color = txtcol, bgcolor = bgcol)
table.cell(table_id = srtable, column = 3, row = rowindex, text = str.tostring(math.round_to_mintick(get_level(suportresistance,x * 2))), text_color = txtcol, bgcolor = bgcol)
rowindex += 1
// alerts
// check if the price is not in a channel
not_in_a_channel = true
for x = 0 to math.min(9, maxnumsr)
if close <= array.get(suportresistance, x * 2) and close >= array.get(suportresistance, x * 2 + 1)
not_in_a_channel := false

// if price is not in a channel then check if S/R was broken
if not_in_a_channel
for x = 0 to math.min(9, maxnumsr)
if close[1] <= array.get(suportresistance, x * 2) and close > array.get(suportresistance, x * 2)
resistancebroken := true
if close[1] >= array.get(suportresistance, x * 2 + 1) and close < array.get(suportresistance, x * 2 + 1)
supportbroken := true

alertcondition(resistancebroken, title = "Resistance Broken", message = "Resistance Broken")
alertcondition(supportbroken, title = "Support Broken", message = "Support Broken")
Alright, I apologize for the long wait. I came up with a few versions of this script and finally came up with one I satisfied with. Now because thinkscript is limited in is use of arrays I couldn't make it as dynamic as I wanted to. However I did attempt to make so that it will seek out and highlight the strongest zone. I hope this is at somewhat close to what you were looking for. If anyone has other modifications or ideas that could make it better then go for it!
Code:
# HTF Loopback Support/Resistance Zones (Completed HTF Bars)
#============================================================
# Clark2001
# Script logic and optimization aided by ChatGPT (OpenAI)
# ============================================================
# - Levels come from the last N COMPLETED higher timeframe bars
# - No pivots: pure loopback HTF range
# - Multi-level R1..R5 and S1..S5
# - Strength via touch counts, strongest level highlighted
# ============================================================

declare upper;

# ---------- Inputs ----------
input higherTF             = AggregationPeriod.FOUR_HOURS;  # HTF (HOUR, FOUR_HOURS, DAY, etc.)
input loopbackHTFBars      = 5;                             # How many completed HTF bars to use (1–10 recommended)
input maxLevelsEachSide    = 5;                             # Up to 5 resistance + 5 support levels
input zoneSize             = 0.5;                           # Zone thickness in price units (full height)

input showResistance       = yes;
input showSupport          = yes;
input showLines            = yes;

# Strength settings
input touchLookbackBars    = 500;                           # How many base-TF bars to scan for touches
input touchToleranceTicks  = 4;                             # Distance from level in ticks to count as a touch
input strongMinTouches     = 3;                             # Minimum touches to qualify as "strong"

# Bubble controls
input showLevelLabels      = yes;                           # Turn touch-count bubbles on/off

# ---------- Global Colors ----------
DefineGlobalColor("ResZone",       Color.DARK_GRAY);
DefineGlobalColor("SupZone",       Color.DARK_GRAY);
DefineGlobalColor("ResLine",       Color.GREEN);
DefineGlobalColor("SupLine",       Color.RED);

DefineGlobalColor("StrongResZone", Color.YELLOW);
DefineGlobalColor("StrongSupZone", Color.YELLOW);
DefineGlobalColor("StrongResLine", Color.WHITE);
DefineGlobalColor("StrongSupLine", Color.WHITE);

# ---------- Multi-timeframe Core ----------
def cap   = GetAggregationPeriod();
def aggTF = higherTF;  # force all charts to use the same HTF series

# HTF series
def HtfH = High(period = aggTF);
def HtfL = Low(period  = aggTF);
def HtfO = Open(period = aggTF);

def bn      = BarNumber();
def lastBar = HighestAll(if !IsNaN(close) then bn else 0);

# Detect new HTF bar (when HTF open changes)
def newHTF = HtfO != HtfO[1];

# Running high/low inside the CURRENT HTF bar
def curH = if newHTF then HtfH else Max(curH[1], HtfH);
def curL = if newHTF then HtfL else Min(curL[1], HtfL);

# High/low of the JUST COMPLETED HTF bar
def compH = if newHTF then curH[1] else Double.NaN;
def compL = if newHTF then curL[1] else Double.NaN;

def newComp = !IsNaN(compH) and !IsNaN(compL);

# ---------- Stack last up to 10 completed HTF highs/lows ----------
# h1/l1 = most recent completed, h10/l10 = oldest in memory
def h1 = if newComp then compH else h1[1];
def h2 = if newComp then h1[1] else h2[1];
def h3 = if newComp then h2[1] else h3[1];
def h4 = if newComp then h3[1] else h4[1];
def h5 = if newComp then h4[1] else h5[1];
def h6 = if newComp then h5[1] else h6[1];
def h7 = if newComp then h6[1] else h7[1];
def h8 = if newComp then h7[1] else h8[1];
def h9 = if newComp then h8[1] else h9[1];
def h10 = if newComp then h9[1] else h10[1];

def l1 = if newComp then compL else l1[1];
def l2 = if newComp then l1[1] else l2[1];
def l3 = if newComp then l2[1] else l3[1];
def l4 = if newComp then l3[1] else l4[1];
def l5 = if newComp then l4[1] else l5[1];
def l6 = if newComp then l5[1] else l6[1];
def l7 = if newComp then l6[1] else l7[1];
def l8 = if newComp then l7[1] else l8[1];
def l9 = if newComp then l8[1] else l9[1];
def l10 = if newComp then l9[1] else l10[1];

# Clamp loopback between 1 and 10
def lb = if loopbackHTFBars < 1 then 1 else if loopbackHTFBars > 10 then 10 else loopbackHTFBars;

# Range high over last lb completed HTF bars
def rangeHighNow =
    if lb <= 1 then h1 else
    if lb == 2 then Max(h1, h2) else
    if lb == 3 then Max(Max(h1, h2), h3) else
    if lb == 4 then Max(Max(Max(h1, h2), h3), h4) else
    if lb == 5 then Max(Max(Max(Max(h1, h2), h3), h4), h5) else
    if lb == 6 then Max(Max(Max(Max(Max(h1, h2), h3), h4), h5), h6) else
    if lb == 7 then Max(Max(Max(Max(Max(Max(h1, h2), h3), h4), h5), h6), h7) else
    if lb == 8 then Max(Max(Max(Max(Max(Max(Max(h1, h2), h3), h4), h5), h6), h7), h8) else
    if lb == 9 then Max(Max(Max(Max(Max(Max(Max(Max(h1, h2), h3), h4), h5), h6), h7), h8), h9) else
    Max(Max(Max(Max(Max(Max(Max(Max(Max(h1, h2), h3), h4), h5), h6), h7), h8), h9), h10);

# Range low over last lb completed HTF bars
def rangeLowNow =
    if lb <= 1 then l1 else
    if lb == 2 then Min(l1, l2) else
    if lb == 3 then Min(Min(l1, l2), l3) else
    if lb == 4 then Min(Min(Min(l1, l2), l3), l4) else
    if lb == 5 then Min(Min(Min(Min(l1, l2), l3), l4), l5) else
    if lb == 6 then Min(Min(Min(Min(Min(l1, l2), l3), l4), l5), l6) else
    if lb == 7 then Min(Min(Min(Min(Min(Min(l1, l2), l3), l4), l5), l6), l7) else
    if lb == 8 then Min(Min(Min(Min(Min(Min(Min(l1, l2), l3), l4), l5), l6), l7), l8) else
    if lb == 9 then Min(Min(Min(Min(Min(Min(Min(Min(l1, l2), l3), l4), l5), l6), l7), l8), l9) else
    Min(Min(Min(Min(Min(Min(Min(Min(Min(l1, l2), l3), l4), l5), l6), l7), l8), l9), l10);

# Freeze range at last bar
def rangeHigh = HighestAll(if bn == lastBar then rangeHighNow else Double.NaN);
def rangeLow  = HighestAll(if bn == lastBar then rangeLowNow  else Double.NaN);

def rangeSize = Max(rangeHigh - rangeLow, 0);

# ---------- Build Level Centers from Range ----------
def lvlCount = Max(1, maxLevelsEachSide);
def step = if rangeSize > 0 then rangeSize / (2 * lvlCount) else 0;

# Resistances from top downward
def r1Dyn = if maxLevelsEachSide >= 1 then rangeHigh - 0 * step else Double.NaN;
def r2Dyn = if maxLevelsEachSide >= 2 then rangeHigh - 1 * step else Double.NaN;
def r3Dyn = if maxLevelsEachSide >= 3 then rangeHigh - 2 * step else Double.NaN;
def r4Dyn = if maxLevelsEachSide >= 4 then rangeHigh - 3 * step else Double.NaN;
def r5Dyn = if maxLevelsEachSide >= 5 then rangeHigh - 4 * step else Double.NaN;

# Supports from bottom upward
def s1Dyn = if maxLevelsEachSide >= 1 then rangeLow + 0 * step else Double.NaN;
def s2Dyn = if maxLevelsEachSide >= 2 then rangeLow + 1 * step else Double.NaN;
def s3Dyn = if maxLevelsEachSide >= 3 then rangeLow + 2 * step else Double.NaN;
def s4Dyn = if maxLevelsEachSide >= 4 then rangeLow + 3 * step else Double.NaN;
def s5Dyn = if maxLevelsEachSide >= 5 then rangeLow + 4 * step else Double.NaN;

# Freeze level centers at last bar
def R1 = HighestAll(if bn == lastBar then r1Dyn else Double.NaN);
def R2 = HighestAll(if bn == lastBar then r2Dyn else Double.NaN);
def R3 = HighestAll(if bn == lastBar then r3Dyn else Double.NaN);
def R4 = HighestAll(if bn == lastBar then r4Dyn else Double.NaN);
def R5 = HighestAll(if bn == lastBar then r5Dyn else Double.NaN);

def S1 = HighestAll(if bn == lastBar then s1Dyn else Double.NaN);
def S2 = HighestAll(if bn == lastBar then s2Dyn else Double.NaN);
def S3 = HighestAll(if bn == lastBar then s3Dyn else Double.NaN);
def S4 = HighestAll(if bn == lastBar then s4Dyn else Double.NaN);
def S5 = HighestAll(if bn == lastBar then s5Dyn else Double.NaN);

# ---------- Zone Geometry ----------
def halfZ = zoneSize / 2;

def useR1 = showResistance and maxLevelsEachSide >= 1 and !IsNaN(R1);
def useR2 = showResistance and maxLevelsEachSide >= 2 and !IsNaN(R2);
def useR3 = showResistance and maxLevelsEachSide >= 3 and !IsNaN(R3);
def useR4 = showResistance and maxLevelsEachSide >= 4 and !IsNaN(R4);
def useR5 = showResistance and maxLevelsEachSide >= 5 and !IsNaN(R5);

def useS1 = showSupport and maxLevelsEachSide >= 1 and !IsNaN(S1);
def useS2 = showSupport and maxLevelsEachSide >= 2 and !IsNaN(S2);
def useS3 = showSupport and maxLevelsEachSide >= 3 and !IsNaN(S3);
def useS4 = showSupport and maxLevelsEachSide >= 4 and !IsNaN(S4);
def useS5 = showSupport and maxLevelsEachSide >= 5 and !IsNaN(S5);

def R1Top = R1 + halfZ;
def R1Bot = R1 - halfZ;
def R2Top = R2 + halfZ;
def R2Bot = R2 - halfZ;
def R3Top = R3 + halfZ;
def R3Bot = R3 - halfZ;
def R4Top = R4 + halfZ;
def R4Bot = R4 - halfZ;
def R5Top = R5 + halfZ;
def R5Bot = R5 - halfZ;

def S1Top = S1 + halfZ;
def S1Bot = S1 - halfZ;
def S2Top = S2 + halfZ;
def S2Bot = S2 - halfZ;
def S3Top = S3 + halfZ;
def S3Bot = S3 - halfZ;
def S4Top = S4 + halfZ;
def S4Bot = S4 - halfZ;
def S5Top = S5 + halfZ;
def S5Bot = S5 - halfZ;

# ---------- Strength: Touch Count per Level ----------
def tol = touchToleranceTicks * TickSize();

def nearR1 = if useR1 and AbsValue(close - R1) <= tol then 1 else 0;
def nearR2 = if useR2 and AbsValue(close - R2) <= tol then 1 else 0;
def nearR3 = if useR3 and AbsValue(close - R3) <= tol then 1 else 0;
def nearR4 = if useR4 and AbsValue(close - R4) <= tol then 1 else 0;
def nearR5 = if useR5 and AbsValue(close - R5) <= tol then 1 else 0;

def nearS1 = if useS1 and AbsValue(close - S1) <= tol then 1 else 0;
def nearS2 = if useS2 and AbsValue(close - S2) <= tol then 1 else 0;
def nearS3 = if useS3 and AbsValue(close - S3) <= tol then 1 else 0;
def nearS4 = if useS4 and AbsValue(close - S4) <= tol then 1 else 0;
def nearS5 = if useS5 and AbsValue(close - S5) <= tol then 1 else 0;

def rawR1Touches = Sum(nearR1, touchLookbackBars);
def rawR2Touches = Sum(nearR2, touchLookbackBars);
def rawR3Touches = Sum(nearR3, touchLookbackBars);
def rawR4Touches = Sum(nearR4, touchLookbackBars);
def rawR5Touches = Sum(nearR5, touchLookbackBars);

def rawS1Touches = Sum(nearS1, touchLookbackBars);
def rawS2Touches = Sum(nearS2, touchLookbackBars);
def rawS3Touches = Sum(nearS3, touchLookbackBars);
def rawS4Touches = Sum(nearS4, touchLookbackBars);
def rawS5Touches = Sum(nearS5, touchLookbackBars);

def R1Touches = HighestAll(if bn == lastBar then rawR1Touches else Double.NaN);
def R2Touches = HighestAll(if bn == lastBar then rawR2Touches else Double.NaN);
def R3Touches = HighestAll(if bn == lastBar then rawR3Touches else Double.NaN);
def R4Touches = HighestAll(if bn == lastBar then rawR4Touches else Double.NaN);
def R5Touches = HighestAll(if bn == lastBar then rawR5Touches else Double.NaN);

def S1Touches = HighestAll(if bn == lastBar then rawS1Touches else Double.NaN);
def S2Touches = HighestAll(if bn == lastBar then rawS2Touches else Double.NaN);
def S3Touches = HighestAll(if bn == lastBar then rawS3Touches else Double.NaN);
def S4Touches = HighestAll(if bn == lastBar then rawS4Touches else Double.NaN);
def S5Touches = HighestAll(if bn == lastBar then rawS5Touches else Double.NaN);

def maxRTouches = Max(Max(Max(Max(R1Touches, R2Touches), R3Touches), R4Touches), R5Touches);
def maxSTouches = Max(Max(Max(Max(S1Touches, S2Touches), S3Touches), S4Touches), S5Touches);

def strongR1 = useR1 and R1Touches == maxRTouches and maxRTouches >= strongMinTouches;
def strongR2 = useR2 and R2Touches == maxRTouches and maxRTouches >= strongMinTouches;
def strongR3 = useR3 and R3Touches == maxRTouches and maxRTouches >= strongMinTouches;
def strongR4 = useR4 and R4Touches == maxRTouches and maxRTouches >= strongMinTouches;
def strongR5 = useR5 and R5Touches == maxRTouches and maxRTouches >= strongMinTouches;

def strongS1 = useS1 and S1Touches == maxSTouches and maxSTouches >= strongMinTouches;
def strongS2 = useS2 and S2Touches == maxSTouches and maxSTouches >= strongMinTouches;
def strongS3 = useS3 and S3Touches == maxSTouches and maxSTouches >= strongMinTouches;
def strongS4 = useS4 and S4Touches == maxSTouches and maxSTouches >= strongMinTouches;
def strongS5 = useS5 and S5Touches == maxSTouches and maxSTouches >= strongMinTouches;

# ---------- Clouds ----------
AddCloud(if useR1 then R1Top else Double.NaN, if useR1 then R1Bot else Double.NaN,
         GlobalColor("ResZone"), GlobalColor("ResZone"));
AddCloud(if useR2 then R2Top else Double.NaN, if useR2 then R2Bot else Double.NaN,
         GlobalColor("ResZone"), GlobalColor("ResZone"));
AddCloud(if useR3 then R3Top else Double.NaN, if useR3 then R3Bot else Double.NaN,
         GlobalColor("ResZone"), GlobalColor("ResZone"));
AddCloud(if useR4 then R4Top else Double.NaN, if useR4 then R4Bot else Double.NaN,
         GlobalColor("ResZone"), GlobalColor("ResZone"));
AddCloud(if useR5 then R5Top else Double.NaN, if useR5 then R5Bot else Double.NaN,
         GlobalColor("ResZone"), GlobalColor("ResZone"));

AddCloud(if useS1 then S1Top else Double.NaN, if useS1 then S1Bot else Double.NaN,
         GlobalColor("SupZone"), GlobalColor("SupZone"));
AddCloud(if useS2 then S2Top else Double.NaN, if useS2 then S2Bot else Double.NaN,
         GlobalColor("SupZone"), GlobalColor("SupZone"));
AddCloud(if useS3 then S3Top else Double.NaN, if useS3 then S3Bot else Double.NaN,
         GlobalColor("SupZone"), GlobalColor("SupZone"));
AddCloud(if useS4 then S4Top else Double.NaN, if useS4 then S4Bot else Double.NaN,
         GlobalColor("SupZone"), GlobalColor("SupZone"));
AddCloud(if useS5 then S5Top else Double.NaN, if useS5 then S5Bot else Double.NaN,
         GlobalColor("SupZone"), GlobalColor("SupZone"));

# Strong overlays
AddCloud(if strongR1 then R1Top else Double.NaN, if strongR1 then R1Bot else Double.NaN,
         GlobalColor("StrongResZone"), GlobalColor("StrongResZone"));
AddCloud(if strongR2 then R2Top else Double.NaN, if strongR2 then R2Bot else Double.NaN,
         GlobalColor("StrongResZone"), GlobalColor("StrongResZone"));
AddCloud(if strongR3 then R3Top else Double.NaN, if strongR3 then R3Bot else Double.NaN,
         GlobalColor("StrongResZone"), GlobalColor("StrongResZone"));
AddCloud(if strongR4 then R4Top else Double.NaN, if strongR4 then R4Bot else Double.NaN,
         GlobalColor("StrongResZone"), GlobalColor("StrongResZone"));
AddCloud(if strongR5 then R5Top else Double.NaN, if strongR5 then R5Bot else Double.NaN,
         GlobalColor("StrongResZone"), GlobalColor("StrongResZone"));

AddCloud(if strongS1 then S1Top else Double.NaN, if strongS1 then S1Bot else Double.NaN,
         GlobalColor("StrongSupZone"), GlobalColor("StrongSupZone"));
AddCloud(if strongS2 then S2Top else Double.NaN, if strongS2 then S2Bot else Double.NaN,
         GlobalColor("StrongSupZone"), GlobalColor("StrongSupZone"));
AddCloud(if strongS3 then S3Top else Double.NaN, if strongS3 then S3Bot else Double.NaN,
         GlobalColor("StrongSupZone"), GlobalColor("StrongSupZone"));
AddCloud(if strongS4 then S4Top else Double.NaN, if strongS4 then S4Bot else Double.NaN,
         GlobalColor("StrongSupZone"), GlobalColor("StrongSupZone"));
AddCloud(if strongS5 then S5Top else Double.NaN, if strongS5 then S5Bot else Double.NaN,
         GlobalColor("StrongSupZone"), GlobalColor("StrongSupZone"));

# ---------- Center Lines ----------
plot R1Line = if showLines and useR1 then R1 else Double.NaN;
plot R2Line = if showLines and useR2 then R2 else Double.NaN;
plot R3Line = if showLines and useR3 then R3 else Double.NaN;
plot R4Line = if showLines and useR4 then R4 else Double.NaN;
plot R5Line = if showLines and useR5 then R5 else Double.NaN;

plot S1Line = if showLines and useS1 then S1 else Double.NaN;
plot S2Line = if showLines and useS2 then S2 else Double.NaN;
plot S3Line = if showLines and useS3 then S3 else Double.NaN;
plot S4Line = if showLines and useS4 then S4 else Double.NaN;
plot S5Line = if showLines and useS5 then S5 else Double.NaN;

R1Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R3Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R4Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R5Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

S1Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S4Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S5Line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

R1Line.SetLineWeight(2);
R2Line.SetLineWeight(2);
R3Line.SetLineWeight(2);
R4Line.SetLineWeight(2);
R5Line.SetLineWeight(2);

S1Line.SetLineWeight(2);
S2Line.SetLineWeight(2);
S3Line.SetLineWeight(2);
S4Line.SetLineWeight(2);
S5Line.SetLineWeight(2);

R1Line.AssignValueColor(if strongR1 then GlobalColor("StrongResLine") else GlobalColor("ResLine"));
R2Line.AssignValueColor(if strongR2 then GlobalColor("StrongResLine") else GlobalColor("ResLine"));
R3Line.AssignValueColor(if strongR3 then GlobalColor("StrongResLine") else GlobalColor("ResLine"));
R4Line.AssignValueColor(if strongR4 then GlobalColor("StrongResLine") else GlobalColor("ResLine"));
R5Line.AssignValueColor(if strongR5 then GlobalColor("StrongResLine") else GlobalColor("ResLine"));

S1Line.AssignValueColor(if strongS1 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"));
S2Line.AssignValueColor(if strongS2 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"));
S3Line.AssignValueColor(if strongS3 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"));
S4Line.AssignValueColor(if strongS4 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"));
S5Line.AssignValueColor(if strongS5 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"));

# ---------- Level Labels ----------
AddChartBubble(showLevelLabels and useR1 and bn == lastBar,
               R1,
               "R1 (" + AsText(R1Touches) + ")",
               if strongR1 then GlobalColor("StrongResLine") else GlobalColor("ResLine"),
               yes);
AddChartBubble(showLevelLabels and useR2 and bn == lastBar,
               R2,
               "R2 (" + AsText(R2Touches) + ")",
               if strongR2 then GlobalColor("StrongResLine") else GlobalColor("ResLine"),
               yes);
AddChartBubble(showLevelLabels and useR3 and bn == lastBar,
               R3,
               "R3 (" + AsText(R3Touches) + ")",
               if strongR3 then GlobalColor("StrongResLine") else GlobalColor("ResLine"),
               yes);
AddChartBubble(showLevelLabels and useR4 and bn == lastBar,
               R4,
               "R4 (" + AsText(R4Touches) + ")",
               if strongR4 then GlobalColor("StrongResLine") else GlobalColor("ResLine"),
               yes);
AddChartBubble(showLevelLabels and useR5 and bn == lastBar,
               R5,
               "R5 (" + AsText(R5Touches) + ")",
               if strongR5 then GlobalColor("StrongResLine") else GlobalColor("ResLine"),
               yes);

AddChartBubble(showLevelLabels and useS1 and bn == lastBar,
               S1,
               "S1 (" + AsText(S1Touches) + ")",
               if strongS1 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"),
               no);
AddChartBubble(showLevelLabels and useS2 and bn == lastBar,
               S2,
               "S2 (" + AsText(S2Touches) + ")",
               if strongS2 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"),
               no);
AddChartBubble(showLevelLabels and useS3 and bn == lastBar,
               S3,
               "S3 (" + AsText(S3Touches) + ")",
               if strongS3 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"),
               no);
AddChartBubble(showLevelLabels and useS4 and bn == lastBar,
               S4,
               "S4 (" + AsText(S4Touches) + ")",
               if strongS4 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"),
               no);
AddChartBubble(showLevelLabels and useS5 and bn == lastBar,
               S5,
               "S5 (" + AsText(S5Touches) + ")",
               if strongS5 then GlobalColor("StrongSupLine") else GlobalColor("SupLine"),
               no);
 

Attachments

  • HTF_Zones.png
    HTF_Zones.png
    124.2 KB · Views: 77

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