Support and Resistance Based on H, L, O, C of Daily Candle

a1cturner

Well-known member
I cannot for the life of my find a study that shows what I am looking for and have been off of here for so long that I can barely remember how to switch timeframes on my own chart, lol.

I believe what I am looking for is fairy simple so here goes.

First, I would like to look back over the past year and collect data points for every daily candle to include the high, low, open, and close.

Second, I would like to use those data points to compare where they fall in relation to other days and if they meet certain criteria (i.e. within 0.01% of each other) than "plot" a point (not a visible point, just a data point)

Third, If there are 3 or more of the plots from step 2 at the same level than I would plot a visible line extending to the right.

Fourth, The more points that intersect, the thicker the line.

If I didn't make sense, here is a picture.

y75VYfu.png


The code would take into account the open of the green candle, the high of the red candle, and the low of the green candle two days later. It would realize that all three are within 0.01% of each other and plot a line to the right. About 2 weeks later the green candle opens up within 0.01% of our plotted line so that would make the plot even thicker (this is a want, not a need).

About a week after that when I notice the stock is going down, I use this plotted line as a resistance point and exit at or before the price dips to the line.

Am I missing this study somewhere????
 
I cannot for the life of my find a study that shows what I am looking for and have been off of here for so long that I can barely remember how to switch timeframes on my own chart, lol.

I believe what I am looking for is fairy simple so here goes.

First, I would like to look back over the past year and collect data points for every daily candle to include the high, low, open, and close.

Second, I would like to use those data points to compare where they fall in relation to other days and if they meet certain criteria (i.e. within 0.01% of each other) than "plot" a point (not a visible point, just a data point)

Third, If there are 3 or more of the plots from step 2 at the same level than I would plot a visible line extending to the right.

Fourth, The more points that intersect, the thicker the line.

If I didn't make sense, here is a picture.

y75VYfu.png


The code would take into account the open of the green candle, the high of the red candle, and the low of the green candle two days later. It would realize that all three are within 0.01% of each other and plot a line to the right. About 2 weeks later the green candle opens up within 0.01% of our plotted line so that would make the plot even thicker (this is a want, not a need).

About a week after that when I notice the stock is going down, I use this plotted line as a resistance point and exit at or before the price dips to the line.

Am I missing this study somewhere????
This is what I have been hoping to figure out. I use the D, 4 hr, 1 hr, to locate these points and use them as "Major" pivot points to trade when price tests this "zone". I hope this is doable. @halcyonguy is helping, I think. as well as others. This would be an amazing indicator and would save a ton of time.
 
This is what I have been hoping to figure out. I use the D, 4 hr, 1 hr, to locate these points and use them as "Major" pivot points to trade when price tests this "zone". I hope this is doable. @halcyonguy is helping, I think. as well as others. This would be an amazing indicator and would save a ton of time.
That would be great! I just can’t wrap my head around it just yet. I’ll keep working it one step at a time though.

First thing I was going to look into is how to “lookback” 1 year or so many periods and then define close, and open, and high and low etc during that “lookback“ period. 🤷🏻‍♂️
 
I cannot for the life of my find a study that shows what I am looking for and have been off of here for so long that I can barely remember how to switch timeframes on my own chart, lol.

I believe what I am looking for is fairy simple so here goes.

First, I would like to look back over the past year and collect data points for every daily candle to include the high, low, open, and close.

Second, I would like to use those data points to compare where they fall in relation to other days and if they meet certain criteria (i.e. within 0.01% of each other) than "plot" a point (not a visible point, just a data point)

Third, If there are 3 or more of the plots from step 2 at the same level than I would plot a visible line extending to the right.

Fourth, The more points that intersect, the thicker the line.

If I didn't make sense, here is a picture.



The code would take into account the open of the green candle, the high of the red candle, and the low of the green candle two days later. It would realize that all three are within 0.01% of each other and plot a line to the right. About 2 weeks later the green candle opens up within 0.01% of our plotted line so that would make the plot even thicker (this is a want, not a need).

About a week after that when I notice the stock is going down, I use this plotted line as a resistance point and exit at or before the price dips to the line.

Am I missing this study somewhere????

i don't think this can be done as you describe. it would require 100's of variables.
below is something that looks at close prices, and plots 10 different lines at a time


1. ..past year and collect data points for every daily candle to include the high, low, open, and close.
there are no arrays, so no collecting data. those common price levels already exist.
there are about 250 days in a year. with 4 data points, that would be up to a 1000 variables to configure.
this will be true during the last 250 bars on the chart,
def rng = (!isnan(close) and isnan(close[-bars]));


2. use those data points to compare where they fall in relation to other days and if they meet certain criteria (i.e. within 0.01% of each other) than "plot" a point (not a visible point, just a data point)
compare open to other opens? or to any of the other prices?
on every bar, 4 loops (for the 4 price levels on that bar) would have to sequence through all the remaining bars, and look for a match.


3. If there are 3 or more of the plots from step 2 at the same level than I would plot a visible line extending to the right.
there could be dozens, or 100s of lines to plot.


4. The more points that intersect, the thicker the line.
this would require more variables, to hold past counts, to compare to.


--------------------


here is something to experiment with.
it looks at just the close prices, from the last 250 bars(about a years worth on a daily chart).
it compares current bar close, to all the remaining close prices.
if a future price is near the current one, then a counter is +1, close_cnt.
if close_cnt >= some quantity, (default 3), then a line will be drawn from that bar.

there are just 10 plots. so when the 11th count signal occurs, the 1st line stops and a new line starts.

linenum is a counter, that counts 1 to 10, then starts over at 1.
this controls the sequencing through the 10 plots.


Code:
# daily_prices_compare_to_near_00

#https://usethinkscript.com/threads/support-and-resistance-based-on-h-l-o-c-of-daily-candle.15492/
#Support and Resistance Based on H, L, O, C of Daily Candle

def na = double.nan;
def bn = barnumber();

def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;
#def lastbar = !isnan(close[0]) and isnan(close[-1]);

#def barsleft = lastbn - bn + 1;
def barsleft = lastbn - bn + 0;


#---------------------------

input bars = 250;
def rng = (!isnan(close) and isnan(close[-bars]));

def rng_start = (!isnan(close[-(bars-1)]) and isnan(close[-(bars+0)]));

input test_start_line = yes;
addverticalline(test_start_line and rng_start, "start", color.cyan);


#---------------------------

input near_per = 0.01;
#input near_per = 0.05;

input min_qty_to_match = 3;


addlabel(1, "  ", color.black);
addlabel(1,  min_qty_to_match + "  min qty of occurances of a price", color.yellow);


# check close price to future close prices
def close_cnt = if barsleft >= bars then 0
 else fold i1 = 1 to bars+1
  with p1
  while !isnan(getvalue(close, -i1))
  do p1 + if ((close + near_per) >= getvalue(close, -i1) and (close - near_per) <= getvalue(close, -i1)) then 1 else 0;

def cls_en = if close_cnt >= min_qty_to_match then 1 else 0;

# count bars with enough counts
def count_close_en;
if bn == 1 then {
 count_close_en = 0;
} else if rng_start then {
 count_close_en = fold i2 = 1 to bars+1
  with p2
  while !isnan(getvalue(close, -i2))
  do p2 + if (getvalue(cls_en, -i2)) then 1 else 0;
} else {
 count_close_en = count_close_en[1];
}


addlabel(1, "  ", color.black);
addlabel(1,
count_close_en + " quantity of bar closes with more than " + min_qty_to_match + " occurances"
, color.yellow);


input test2_count = yes;
addchartbubble(test2_count, low*0.999,
close_cnt + "\n"
, (if cls_en then color.green else if close_cnt > 0 then color.magenta else color.gray), no);



def lineqty = 10;

def cnt;
def linenum;
#def seq;
if bn == 1 then {
 cnt = 0;
 linenum = 0;
} else if cls_en then {
 cnt = cnt[1] + 1;
 linenum = if cnt % lineqty == 0 then lineqty else cnt % lineqty;
} else {
 cnt = cnt[1];
 linenum = linenum[1];
}


# plot 10 lines
def l1 = if linenum[1] != 1 and linenum == 1 then close else l1[1];
def l2 = if linenum[1] != 2 and linenum == 2 then close else l2[1];
def l3 = if linenum[1] != 3 and linenum == 3 then close else l3[1];
def l4 = if linenum[1] != 4 and linenum == 4 then close else l4[1];
def l5 = if linenum[1] != 5 and linenum == 5 then close else l5[1];
def l6 = if linenum[1] != 6 and linenum == 6 then close else l6[1];
def l7 = if linenum[1] != 7 and linenum == 7 then close else l7[1];
def l8 = if linenum[1] != 8 and linenum == 8 then close else l8[1];
def l9 = if linenum[1] != 9 and linenum == 9 then close else l9[1];
def l10 = if linenum[1] != 10 and linenum == 10 then close else l10[1];


plot z1 = if l1 == 0 or isnan(close) then na else l1;
plot z2 = if l2 == 0 or isnan(close) then na else l2;
plot z3 = if l3 == 0 or isnan(close) then na else l3;
plot z4 = if l4 == 0 or isnan(close) then na else l4;
plot z5 = if l5 == 0 or isnan(close) then na else l5;
plot z6 = if l6 == 0 or isnan(close) then na else l6;
plot z7 = if l7 == 0 or isnan(close) then na else l7;
plot z8 = if l8 == 0 or isnan(close) then na else l8;
plot z9 = if l9 == 0 or isnan(close) then na else l9;
plot z10 = if l10 == 0 or isnan(close) then na else l10;



z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


input test3 = no;
addchartbubble(test3, low*0.999,
close_cnt + "\n" +
cnt + "\n" +
linenum
, (if cls_en then color.green else if close_cnt > 0 then color.magenta else color.gray), no);


#----------------------

input test1 = no;
addchartbubble(test1, low,
bn + "\n" +
barsleft
, color.yellow, no);


input test_vert_lines = no;
addverticalline(test_vert_lines and rng, "-");

#

lines from close prices, that are near at least 3 future close prices
a bubble shows the quantity
YFEiMg2.jpg




--------------------

an alternative is to do a profile of the prices.
here is my version of a profile, that looks at 40 price groups, spanning the prices on the chart. so the % tolerance couold vary quite a bit. and to get a smaller %, would require a lot more than 40 sets of formulas.

Tradingview Poor man's volume profile
post14
https://usethinkscript.com/threads/tradingview-poor-mans-volume-profile.14460/#post-119999
 
Last edited:
i don't think this can be done as you describe. it would require 100's of variables.
below is something that looks at close prices, and plots 10 different lines at a time



there are no arrays, so no collecting data. those common price levels already exist.
there are about 250 days in a year. with 4 data points, that would be up to a 1000 variables to configure.
this will be true during the last 250 bars on the chart,
def rng = (!isnan(close) and isnan(close[-bars]));



compare open to other opens? or to any of the other prices?
on every bar, 4 loops (for the 4 price levels on that bar) would have to sequence through all the remaining bars, and look for a match.



there could be dozens, or 100s of lines to plot.



this would require more variables, to hold past counts, to compare to.


--------------------


here is something to experiment with.
it looks at just the close prices, from the last 250 bars(about a years worth on a daily chart).
it compares current bar close, to all the remaining close prices.
if a future price is near the current one, then a counter is +1, close_cnt.
if close_cnt >= some quantity, (default 3), then a line will be drawn from that bar.

there are just 10 plots. so when the 11th count signal occurs, the 1st line stops and a new line starts.

linenum is a counter, that counts 1 to 10, then starts over at 1.
this controls the sequencing through the 10 plots.


Code:
# daily_prices_compare_to_near_00

#https://usethinkscript.com/threads/support-and-resistance-based-on-h-l-o-c-of-daily-candle.15492/
#Support and Resistance Based on H, L, O, C of Daily Candle

def na = double.nan;
def bn = barnumber();

def lastbn = HighestAll(If(IsNaN(close), 0, bn));
def lastbar = if (bn == lastbn) then 1 else 0;
#def lastbar = !isnan(close[0]) and isnan(close[-1]);

#def barsleft = lastbn - bn + 1;
def barsleft = lastbn - bn + 0;


#---------------------------

input bars = 250;
def rng = (!isnan(close) and isnan(close[-bars]));

def rng_start = (!isnan(close[-(bars-1)]) and isnan(close[-(bars+0)]));

input test_start_line = yes;
addverticalline(test_start_line and rng_start, "start", color.cyan);


#---------------------------

input near_per = 0.01;
#input near_per = 0.05;

input min_qty_to_match = 3;


addlabel(1, "  ", color.black);
addlabel(1,  min_qty_to_match + "  min qty of occurances of a price", color.yellow);


# check close price to future close prices
def close_cnt = if barsleft >= bars then 0
 else fold i1 = 1 to bars+1
  with p1
  while !isnan(getvalue(close, -i1))
  do p1 + if ((close + near_per) >= getvalue(close, -i1) and (close - near_per) <= getvalue(close, -i1)) then 1 else 0;

def cls_en = if close_cnt >= min_qty_to_match then 1 else 0;

# count bars with enough counts
def count_close_en;
if bn == 1 then {
 count_close_en = 0;
} else if rng_start then {
 count_close_en = fold i2 = 1 to bars+1
  with p2
  while !isnan(getvalue(close, -i2))
  do p2 + if (getvalue(cls_en, -i2)) then 1 else 0;
} else {
 count_close_en = count_close_en[1];
}


addlabel(1, "  ", color.black);
addlabel(1,
count_close_en + " quantity of bar closes with more than " + min_qty_to_match + " occurances"
, color.yellow);


input test2_count = yes;
addchartbubble(test2_count, low*0.999,
close_cnt + "\n"
, (if cls_en then color.green else if close_cnt > 0 then color.magenta else color.gray), no);



def lineqty = 10;

def cnt;
def linenum;
#def seq;
if bn == 1 then {
 cnt = 0;
 linenum = 0;
} else if cls_en then {
 cnt = cnt[1] + 1;
 linenum = if cnt % lineqty == 0 then lineqty else cnt % lineqty;
} else {
 cnt = cnt[1];
 linenum = linenum[1];
}


# plot 10 lines
def l1 = if linenum[1] != 1 and linenum == 1 then close else l1[1];
def l2 = if linenum[1] != 2 and linenum == 2 then close else l2[1];
def l3 = if linenum[1] != 3 and linenum == 3 then close else l3[1];
def l4 = if linenum[1] != 4 and linenum == 4 then close else l4[1];
def l5 = if linenum[1] != 5 and linenum == 5 then close else l5[1];
def l6 = if linenum[1] != 6 and linenum == 6 then close else l6[1];
def l7 = if linenum[1] != 7 and linenum == 7 then close else l7[1];
def l8 = if linenum[1] != 8 and linenum == 8 then close else l8[1];
def l9 = if linenum[1] != 9 and linenum == 9 then close else l9[1];
def l10 = if linenum[1] != 10 and linenum == 10 then close else l10[1];


plot z1 = if l1 == 0 or isnan(close) then na else l1;
plot z2 = if l2 == 0 or isnan(close) then na else l2;
plot z3 = if l3 == 0 or isnan(close) then na else l3;
plot z4 = if l4 == 0 or isnan(close) then na else l4;
plot z5 = if l5 == 0 or isnan(close) then na else l5;
plot z6 = if l6 == 0 or isnan(close) then na else l6;
plot z7 = if l7 == 0 or isnan(close) then na else l7;
plot z8 = if l8 == 0 or isnan(close) then na else l8;
plot z9 = if l9 == 0 or isnan(close) then na else l9;
plot z10 = if l10 == 0 or isnan(close) then na else l10;



z1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
z10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


input test3 = no;
addchartbubble(test3, low*0.999,
close_cnt + "\n" +
cnt + "\n" +
linenum
, (if cls_en then color.green else if close_cnt > 0 then color.magenta else color.gray), no);


#----------------------

input test1 = no;
addchartbubble(test1, low,
bn + "\n" +
barsleft
, color.yellow, no);


input test_vert_lines = no;
addverticalline(test_vert_lines and rng, "-");

#

lines from close prices, that are near at least 3 future close prices
a bubble shows the quantity
YFEiMg2.jpg




--------------------

an alternative is to do a profile of the prices.
here is my version of a profile, that looks at 40 price groups, spanning the prices on the chart. so the % tolerance couold vary quite a bit. and to get a smaller %, would require a lot more than 40 sets of formulas.

Tradingview Poor man's volume profile
post14
https://usethinkscript.com/threads/tradingview-poor-mans-volume-profile.14460/#post-119999
Wow. This is very close. I wander if it could be refined so that it will produce a cloud instead of lines. So if lines are within a "cloud Range" then it will only draw one cloud. Please do not think I am asking for you to do a ton of work on this. I am curious if it can be achieved. This is really close though. I just tested it today and the pivots were spot on. I changed the "near per" to .0001 to cut out a lot on a 5 min chart. Can this be coded so that the bubbles can be turned of/on?

Also, Is there a way to get this to look for the data on a higher TF? Say I want to use a 1m TF for scalping but I want to look for these pivots on a 1hr TF. Is that possible?

So after testing this overnight and this morning, It is very close.
Can the following be accomplished?
Can the lines go all the way to the right?
Have at least 3 input options for different TF's
Have these different time frame paint a color of choice
For example:
Input TF1 = 5M
Input TF1 = 15M
Input TF1 = 1Hr
Input TF1 = 1D

Option to select color that corresponds to the TF so all 15m pivots will be "x" color and "x" line width.
May require number of bars to lookback for each TF.
May also require "near per" and ""Min qty to match" for each TF.
Remove all bubbles as I do not see where they would be needed.
@a1cturner Please provide your feedback
 
Last edited:
Wow. This is very close. I wander if it could be refined so that it will produce a cloud instead of lines. So if lines are within a "cloud Range" then it will only draw one cloud. Please do not think I am asking for you to do a ton of work on this. I am curious if it can be achieved. This is really close though. I just tested it today and the pivots were spot on. I changed the "near per" to .0001 to cut out a lot on a 5 min chart. Can this be coded so that the bubbles can be turned of/on?

Also, Is there a way to get this to look for the data on a higher TF? Say I want to use a 1m TF for scalping but I want to look for these pivots on a 1hr TF. Is that possible?

So after testing this overnight and this morning, It is very close.
Can the following be accomplished?
Can the lines go all the way to the right?
Have at least 3 input options for different TF's
Have these different time frame paint a color of choice
For example:
Input TF1 = 5M
Input TF1 = 15M
Input TF1 = 1Hr
Input TF1 = 1D

Option to select color that corresponds to the TF so all 15m pivots will be "x" color and "x" line width.
May require number of bars to lookback for each TF.
May also require "near per" and ""Min qty to match" for each TF.
Remove all bubbles as I do not see where they would be needed.
@a1cturner Please provide your feedback
@METAL it looks like what we need is the SR Channel from LonesomeTheBlue on Trading View converted to TOS. It has been requested multiple times but still has not been converted. I am definitely not smart enough to do it.
 
@METAL it looks like what we need is the SR Channel from LonesomeTheBlue on Trading View converted to TOS. It has been requested multiple times but still has not been converted. I am definitely not smart enough to do it.
I will check that out. Hopefully someone can do it. Just looked at it. That is it. Pretty much.
 

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