Repaints Finding "major" pivot points

Repaints

METAL

Active member
Plus
So I may be asking for the wrong thing, however, I have watched tons of videos and traders live calling it supply/Demand and also support/resistance. To be honest, it isn't consistently referenced the same.

What I am looking for is:
-Finding "major" pivot points.

Typically, by using higher time frames such as 1hr, D, 4r, and sometimes 15m. The pivot points seem to play a major role in the Break and retest strategy that I have been using for trading options on the 1 and 2m TF.
https://usethinkscript.com/threads/support-resistance-with-breaks-and-retests-for-thinkorswim.14893/

I have tested so many of the Supply/Demand and Support/Resistance indicators.
I get okay results but not very consistent in locating the precise zones.
There may be one or more out there, but I think I have tried them all on this forum.

- What I believe needs to occur in and indicator is to:
1) find the pivot points
2) Have a optional parameter that may be applied, such as
How many times this pivot point has been approached and either rejected or broken through and retested where it becomes either a support where it was previously a resistance and visa versa.
3) I assume there would need to be a range parameter that would allow for how close the pivot point can be approached for it to be considered a viable zone.
4)How far back this zone/pivot point is searched for. Could be bars, but I think for ease, it would be better to have days, weeks, months option.
4) the cloud/zone to be all the way across chart.
Also would like for it to be sizeable. Not sure if this is possible, but would be nice to have set parameters for the width of the zone.

Do you know if this is even achievable or is there an indicator out there that will accomplish this?
@samer800 @halcyonguy @Christopher84
 
Last edited by a moderator:
So I may be asking for the wrong thing, however, I have watched tons of videos and traders live calling it supply/Demand and also support/resistance. To be honest, it isn't consistently referenced the same.

What I am looking for is:
-Finding "major" pivot points.

Typically, by using higher time frames such as 1hr, D, 4r, and sometimes 15m. The pivot points seem to play a major role in the Break and retest strategy that I have been using for trading options on the 1 and 2m TF.
https://usethinkscript.com/threads/support-resistance-with-breaks-and-retests-for-thinkorswim.14893/

I have tested so many of the Supply/Demand and Support/Resistance indicators.
I get okay results but not very consistent in locating the precise zones.
There may be one or more out there, but I think I have tried them all on this forum.

- What I believe needs to occur in and indicator is to:
1) find the pivot points
2) Have a optional parameter that may be applied, such as
How many times this pivot point has been approached and either rejected or broken through and retested where it becomes either a support where it was previously a resistance and visa versa.
3) I assume there would need to be a range parameter that would allow for how close the pivot point can be approached for it to be considered a viable zone.
4)How far back this zone/pivot point is searched for. Could be bars, but I think for ease, it would be better to have days, weeks, months option.
4) the cloud/zone to be all the way across chart.
Also would like for it to be sizeable. Not sure if this is possible, but would be nice to have set parameters for the width of the zone.

Do you know if this is even achievable or is there an indicator out there that will accomplish this?
@samer800 @halcyonguy @Christopher84


-Finding "major" pivot points.

Typically, by using higher time frames such as 1hr, D, 4r, and sometimes 15m. The pivot points seem to play a major role in the Break and retest strategy that I have been using for trading options on the 1 and 2m TF.
sometimes using 2nd agg data has consequences. sometimes you can simulate data from a higher time frame by looking at more history data, by using longer length in functions.


- What I believe needs to occur in and indicator is to:

1) find the pivot points
you skipped over the most important part,
define a pivot...

is it based on highs and lows? or body size?
is it a reversal?
is it 1 bar that has a low , that is lower than x previous bars and lower than x future bars?

something like the first code in this post ?
https://usethinkscript.com/threads/...ows-indefinitely-in-thinkorswim.930/post-7048
my version of it
Code:
# peaks_valleys_template_00c

#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# post10  robert payne
# find peaks and valleys
# length includes current bar

def na = double.nan;
def bn = BarNumber();
def lastbn = highestall(if isnan(close) then 0 else bn);
def lastcls = if lastbn then close else lastcls[1];
#def lastbar = (!isnan(close) and isnan(close[-1]));

input show_peak_valley_arrows = yes;
def spva = show_peak_valley_arrows;
input len = 4;
def offset = Min(len - 1, lastbn - bn);

#--------------------------
#valley section
#def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
def valley = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);

plot ArrowUP = if spva then Valley else na;
ArrowUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUP.SetDefaultColor(Color.WHITE);
ArrowUP.SetLineWeight(2);

#---------------------------
#peak section
#def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
def peak = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);

plot ArrowDN = if spva then Peak else na;
ArrowDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDN.SetDefaultColor(Color.WHITE);
ArrowDN.SetLineWeight(2);
#



2) Have a optional parameter that may be applied, such as
How many times this pivot point has been approached and either rejected or broken through and retested where it becomes either a support where it was previously a resistance and visa versa.
that is a lot of variations, ... lots of possible values, many variables
start simple, with one parameter, get it working, then add another...


3) I assume there would need to be a range parameter that would allow for how close the pivot point can be approached for it to be considered a viable zone.
yes, what defines near to a price level ? within some % , within some $$ amount ?


4)How far back this zone/pivot point is searched for. Could be bars, but I think for ease, it would be better to have days, weeks, months option.
bars will always be easier. it's a number that can be used in a loop.
any time range would need converting.



5) the cloud/zone to be all the way across chart.
would need many variables. any guesses on the max pivots on a chart ? 4,8,10,...


Also would like for it to be sizeable. Not sure if this is possible, but would be nice to have set parameters for the width of the zone.
what is 'it'? try not to use generic words when describing things.
size what, in what way?

there will be a max quantity of pivot zones on a chart. when max+1 occurs, the oldest could stop drawing. ( ref my gap code below , 4 gap zones at a time)
(can't have infinite items drawn on a chart. no one is going to program 100 sets of formulas for that many pivots...)



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


ref code , gaps
show what can be done to have 4 of the same thing on a chart. 4x the formulas.
this will plot 4 gaps at a time.
if this is yes, reduce_gaps = yes , then the gap clouds will reduce as bars come into the gap zone.

might be in one of these posts?
https://usethinkscript.com/search/1149095/?q=gaps&c[users]=halcyonguy&o=date

Code:
# bargaps_06

# find gaps, more than some %.

# this will plot 4 gaps at a time.
# if a 5th gaps occurs, the 1st gap lines stop and the new gap lines starts.

# gaps are determined when a price difference between 2 bars is more than some %.
#  choose a minimum gap % , a % of the price.
#  default is 1%

# determine gap from previous bar price : close or high/low
# determine gap from current bar price : high or low

# can choose to reduce gaps,  when price crosses into a gap.
# if gaps are not reduced, lines will extend until another of the same gap seq number occurs (1,2,3,4)


def hi = high;
def lo = low;
def opn = open;
def cls = close;
def na = Double.NaN;
def bn = BarNumber();

# pick price level - prev bar
input prev_bar_price = { high_low , default close };

def prevhi;
def prevlo;
switch (prev_bar_price) {
case high_low:
 prevhi = hi[1];
 prevlo = lo[1];
case close:
 prevhi = cls[1];
 prevlo = cls[1];
}

# ----------------------
# current bar
def currhi = hi;
def currlo = lo;

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

input reduce_gaps = yes;

input min_gap_percent = 1.0;
#def per_digits = 1;
AddLabel(1, "find gaps that are > " + min_gap_percent + " % of price", Color.YELLOW);


input show_gap_clouds = yes;
input show_gap_stats_bubbles = no;

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

# if a gap, set gap high and low, and gap dir
def gaphi;
def gaplo;
def dir;
if bn == 1 then {
    gaphi = hl2;
    gaplo = hl2;
    dir = 0;
} else if prevhi < currlo then {
# gap up , high to low
    gaphi = currlo;
    gaplo = prevhi;
    dir = if gaphi > gaplo then 1 else 0;
} else if prevlo > currhi then {
# gap down , low to high
    gaphi = prevlo;
    gaplo = currhi;
    dir = if gaphi > gaplo then -1 else 0;
} else {
    gaphi = hl2;
    gaplo = hl2;
    dir = 0;
}

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

# determine the gap , + or - number
def gap = if dir > 0 then round(gaphi - gaplo, 2)
 else if dir < 0 then round(gaplo - gaphi, 2)
 else 0;

# check if gap is > min %
def gap_per = if gap == 0 then 0 else Round((gap / gaplo) * 100, 1);
def gap_en = (absvalue(gap_per) > min_gap_percent);

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

# counter of gaps
def gapqty = 4;

def cnt = if bn == 1 then 0
  else if gap_en then cnt[1] + 1
  else cnt[1];

# sequence counter, thru the qty
#  1,2,3,0,1,2,3,0...
def seq1 = (cnt % gapqty);
# chg to be,  1,2,3,4,1,2,3,4,...
def seq = if seq1 == 0 then gapqty else seq1;

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

# seq thru diff lines, and update 1 at a time
def gap1_en = (gap_en and seq == 1);
def gap2_en = (gap_en and seq == 2);
def gap3_en = (gap_en and seq == 3);
def gap4_en = (gap_en and seq == 4);

def p = (gap1_en or gap2_en or gap3_en or gap4_en);

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

# bubble location
def bubble_vert_offset = 0.005;
def bubhiy = (gaphi[0] * ( 1 + bubble_vert_offset));
def bubloy = (gaplo[0] * ( 1 - bubble_vert_offset));

# ----------------------------
# gap1

def gap1dir = if gap1_en then dir else gap1dir[1];

AddChartBubble(show_gap_stats_bubbles and gap1_en, (if gap1dir > 0 then bubloy else bubhiy) ,  gap + "\n" + gap_per + "%", if gap1dir < 0 then Color.RED else if gap1dir > 0 then Color.GREEN else Color.GRAY, (if gap1dir < 0 then yes else no) );
 
def top1 = if (bn == 1 or gap1_en[-1] == 1) then na else if gap1_en then gaphi else top1[1];
def bot1 = if (bn == 1 or gap1_en[-1] == 1) then na else if gap1_en then gaplo else bot1[1];

def top1b = if (bn == 1 or gap1_en[-1] == 1) then na
 else if gap1_en then gaphi
 else if !reduce_gaps then top1b[1]
 else if (lo < top1[0] and lo < top1b[1] and gap1dir == 1) then lo
 else top1b[1];

def bot1b = if (bn == 1 or gap1_en[-1] == 1) then na
 else if gap1_en then gaplo
 else if !reduce_gaps then bot1b[1]
 else if (hi > bot1[0] and hi > bot1b[1] and gap1dir == -1) then hi
 else bot1b[1];

# is the gap < 0 ,  then cancel
def gap1cancel = if gap1_en then 0 else if (top1b - bot1b) < 0 then 1 else 0;

def top1c = if gap1_en then top1
 else if gap1cancel then na
 else top1b[0];

def bot1c = if gap1_en then bot1
 else if gap1cancel then na
 else bot1b[0];


plot z1 = top1c;
z1.AssignValueColor(if gap1dir > 0 then color.green else color.red);
z1.SetStyle(Curve.MEDIUM_DASH);

plot z2 = bot1c;
z2.AssignValueColor(if gap1dir > 0 then color.green else color.red);
z2.SetStyle(Curve.MEDIUM_DASH);

def gap1top = if !show_gap_clouds then na else if gap1dir > 0 then z1 else z2;
def gap1bot = if !show_gap_clouds then na else if gap1dir > 0 then z2 else z1;
AddCloud(gap1top, gap1bot, Color.LIGHT_GREEN, Color.LIGHT_RED);


# ----------------------------------
# gap2

def gap2dir = if gap2_en then dir else gap2dir[1];

AddChartBubble(show_gap_stats_bubbles and gap2_en, (if gap2dir > 0 then bubloy else bubhiy) ,  gap + "\n" + gap_per + "%", if gap2dir < 0 then Color.RED else if gap2dir > 0 then Color.GREEN else Color.GRAY, (if gap2dir < 0 then yes else no) );
 
def top2 = if (bn == 1 or gap2_en[-1] == 1) then na else if gap2_en then gaphi else top2[1];
def bot2 = if (bn == 1 or gap2_en[-1] == 1) then na else if gap2_en then gaplo else bot2[1];

def top2b = if (bn == 1 or gap2_en[-1] == 1) then na
 else if gap2_en then gaphi
 else if !reduce_gaps then top2b[1]
 else if (lo < top2[0] and lo < top2b[1] and gap2dir == 1) then lo
 else top2b[1];

def bot2b = if (bn == 1 or gap2_en[-1] == 1) then na
 else if gap2_en then gaplo
 else if !reduce_gaps then bot2b[1]
 else if (hi > bot2[0] and hi > bot2b[1] and gap2dir == -1) then hi
 else bot2b[1];

# is the gap < 0 ,  then cancel
def gap2cancel = if gap2_en then 0 else if (top2b - bot2b) < 0 then 1 else 0;

def top2c = if gap2_en then top2
 else if gap2cancel then na
 else top2b[0];

def bot2c = if gap2_en then bot2
 else if gap2cancel then na
 else bot2b[0];

plot z3 = top2c;
z3.AssignValueColor(if gap2dir > 0 then color.green else color.red);
z3.SetStyle(Curve.MEDIUM_DASH);

plot z4 = bot2c;
z4.AssignValueColor(if gap2dir > 0 then color.green else color.red);
z4.SetStyle(Curve.MEDIUM_DASH);

def gap2top = if !show_gap_clouds then na else if gap2dir > 0 then z3 else z4;
def gap2bot = if !show_gap_clouds then na else if gap2dir > 0 then z4 else z3;
AddCloud(gap2top, gap2bot, Color.LIGHT_GREEN, Color.LIGHT_RED);


# --------------------------------
# gap3

def gap3dir = if gap3_en then dir else gap3dir[1];

AddChartBubble(show_gap_stats_bubbles and gap3_en, (if gap3dir > 0 then bubloy else bubhiy) ,  gap + "\n" + gap_per + "%", if gap3dir < 0 then Color.RED else if gap3dir > 0 then Color.GREEN else Color.GRAY, (if gap3dir < 0 then yes else no) );
 
def top3 = if (bn == 1 or gap3_en[-1] == 1) then na else if gap3_en then gaphi else top3[1];
def bot3 = if (bn == 1 or gap3_en[-1] == 1) then na else if gap3_en then gaplo else bot3[1];

def top3b = if (bn == 1 or gap3_en[-1] == 1) then na
 else if gap3_en then gaphi
 else if !reduce_gaps then top3b[1]
 else if (lo < top3[0] and lo < top3b[1] and gap3dir == 1) then lo
 else top3b[1];

def bot3b = if (bn == 1 or gap3_en[-1] == 1) then na
 else if gap3_en then gaplo
 else if !reduce_gaps then bot3b[1]
 else if (hi > bot3[0] and hi > bot3b[1] and gap3dir == -1) then hi
 else bot3b[1];

# is the gap < 0 ,  then cancel
def gap3cancel = if gap3_en then 0 else if (top3b - bot3b) < 0 then 1 else 0;

def top3c = if gap3_en then top3
 else if gap3cancel then na
 else top3b[0];

def bot3c = if gap3_en then bot3
 else if gap3cancel then na
 else bot3b[0];

plot z5 = top3c;
z5.AssignValueColor(if gap3dir > 0 then color.green else color.red);
z5.SetStyle(Curve.MEDIUM_DASH);

plot z6 = bot3c;
z6.AssignValueColor(if gap3dir > 0 then color.green else color.red);
z6.SetStyle(Curve.MEDIUM_DASH);

def gap3top = if !show_gap_clouds then na else if gap3dir > 0 then z5 else z6;
def gap3bot = if !show_gap_clouds then na else if gap3dir > 0 then z6 else z5;
AddCloud(gap3top, gap3bot, Color.LIGHT_GREEN, Color.LIGHT_RED);


# --------------------------------
# gap4

def gap4dir = if gap4_en then dir else gap4dir[1];

AddChartBubble(show_gap_stats_bubbles and gap4_en, (if gap4dir > 0 then bubloy else bubhiy) ,  gap + "\n" + gap_per + "%", if gap4dir < 0 then Color.RED else if gap4dir > 0 then Color.GREEN else Color.GRAY, (if gap4dir < 0 then yes else no) );
 
def top4 = if (bn == 1 or gap4_en[-1] == 1) then na else if gap4_en then gaphi else top4[1];
def bot4 = if (bn == 1 or gap4_en[-1] == 1) then na else if gap4_en then gaplo else bot4[1];

def top4b = if (bn == 1 or gap4_en[-1] == 1) then na
 else if gap4_en then gaphi
 else if !reduce_gaps then top4b[1]
 else if (lo < top4[0] and lo < top4b[1] and gap4dir == 1) then lo
 else top4b[1];

def bot4b = if (bn == 1 or gap4_en[-1] == 1) then na
 else if gap4_en then gaplo
 else if !reduce_gaps then bot4b[1]
 else if (hi > bot4[0] and hi > bot4b[1] and gap4dir == -1) then hi
 else bot4b[1];

# is the gap < 0 ,  then cancel
def gap4cancel = if gap4_en then 0 else if (top4b - bot4b) < 0 then 1 else 0;

def top4c = if gap4_en then top4
 else if gap4cancel then na
 else top4b[0];

def bot4c = if gap4_en then bot4
 else if gap4cancel then na
 else bot4b[0];

plot z7 = top4c;
z7.AssignValueColor(if gap4dir > 0 then color.green else color.red);
z7.SetStyle(Curve.MEDIUM_DASH);

plot z8 = bot4c;
z8.AssignValueColor(if gap4dir > 0 then color.green else color.red);
z8.SetStyle(Curve.MEDIUM_DASH);

def gap4top = if !show_gap_clouds then na else if gap4dir > 0 then z7 else z8;
def gap4bot = if !show_gap_clouds then na else if gap4dir > 0 then z8 else z7;
AddCloud(gap4top, gap4bot, Color.LIGHT_GREEN, Color.LIGHT_RED);

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


# ----------------------------------------
# test stuff

input debug_data = 0;

input test_seq_counter = no;
addchartbubble(test_seq_counter and p, hi, seq, color.cyan, yes);

input test_show_all_gaps = no;
addchartbubble(test_show_all_gaps and p, high, gap, (if dir > 0 then color.green else color.red), yes);

input test_gap_hi_lo = no;
addchartbubble(test_gap_hi_lo and dir != 0,lo,
 gaphi + " hi\n" +
 gaplo + " lo\n" +
 dir + " dir"
, (if dir > 0 then color.green else if dir < 0 then color.red else color.gray), no);
#
 

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

So I may be asking for the wrong thing, however, I have watched tons of videos and traders live calling it supply/Demand and also support/resistance. To be honest, it isn't consistently referenced the same.

What I am looking for is:
-Finding "major" pivot points.

Typically, by using higher time frames such as 1hr, D, 4r, and sometimes 15m. The pivot points seem to play a major role in the Break and retest strategy that I have been using for trading options on the 1 and 2m TF.
https://usethinkscript.com/threads/support-resistance-with-breaks-and-retests-for-thinkorswim.14893/

I have tested so many of the Supply/Demand and Support/Resistance indicators.
I get okay results but not very consistent in locating the precise zones.
There may be one or more out there, but I think I have tried them all on this forum.

- What I believe needs to occur in and indicator is to:
1) find the pivot points
2) Have a optional parameter that may be applied, such as
How many times this pivot point has been approached and either rejected or broken through and retested where it becomes either a support where it was previously a resistance and visa versa.
3) I assume there would need to be a range parameter that would allow for how close the pivot point can be approached for it to be considered a viable zone.
4)How far back this zone/pivot point is searched for. Could be bars, but I think for ease, it would be better to have days, weeks, months option.
4) the cloud/zone to be all the way across chart.
Also would like for it to be sizeable. Not sure if this is possible, but would be nice to have set parameters for the width of the zone.
hal_aggpeak
Do you know if this is even achievable or is there an indicator out there that will accomplish this?
@samer800 @halcyonguy @Christopher84


maybe this will help you think about your request and come up with different questions , tasks.

find pivots (peaks and valleys) for up to 4 diff agg times, and draw arrows.

this does NOT use 2nd aggregation prices.
it only uses chart time data.
(if a 2nd agg time of hour(60 min) is picked, and the chart time is 15 minutes, then 60/15 = 4 - 15 minute bars are needed to represent an hour bar)

it calculates a quantity of bars , based on a input quantity, a 2nd agg time, and the chart time.
it looks forward and back by that quantity of bars,
to determine if the current bar is a highest or lowest price (peak or valley).

it draws colored, stacked arrows on bars with a peak or valley.
if a bar has a peak for all 4 times, then there will be 4 arrows, each one above the other.
each agg time item (labels, arrows) will have a unique color.
agg1 - cyan - day
agg2 - red - 4 hours
agg3 - yellow - hour
agg4 - green - 15 minutes

if a bar quantity is set to 0, then labels and arrows for that time are not drawn.


Code:
# major_pivots_mtf_sim

#https://usethinkscript.com/threads/finding-major-pivot-points.15354/
#Finding "major" pivot points

# Find "major" pivot points 
#  higher time frames ,  day, 4hr, hr , 15m


#----------------------------
# Find "major" pivot points 
#  higher time frames ,  day, 4hr, hr , 15m


#/////////////////////////
# sub1
# peak / valley at agg time x bars

script pv {
 input len = 1;
 input lastbn = 1;

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

 def offset = Min(len - 1, lastbn - bn);
#--------------------------
# valley section
#def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
#def valley1 = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);
def valley1;
if len == 0 then {
 valley1 = 0;
} else {
 valley1 = (low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset));
}

# peak section
#def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
#def peak1 = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);
def peak1;
if len == 0 then {
peak1 = 0;
} else {
peak1 = (high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset));
}

plot peak = peak1;
plot valley = valley1;
}

#/////////////////////////




#------------------------
def na = double.nan;
def bn = BarNumber();


def lastbn = highestall(if isnan(close) then 0 else bn);
def lastcls = if lastbn then close else lastcls[1];
#def lastbar = (!isnan(close) and isnan(close[-1]));



DefineGlobalColor("agg1col", getcolor(1));
DefineGlobalColor("agg2col", getcolor(5));
DefineGlobalColor("agg3col", getcolor(8));
DefineGlobalColor("agg4col", getcolor(6));

# x.SetDefaultColor(GlobalColor("xxx");




#---------------------------------
# get chart agg time
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#---------------------------------

input agg1 = AggregationPeriod.day;
def agg1min = agg1/60000;
def min1 = if agg1min > 240 then 390 else agg1min;
def agg1ratio = min1/chartmin;
input agg1_pivot_bars = 10;
def agg1bars = roundup(agg1_pivot_bars * agg1ratio , 0);

input agg2 = AggregationPeriod.four_hours;
def agg2min = agg2/60000;
def min2 = if agg2min > 240 then 390 else agg2min;
def agg2ratio = agg2min/chartmin;
input agg2_pivot_bars = 10;
def agg2bars = roundup(agg2_pivot_bars * agg2ratio , 0);

input agg3 = AggregationPeriod.HOUR;
def agg3min = agg3/60000;
def min3 = if agg3min > 240 then 390 else agg3min;
def agg3ratio = agg3min/chartmin;
input agg3_pivot_bars = 10;
def agg3bars = roundup(agg3_pivot_bars * agg3ratio , 0);

input agg4 = AggregationPeriod.fifteen_min;
def agg4min = agg4/60000;
def min4 = if agg4min > 240 then 390 else agg4min;
def agg4ratio = agg4min/chartmin;
input agg4_pivot_bars = 10;
def agg4bars = roundup(agg4_pivot_bars * agg4ratio , 0);

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

input labels_period_stats = yes;
addlabel(labels_period_stats, " ", color.black);
addlabel(labels_period_stats, "chart " + chartmin + " min", color.magenta);

addlabel(agg1bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg1bars > 0 and labels_period_stats, "agg 1" , color.white);
addlabel(agg1bars > 0 and labels_period_stats,  min1 + " min", GlobalColor("agg1col"));
addlabel(agg1bars > 0 and labels_period_stats, "ratio " + agg1ratio, GlobalColor("agg1col"));
addlabel(agg1bars > 0 and labels_period_stats, "agg qty " + agg1_pivot_bars, GlobalColor("agg1col"));
addlabel(agg1bars > 0 and labels_period_stats, "bars " + agg1bars, GlobalColor("agg1col"));

addlabel(agg2bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg2bars > 0 and labels_period_stats, "agg 2" , color.white);
addlabel(agg2bars > 0 and labels_period_stats,  min2 + " min", GlobalColor("agg2col"));
addlabel(agg2bars > 0 and labels_period_stats, "ratio " + agg2ratio, GlobalColor("agg2col"));
addlabel(agg2bars > 0 and labels_period_stats, "agg qty " + agg2_pivot_bars, GlobalColor("agg2col"));
addlabel(agg2bars > 0 and labels_period_stats, "bars " + agg2bars, GlobalColor("agg2col"));

addlabel(agg3bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg3bars > 0 and labels_period_stats, "agg 3" , color.white);
addlabel(agg3bars > 0 and labels_period_stats,  min3 + " min", GlobalColor("agg3col"));
addlabel(agg3bars > 0 and labels_period_stats, "ratio " + agg3ratio, GlobalColor("agg3col"));
addlabel(agg3bars > 0 and labels_period_stats, "agg qty " + agg3_pivot_bars, GlobalColor("agg3col"));
addlabel(agg3bars > 0 and labels_period_stats, "bars " + agg3bars, GlobalColor("agg3col"));

addlabel(agg4bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg4bars > 0 and labels_period_stats, "agg 4" , color.white);
addlabel(agg4bars > 0 and labels_period_stats,  min4 + " min", GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, "ratio " + agg4ratio, GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, "agg qty " + agg4_pivot_bars, GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, "bars " + agg4bars, GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, " ", color.black);



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

# peaks_valleys_template_00c
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# post10  robert payne
# find peaks and valleys
# length includes current bar

#def na = double.nan;
#def bn = BarNumber();
#def lastbn = highestall(if isnan(close) then 0 else bn);
#def lastcls = if lastbn then close else lastcls[1];
##def lastbar = (!isnan(close) and isnan(close[-1]));


#input len = 4;
#def offset = Min(len - 1, lastbn - bn);
##--------------------------
## valley section
##def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
#def valley = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);
## peak section
##def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
#def peak = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);




def peak1 = pv(agg1bars , lastbn).peak;
def valley1 = pv(agg1bars , lastbn).valley;

def peak2 = pv(agg2bars , lastbn).peak;
def valley2 = pv(agg2bars , lastbn).valley;

def peak3 = pv(agg3bars , lastbn).peak;
def valley3 = pv(agg3bars , lastbn).valley;

def peak4 = pv(agg4bars , lastbn).peak;
def valley4 = pv(agg4bars , lastbn).valley;

def y = 30;
def f1 = 5;
def f2 = f1 + (1*y);
def f3 = f1 + (2*y);
def f4 = f1 + (3*y);

def tik = ticksize();


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

input show_peak_valley_arrows = yes;
def spva = show_peak_valley_arrows;


plot zv1 = if spva and Valley1 then low - (f1 * tik) else na;
zv1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv1.SetDefaultColor(GlobalColor("agg1col"));
zv1.SetLineWeight(2);

plot zp1 = if spva and peak1 then high + (f1 * tik) else na;
zp1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp1.SetDefaultColor(GlobalColor("agg1col"));
zp1.SetLineWeight(2);


plot zv2 = if spva and Valley2 then low - (f2 * tik) else na;
zv2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv2.SetDefaultColor(GlobalColor("agg2col"));
zv2.SetLineWeight(2);

plot zp2 = if spva and peak2 then high + (f2 * tik) else na;
zp2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp2.SetDefaultColor(GlobalColor("agg2col"));
zp2.SetLineWeight(2);


plot zv3 = if spva and Valley3 then low - (f3 * tik) else na;
zv3.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv3.SetDefaultColor(GlobalColor("agg3col"));
zv3.SetLineWeight(2);

plot zp3 = if spva and peak3 then high + (f3 * tik) else na;
zp3.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp3.SetDefaultColor(GlobalColor("agg3col"));
zp3.SetLineWeight(2);


plot zv4 = if spva and Valley4 then low - (f4 * tik) else na;
zv4.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv4.SetDefaultColor(GlobalColor("agg4col"));
zv4.SetLineWeight(2);

plot zp4 = if spva and peak4 then high + (f4 * tik) else na;
zp4.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp4.SetDefaultColor(GlobalColor("agg4col"));
zp4.SetLineWeight(2);
#

yCaBCIv.jpg
 
So I may be asking for the wrong thing, however, I have watched tons of videos and traders live calling it supply/Demand and also support/resistance. To be honest, it isn't consistently referenced the same.

What I am looking for is:
-Finding "major" pivot points.

Typically, by using higher time frames such as 1hr, D, 4r, and sometimes 15m. The pivot points seem to play a major role in the Break and retest strategy that I have been using for trading options on the 1 and 2m TF.
https://usethinkscript.com/threads/support-resistance-with-breaks-and-retests-for-thinkorswim.14893/

I have tested so many of the Supply/Demand and Support/Resistance indicators.
I get okay results but not very consistent in locating the precise zones.
There may be one or more out there, but I think I have tried them all on this forum.

- What I believe needs to occur in and indicator is to:
1) find the pivot points
2) Have a optional parameter that may be applied, such as
How many times this pivot point has been approached and either rejected or broken through and retested where it becomes either a support where it was previously a resistance and visa versa.
3) I assume there would need to be a range parameter that would allow for how close the pivot point can be approached for it to be considered a viable zone.
4)How far back this zone/pivot point is searched for. Could be bars, but I think for ease, it would be better to have days, weeks, months option.
4) the cloud/zone to be all the way across chart.
Also would like for it to be sizeable. Not sure if this is possible, but would be nice to have set parameters for the width of the zone.

Do you know if this is even achievable or is there an indicator out there that will accomplish this?
@samer800 @halcyonguy @Christopher84


another piece of the puzzle.

find peaks and valleys,
on every peak, a loop looks at future bars to count them if they are within the current bar + some dollar amount.
same for valleys.


Code:
# major_pivots_count_occur

#https://usethinkscript.com/threads/finding-major-pivot-points.15354/
#Finding "major" pivot points

# rules

#2) Have a optional parameter that may be applied, such as
#How many times this pivot point has been approached and either rejected or broken through and retested where it becomes either a support where it was previously a resistance and visa versa.

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

DefineGlobalColor("c1", getcolor(1));

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

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


def lastbn = highestall(if isnan(close) then 0 else bn);
def lastcls = if lastbn then close else lastcls[1];
#def lastbar = (!isnan(close) and isnan(close[-1]));

 input len = 13;

 def offset = Min(len - 1, lastbn - bn);
#--------------------------
# valley section
#def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
def valley1 = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);


# peak section
#def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
def peak1 = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);

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

input spva = yes;
plot zv1 = if spva and Valley1 then low else na;
zv1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv1.SetDefaultColor(GlobalColor("c1"));
zv1.SetLineWeight(2);

plot zp1 = if spva and peak1 then high else na;
zp1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp1.SetDefaultColor(GlobalColor("c1"));
zp1.SetLineWeight(2);


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

input near_dollar_amt = 0.2;
def barz = (lastbn - bn)+1;
# qty of future bars, within the current bar + tol.

# peaks
def future_near_peaks;
if peak1 then {
 future_near_peaks = fold i = 1 to barz
 with p
 while !isnan(close)
 do p + ( if getvalue(high, -i) < (high + near_dollar_amt) and getvalue(low, -i) > (low - near_dollar_amt) then 1 else 0
);
} else {
 future_near_peaks = future_near_peaks[1];
}

addchartbubble(peak1, low,
future_near_peaks
, color.yellow, no);


# valleys
def future_near_valleys;
if valley1 then {
 future_near_valleys = fold k = 1 to barz
 with q
 while !isnan(close)
 do q + ( if getvalue(high, -k) < (high + near_dollar_amt) and getvalue(low, -k) > (low - near_dollar_amt) then 1 else 0
);
} else {
 future_near_valleys = future_near_peaks[1];
}

addchartbubble(valley1, high,
future_near_valleys
, color.yellow, yes);


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


# lines from peak/valley bar


def pktop = if bn == 1 then na
 else if peak1 then high + near_dollar_amt 
 else pktop[1];

def pkbot = if bn == 1 then na
 else if peak1 then low - near_dollar_amt 
 else pkbot[1];



def valtop = if bn == 1 then na
 else if valley1 then high + near_dollar_amt 
 else valtop[1];

def valbot = if bn == 1 then na
 else if valley1 then low - near_dollar_amt 
 else valbot[1];

plot zptop = pktop;
plot zpbot = pkbot;
plot zvtop = valtop;
plot zvbot = valbot;

zptop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zpbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zvtop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zvbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

zptop.SetDefaultColor(Color.light_gray);
zpbot.SetDefaultColor(Color.light_gray);
zvtop.SetDefaultColor(Color.magenta);
zvbot.SetDefaultColor(Color.magenta);
#

peak/valley lines drawn only till the next one.
but the count is from current bar to the last bar, of bars that are within the lines.
2DeFJxo.jpg
 
maybe this will help you think about your request and come up with different questions , tasks.

find pivots (peaks and valleys) for up to 4 diff agg times, and draw arrows.

this does NOT use 2nd aggregation prices.
it only uses chart time data.
(if a 2nd agg time of hour(60 min) is picked, and the chart time is 15 minutes, then 60/15 = 4 - 15 minute bars are needed to represent an hour bar)

it calculates a quantity of bars , based on a input quantity, a 2nd agg time, and the chart time.
it looks forward and back by that quantity of bars,
to determine if the current bar is a highest or lowest price (peak or valley).

it draws colored, stacked arrows on bars with a peak or valley.
if a bar has a peak for all 4 times, then there will be 4 arrows, each one above the other.
each agg time item (labels, arrows) will have a unique color.
agg1 - cyan - day
agg2 - red - 4 hours
agg3 - yellow - hour
agg4 - green - 15 minutes

if a bar quantity is set to 0, then labels and arrows for that time are not drawn.


Code:
# major_pivots_mtf_sim

#https://usethinkscript.com/threads/finding-major-pivot-points.15354/
#Finding "major" pivot points

# Find "major" pivot points
#  higher time frames ,  day, 4hr, hr , 15m


#----------------------------
# Find "major" pivot points
#  higher time frames ,  day, 4hr, hr , 15m


#/////////////////////////
# sub1
# peak / valley at agg time x bars

script pv {
 input len = 1;
 input lastbn = 1;

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

 def offset = Min(len - 1, lastbn - bn);
#--------------------------
# valley section
#def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
#def valley1 = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);
def valley1;
if len == 0 then {
 valley1 = 0;
} else {
 valley1 = (low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset));
}

# peak section
#def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
#def peak1 = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);
def peak1;
if len == 0 then {
peak1 = 0;
} else {
peak1 = (high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset));
}

plot peak = peak1;
plot valley = valley1;
}

#/////////////////////////




#------------------------
def na = double.nan;
def bn = BarNumber();


def lastbn = highestall(if isnan(close) then 0 else bn);
def lastcls = if lastbn then close else lastcls[1];
#def lastbar = (!isnan(close) and isnan(close[-1]));



DefineGlobalColor("agg1col", getcolor(1));
DefineGlobalColor("agg2col", getcolor(5));
DefineGlobalColor("agg3col", getcolor(8));
DefineGlobalColor("agg4col", getcolor(6));

# x.SetDefaultColor(GlobalColor("xxx");




#---------------------------------
# get chart agg time
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#---------------------------------

input agg1 = AggregationPeriod.day;
def agg1min = agg1/60000;
def min1 = if agg1min > 240 then 390 else agg1min;
def agg1ratio = min1/chartmin;
input agg1_pivot_bars = 10;
def agg1bars = roundup(agg1_pivot_bars * agg1ratio , 0);

input agg2 = AggregationPeriod.four_hours;
def agg2min = agg2/60000;
def min2 = if agg2min > 240 then 390 else agg2min;
def agg2ratio = agg2min/chartmin;
input agg2_pivot_bars = 10;
def agg2bars = roundup(agg2_pivot_bars * agg2ratio , 0);

input agg3 = AggregationPeriod.HOUR;
def agg3min = agg3/60000;
def min3 = if agg3min > 240 then 390 else agg3min;
def agg3ratio = agg3min/chartmin;
input agg3_pivot_bars = 10;
def agg3bars = roundup(agg3_pivot_bars * agg3ratio , 0);

input agg4 = AggregationPeriod.fifteen_min;
def agg4min = agg4/60000;
def min4 = if agg4min > 240 then 390 else agg4min;
def agg4ratio = agg4min/chartmin;
input agg4_pivot_bars = 10;
def agg4bars = roundup(agg4_pivot_bars * agg4ratio , 0);

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

input labels_period_stats = yes;
addlabel(labels_period_stats, " ", color.black);
addlabel(labels_period_stats, "chart " + chartmin + " min", color.magenta);

addlabel(agg1bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg1bars > 0 and labels_period_stats, "agg 1" , color.white);
addlabel(agg1bars > 0 and labels_period_stats,  min1 + " min", GlobalColor("agg1col"));
addlabel(agg1bars > 0 and labels_period_stats, "ratio " + agg1ratio, GlobalColor("agg1col"));
addlabel(agg1bars > 0 and labels_period_stats, "agg qty " + agg1_pivot_bars, GlobalColor("agg1col"));
addlabel(agg1bars > 0 and labels_period_stats, "bars " + agg1bars, GlobalColor("agg1col"));

addlabel(agg2bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg2bars > 0 and labels_period_stats, "agg 2" , color.white);
addlabel(agg2bars > 0 and labels_period_stats,  min2 + " min", GlobalColor("agg2col"));
addlabel(agg2bars > 0 and labels_period_stats, "ratio " + agg2ratio, GlobalColor("agg2col"));
addlabel(agg2bars > 0 and labels_period_stats, "agg qty " + agg2_pivot_bars, GlobalColor("agg2col"));
addlabel(agg2bars > 0 and labels_period_stats, "bars " + agg2bars, GlobalColor("agg2col"));

addlabel(agg3bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg3bars > 0 and labels_period_stats, "agg 3" , color.white);
addlabel(agg3bars > 0 and labels_period_stats,  min3 + " min", GlobalColor("agg3col"));
addlabel(agg3bars > 0 and labels_period_stats, "ratio " + agg3ratio, GlobalColor("agg3col"));
addlabel(agg3bars > 0 and labels_period_stats, "agg qty " + agg3_pivot_bars, GlobalColor("agg3col"));
addlabel(agg3bars > 0 and labels_period_stats, "bars " + agg3bars, GlobalColor("agg3col"));

addlabel(agg4bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg4bars > 0 and labels_period_stats, "agg 4" , color.white);
addlabel(agg4bars > 0 and labels_period_stats,  min4 + " min", GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, "ratio " + agg4ratio, GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, "agg qty " + agg4_pivot_bars, GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, "bars " + agg4bars, GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, " ", color.black);



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

# peaks_valleys_template_00c
#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# post10  robert payne
# find peaks and valleys
# length includes current bar

#def na = double.nan;
#def bn = BarNumber();
#def lastbn = highestall(if isnan(close) then 0 else bn);
#def lastcls = if lastbn then close else lastcls[1];
##def lastbar = (!isnan(close) and isnan(close[-1]));


#input len = 4;
#def offset = Min(len - 1, lastbn - bn);
##--------------------------
## valley section
##def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
#def valley = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);
## peak section
##def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
#def peak = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);




def peak1 = pv(agg1bars , lastbn).peak;
def valley1 = pv(agg1bars , lastbn).valley;

def peak2 = pv(agg2bars , lastbn).peak;
def valley2 = pv(agg2bars , lastbn).valley;

def peak3 = pv(agg3bars , lastbn).peak;
def valley3 = pv(agg3bars , lastbn).valley;

def peak4 = pv(agg4bars , lastbn).peak;
def valley4 = pv(agg4bars , lastbn).valley;

def y = 30;
def f1 = 5;
def f2 = f1 + (1*y);
def f3 = f1 + (2*y);
def f4 = f1 + (3*y);

def tik = ticksize();


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

input show_peak_valley_arrows = yes;
def spva = show_peak_valley_arrows;


plot zv1 = if spva and Valley1 then low - (f1 * tik) else na;
zv1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv1.SetDefaultColor(GlobalColor("agg1col"));
zv1.SetLineWeight(2);

plot zp1 = if spva and peak1 then high + (f1 * tik) else na;
zp1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp1.SetDefaultColor(GlobalColor("agg1col"));
zp1.SetLineWeight(2);


plot zv2 = if spva and Valley2 then low - (f2 * tik) else na;
zv2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv2.SetDefaultColor(GlobalColor("agg2col"));
zv2.SetLineWeight(2);

plot zp2 = if spva and peak2 then high + (f2 * tik) else na;
zp2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp2.SetDefaultColor(GlobalColor("agg2col"));
zp2.SetLineWeight(2);


plot zv3 = if spva and Valley3 then low - (f3 * tik) else na;
zv3.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv3.SetDefaultColor(GlobalColor("agg3col"));
zv3.SetLineWeight(2);

plot zp3 = if spva and peak3 then high + (f3 * tik) else na;
zp3.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp3.SetDefaultColor(GlobalColor("agg3col"));
zp3.SetLineWeight(2);


plot zv4 = if spva and Valley4 then low - (f4 * tik) else na;
zv4.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv4.SetDefaultColor(GlobalColor("agg4col"));
zv4.SetLineWeight(2);

plot zp4 = if spva and peak4 then high + (f4 * tik) else na;
zp4.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp4.SetDefaultColor(GlobalColor("agg4col"));
zp4.SetLineWeight(2);
#

yCaBCIv.jpg
curious if there is a scan that can be done for when all 4 set up on a 5m or 30min timeframe.
 
1) find the pivot points
you skipped over the most important part,
define a pivot...

is it based on highs and lows? or body size?
is it a reversal?
is it 1 bar that has a low , that is lower than x previous bars and lower than x future bars?
-I would say that the majority of points I use is reversal point however, they are also highs and lows at that time. Not high of day. What i do using a 1hr TF, I go back however far I need to to locate reversal points that were points of reversal or retest on at least 3 and more times. Sometime 2 points will be a "Major" reversal point.
6ARkLcX.jpg


2) Have a optional parameter that may be applied, such as
How many times this pivot point has been approached and either rejected or broken through and retested where it becomes either a support where it was previously a resistance and visa versa.
that is a lot of variations, ... lots of possible values, many variables
start simple, with one parameter, get it working, then add another...
I agree

3) I assume there would need to be a range parameter that would allow for how close the pivot point can be approached for it to be considered a viable zone.
yes, what defines near to a price level ? within some % , within some $$ amount ?
I agree

4)How far back this zone/pivot point is searched for. Could be bars, but I think for ease, it would be better to have days, weeks, months option.
bars will always be easier. it's a number that can be used in a loop.
any time range would need converting.
Okay

5) the cloud/zone to be all the way across chart.
would need many variables. any guesses on the max pivots on a chart ? 4,8,10,...
The reason I added this is because some of the studies create a zone as the day goes on which I get, but I would like the zones to stay across the day I am trading on so I may use them as entry/exit points. So I really meant just across the day I am trading.

Also would like for it to be sizeable. Not sure if this is possible, but would be nice to have set parameters for the width of the zone.
what is 'it'? try not to use generic words when describing things.
size what, in what way?
What I have noticed is some indicators will draw a zone that covers most of the chart, so it really isn't useable. I get that this may be an entire consolidation area. What I would like to accomplish is a set height/width of the zone. Maybe a center pivot point that the zone is x size from that line?? Maybe this is asking too much or not relevant enough.

I actually use the Gap finder to mark those out on the stocks I am trading.

Thank you by the way. Your help is ALWAYS appreciated.
 
Thanks for work on this. One thing I must have forgot to mention is that I was hoping the indicator would draw horizontal line/zone with cloud/rectangle if possible. I can go in everyday and find these points and mark them myself. I am hoping to get an indicator that can locate and provide the zone just to save me time.
 
curious if there is a scan that can be done for when all 4 set up on a 5m or 30min timeframe.
Yes, you can add the script 4 times into the scan hacker and scan on 4 different timeframes.

No, you cannot scan for: "all 4 set up on a 5m or 30min timeframe"
Secondary aggregations are not allowed in the scanner, watchlists, or conditional orders

It is because of the fundamental way that the condition wizard works.
In the condition wizard, before we start to create the condition filters, we choose the aggregation period.
It is locked in.

After that, the scanner executes all filter conditions solely within the aggregation chosen.
If the scanner encounters an aggregation period within the filter script that doesn't match what has already been chosen; it produces the error message: "secondary aggregations not allowed".
 
you skipped over the most important part,
define a pivot...

is it based on highs and lows? or body size?
is it a reversal?
is it 1 bar that has a low , that is lower than x previous bars and lower than x future bars?
-I would say that the majority of points I use is reversal point however, they are also highs and lows at that time. Not high of day. What i do using a 1hr TF, I go back however far I need to to locate reversal points that were points of reversal or retest on at least 3 and more times. Sometime 2 points will be a "Major" reversal point.



that is a lot of variations, ... lots of possible values, many variables
start simple, with one parameter, get it working, then add another...
I agree


yes, what defines near to a price level ? within some % , within some $$ amount ?
I agree


bars will always be easier. it's a number that can be used in a loop.
any time range would need converting.
Okay


would need many variables. any guesses on the max pivots on a chart ? 4,8,10,...
The reason I added this is because some of the studies create a zone as the day goes on which I get, but I would like the zones to stay across the day I am trading on so I may use them as entry/exit points. So I really meant just across the day I am trading.


what is 'it'? try not to use generic words when describing things.
size what, in what way?
What I have noticed is some indicators will draw a zone that covers most of the chart, so it really isn't useable. I get that this may be an entire consolidation area. What I would like to accomplish is a set height/width of the zone. Maybe a center pivot point that the zone is x size from that line?? Maybe this is asking too much or not relevant enough.

I actually use the Gap finder to mark those out on the stocks I am trading.

Thank you by the way. Your help is ALWAYS appreciated.


another version to experiment with

on each peak, it looks at future peaks and valleys, and count them if within a range.
on each valley, it looks at future peaks and valleys, and count them if within a range.

can choose to continue previous lines, if next peak/valley is within a range

instead of using 2nd aggregation to find, 'longer' period peaks/valleys, for hour or whatever, i just used more bars on either side of current bar. there is a factor number, that is multiplied by the length number.

show bubbles with some counts


Code:
# major_pivots_count_00f

#https://usethinkscript.com/threads/finding-major-pivot-points.15354/
#Finding "major" pivot points

#-------------------------
DefineGlobalColor("arrowcolor", color.cyan);

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

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

def lastbn = highestall(if isnan(close) then 0 else bn);
#def lastbar = (!isnan(close) and isnan(close[-1]));
def barz_future = (lastbn - bn)+1;

#def lastcls = if lastbn then close else lastcls[1];
def lastcls = if lastbn then close else lastcls[1];

input near_dollar_amt = 0.25;

input peak_valley_length = 10;
input pv_mtf_factor = 3;
#hint pv_mtf_factor: When defining peaks and valleys, \n use a factor * a length, to calculate a longer length. \n Use a longer length instead of using 2nd aggregation.
#input len = 13;
def len = pv_mtf_factor * peak_valley_length;

input labels = yes;
addlabel(labels, " ", color.black);
addlabel(labels, peak_valley_length + " peak_valley_length", color.yellow);
addlabel(labels, pv_mtf_factor + " mtf_factor", color.yellow);
addlabel(labels, len + " length", color.yellow);

def offset = Min(len - 1, lastbn - bn);

#--------------------------
# peak section
#def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
def peak1 = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);

# valley section
#def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
def valley1 = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);

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

input show_arrows = yes;
plot zp1 = if show_arrows and peak1 then high else na;
zp1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp1.SetDefaultColor(GlobalColor("arrowcolor"));
zp1.SetLineWeight(2);

plot zv1 = if show_arrows and Valley1 then low else na;
zv1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv1.SetDefaultColor(GlobalColor("arrowcolor"));
zv1.SetLineWeight(2);

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

# compare every peak high to future peak highs. count if within a range
def pk_to_future_peaks_cnt;
if peak1 then {
 pk_to_future_peaks_cnt = fold i1 = 1 to barz_future
 with p1
 while !isnan(close)
 do p1 + (if (getvalue(peak1, -i1)
  and getvalue(high, -i1) < (high + near_dollar_amt))
  and getvalue(high, -i1) > (high - near_dollar_amt)
  then 1 else 0);
} else {
 pk_to_future_peaks_cnt = pk_to_future_peaks_cnt[1];
}


# compare every peak high to future valley lows. count if within a range
def pk_to_future_valleys_cnt;
if peak1 then {
 pk_to_future_valleys_cnt = fold i2 = 1 to barz_future
 with p2
 while !isnan(close)
 do p2 + (if (getvalue(valley1, -i2)
  and getvalue(low, -i2) < (high + near_dollar_amt))
  and getvalue(low, -i2) > (high - near_dollar_amt)
  then 1 else 0);
} else {
 pk_to_future_valleys_cnt = pk_to_future_valleys_cnt[1];
}

def pkcnt = pk_to_future_peaks_cnt + pk_to_future_valleys_cnt;

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

# compare every valley low to future peak highs. count if within a range
def val_to_future_peaks_cnt;
if valley1 then {
 val_to_future_peaks_cnt = fold i3 = 1 to barz_future
 with p3
 while !isnan(close)
 do p3 + (if (getvalue(peak1, -i3)
  and getvalue(high, -i3) < (low + near_dollar_amt))
  and getvalue(high, -i3) > (low - near_dollar_amt)
  then 1 else 0);
} else {
 val_to_future_peaks_cnt = val_to_future_peaks_cnt[1];
}

# compare every valley low to future valley lows. count if within a range
def val_to_future_valleys_cnt;
if valley1 then {
 val_to_future_valleys_cnt = fold i4 = 1 to barz_future
 with p4
 while !isnan(close)
 do p4 + (if (getvalue(valley1, -i4)
  and getvalue(low, -i4) < (low + near_dollar_amt))
  and getvalue(low, -i4) > (low - near_dollar_amt)
  then 1 else 0);
} else {
 val_to_future_valleys_cnt = val_to_future_valleys_cnt[1];
}

def valcnt = val_to_future_peaks_cnt + val_to_future_valleys_cnt;

#----------------------------
input count_min = 3;

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

input continue_lines_within_range = yes;

# lines from peak/valley bar
def pkline = if bn == 1 then 0
 else if continue_lines_within_range and peak1 and (absvalue(pkline[1] - high) <= near_dollar_amt) then pkline[1]
 else if peak1 then high
 else pkline[1];

def pklinediff = if bn == 1 then 0
 else if pkline[1] == 0 then 0
 else pkline - pkline[1];

def valline = if bn == 1 then 0
 else if continue_lines_within_range and valley1 and (absvalue(valline[1] - low) <= near_dollar_amt) then valline[1]
 else if valley1 then low
 else valline[1];

def vallinediff = if bn == 1 then 0
 else if valline[1] == 0 then 0
 else valline - valline[1];

#-----------------------
def pktop = pkline + near_dollar_amt;
def pkbot = pkline - near_dollar_amt;
def valtop = valline + near_dollar_amt;
def valbot = valline - near_dollar_amt;

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

plot pl = if pkline > 0 then pkline else na;
plot vl = if valline > 0 then valline else na;
pl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pl.SetDefaultColor(Color.cyan);
vl.SetDefaultColor(Color.magenta);

#-----------------------
plot zptop = if pkline > 0 then pktop else na;
plot zpbot = if pkline > 0 then pkbot else na;
plot zvtop = if valline > 0 then valtop else na;
plot zvbot = if valline > 0 then valbot else na;

zptop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zpbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zvtop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zvbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

zptop.SetDefaultColor(Color.gray);
zpbot.SetDefaultColor(Color.gray);
zvtop.SetDefaultColor(Color.gray);
zvbot.SetDefaultColor(Color.gray);

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

def v1 = 0.003;

input bubbles1 = yes;
addchartbubble(bubbles1 and peak1, high*(1+v1),
 pk_to_future_peaks_cnt + " p-p\n" +
 pk_to_future_valleys_cnt + " p-v\n" +
 pkcnt + " peak cnts\n" +
 pklinediff + " diff"
# pk_to_future_peaks_cnt
, color.yellow, yes);

addchartbubble(bubbles1 and valley1, low*(1-v1),
val_to_future_peaks_cnt + " v-p\n" +
val_to_future_valleys_cnt + " v-v\n" +
valcnt + " val cnts\n" +
vallinediff + " diff"
, color.yellow, no);

#

7pBSCbB.jpg
 
Last edited:
another version to experiment with

an each peak, it looks at future peaks and valleys, and count them if within a range.
an each valley, it looks at future peaks and valleys, and count them if within a range.

can choose to continue previous lines, if next peak/valley is within a range

instead of using 2nd aggregation to find, 'longer' period peaks/valleys, for hour or whatever, i just used more bars on either side of current bar. there is a factor number, that is multiplied by the length number.

show bubbles with some counts


Code:
# major_pivots_count_00f

#https://usethinkscript.com/threads/finding-major-pivot-points.15354/
#Finding "major" pivot points

#-------------------------
DefineGlobalColor("arrowcolor", color.cyan);

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

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

def lastbn = highestall(if isnan(close) then 0 else bn);
#def lastbar = (!isnan(close) and isnan(close[-1]));
def barz_future = (lastbn - bn)+1;

#def lastcls = if lastbn then close else lastcls[1];
def lastcls = if lastbn then close else lastcls[1];

input near_dollar_amt = 0.25;

input peak_valley_length = 10;
input pv_mtf_factor = 3;
#hint pv_mtf_factor: When defining peaks and valleys, \n use a factor * a length, to calculate a longer length. \n Use a longer length instead of using 2nd aggregation.
#input len = 13;
def len = pv_mtf_factor * peak_valley_length;

input labels = yes;
addlabel(labels, " ", color.black);
addlabel(labels, peak_valley_length + " peak_valley_length", color.yellow);
addlabel(labels, pv_mtf_factor + " mtf_factor", color.yellow);
addlabel(labels, len + " length", color.yellow);

def offset = Min(len - 1, lastbn - bn);

#--------------------------
# peak section
#def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
def peak1 = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);

# valley section
#def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
def valley1 = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);

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

input show_arrows = yes;
plot zp1 = if show_arrows and peak1 then high else na;
zp1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp1.SetDefaultColor(GlobalColor("arrowcolor"));
zp1.SetLineWeight(2);

plot zv1 = if show_arrows and Valley1 then low else na;
zv1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv1.SetDefaultColor(GlobalColor("arrowcolor"));
zv1.SetLineWeight(2);

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

# compare every peak high to future peak highs. count if within a range
def pk_to_future_peaks_cnt;
if peak1 then {
 pk_to_future_peaks_cnt = fold i1 = 1 to barz_future
 with p1
 while !isnan(close)
 do p1 + (if (getvalue(peak1, -i1)
  and getvalue(high, -i1) < (high + near_dollar_amt))
  and getvalue(high, -i1) > (high - near_dollar_amt)
  then 1 else 0);
} else {
 pk_to_future_peaks_cnt = pk_to_future_peaks_cnt[1];
}


# compare every peak high to future valley lows. count if within a range
def pk_to_future_valleys_cnt;
if peak1 then {
 pk_to_future_valleys_cnt = fold i2 = 1 to barz_future
 with p2
 while !isnan(close)
 do p2 + (if (getvalue(valley1, -i2)
  and getvalue(low, -i2) < (high + near_dollar_amt))
  and getvalue(low, -i2) > (high - near_dollar_amt)
  then 1 else 0);
} else {
 pk_to_future_valleys_cnt = pk_to_future_valleys_cnt[1];
}

def pkcnt = pk_to_future_peaks_cnt + pk_to_future_valleys_cnt;

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

# compare every valley low to future peak highs. count if within a range
def val_to_future_peaks_cnt;
if valley1 then {
 val_to_future_peaks_cnt = fold i3 = 1 to barz_future
 with p3
 while !isnan(close)
 do p3 + (if (getvalue(peak1, -i3)
  and getvalue(high, -i3) < (low + near_dollar_amt))
  and getvalue(high, -i3) > (low - near_dollar_amt)
  then 1 else 0);
} else {
 val_to_future_peaks_cnt = val_to_future_peaks_cnt[1];
}

# compare every valley low to future valley lows. count if within a range
def val_to_future_valleys_cnt;
if valley1 then {
 val_to_future_valleys_cnt = fold i4 = 1 to barz_future
 with p4
 while !isnan(close)
 do p4 + (if (getvalue(valley1, -i4)
  and getvalue(low, -i4) < (low + near_dollar_amt))
  and getvalue(low, -i4) > (low - near_dollar_amt)
  then 1 else 0);
} else {
 val_to_future_valleys_cnt = val_to_future_valleys_cnt[1];
}

def valcnt = val_to_future_peaks_cnt + val_to_future_valleys_cnt;

#----------------------------
input count_min = 3;

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

input continue_lines_within_range = yes;

# lines from peak/valley bar
def pkline = if bn == 1 then 0
 else if continue_lines_within_range and peak1 and (absvalue(pkline[1] - high) <= near_dollar_amt) then pkline[1]
 else if peak1 then high
 else pkline[1];

def pklinediff = if bn == 1 then 0
 else if pkline[1] == 0 then 0
 else pkline - pkline[1];

def valline = if bn == 1 then 0
 else if continue_lines_within_range and valley1 and (absvalue(valline[1] - low) <= near_dollar_amt) then valline[1]
 else if valley1 then low
 else valline[1];

def vallinediff = if bn == 1 then 0
 else if valline[1] == 0 then 0
 else valline - valline[1];

#-----------------------
def pktop = pkline + near_dollar_amt;
def pkbot = pkline - near_dollar_amt;
def valtop = valline + near_dollar_amt;
def valbot = valline - near_dollar_amt;

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

plot pl = if pkline > 0 then pkline else na;
plot vl = if valline > 0 then valline else na;
pl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pl.SetDefaultColor(Color.cyan);
vl.SetDefaultColor(Color.magenta);

#-----------------------
plot zptop = if pkline > 0 then pktop else na;
plot zpbot = if pkline > 0 then pkbot else na;
plot zvtop = if valline > 0 then valtop else na;
plot zvbot = if valline > 0 then valbot else na;

zptop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zpbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zvtop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zvbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

zptop.SetDefaultColor(Color.gray);
zpbot.SetDefaultColor(Color.gray);
zvtop.SetDefaultColor(Color.gray);
zvbot.SetDefaultColor(Color.gray);

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

def v1 = 0.003;

input bubbles1 = yes;
addchartbubble(bubbles1 and peak1, high*(1+v1),
 pk_to_future_peaks_cnt + " p-p\n" +
 pk_to_future_valleys_cnt + " p-v\n" +
 pkcnt + " peak cnts\n" +
 pklinediff + " diff"
# pk_to_future_peaks_cnt
, color.yellow, yes);

addchartbubble(bubbles1 and valley1, low*(1-v1),
val_to_future_peaks_cnt + " v-p\n" +
val_to_future_valleys_cnt + " v-v\n" +
valcnt + " val cnts\n" +
vallinediff + " diff"
, color.yellow, no);

#

7pBSCbB.jpg
This is really close. Thank you for this. Is there a way to have the lines/zones carry all the way across The next day of trading? Say it is 9:00 am and the market isn't open. IS there a way to have the zones go all the way across the chart to 16:00? Hope this make sense. The point is to have these "Major" zones set in place and when the price tests that zone, I place a trade.
I looked at @BenTen Wolf Wave Trend Lines and it plots all the way across. I believe he used LinePlot function. I hope that is doable.
 
Last edited:
This is really close. Thank you for this. Is there a way to have the lines/zones carry all the way across The next day of trading? Say it is 9:00 am and the market isn't open. IS there a way to have the zones go all the way across the chart to 16:00? Hope this make sense. The point is to have these "Major" zones set in place and when the price tests that zone, I place a trade.
I looked at @BenTen Wolf Wave Trend Lines and it plots all the way across. I believe he used LinePlot function. I hope that is doable.

there is no lineplot function.
can't draw lines from within a loop.
if you want multiple lines to draw across the chart, you need multiple sets of supporting formulas and a plot. if there are 12 peaks, then you would want 12 lines. that would need to have 12 sets of formulas and 12 plots to do it. if a 13th peak appeared, the 1st line would stop plotting and the newest one would start plotting.

i can look at my post9 code and see if i can simplify it and add a few plots.... but no guarantees.
 
@METAL .. I've been playing around with the same concept, but using ZigZag pivots and have found them very useful in my trading. The code will plot the last 10 pivots to the right of the current prices.

Code:
# Dap711 - 2024

declare upper;

input showZigZag              = no;
input showPivots              = yes;
input percentamount           = .5;
input revAmount               = 0.0;
input atrreversal             = 1.5;
input atrlength               = 5;

def zz = ZigZagHighLow("price h" = high, "price l" = low, "percentage reversal" = percentAmount, "absolute reversal" = revAmount, "atr length" =atrlength, "atr reversal" = atrreversal);
def reversalAmount        = if (close * percentamount / 100) > Max(revAmount < atrreversal * atrlength, revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * atrlength then atrreversal * atrlength else revAmount;
def zzSave = if !IsNaN(zz) then zz else GetValue(zzSave, 1);
def chg = (if zzSave == high then high else low) - GetValue(zzSave, 1);
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(zz, 1)) and GetValue(isConf, 1));
def zzd = if isUp then 1 else 0;
plot zzp = if zzd <= 1 then zz else Double.NaN;
zzp.AssignValueColor(if zzd == 1 then Color.GREEN else if zzd == 0 then Color.RED else Color.DARK_ORANGE);
zzp.SetStyle(Curve.FIRM);
zzp.EnableApproximation();
zzp.SetHiding(!ShowZigZag);
def xxhigh = if zzSave == high then  high else xxhigh[1];
def chghigh = high - xxhigh[1];
def xxlow = if zzSave == low then low else xxlow[1];
def chglow = low - xxlow[1];
rec zzcount = if zzSave[1] != zzSave then 1 else if zzSave[1] == zzSave then zzcount[1] + 1 else 0;
def zzcounthilo   =  if zzcounthilo[1] == 0 and (zzSave == high or zzSave == low) then 1 else if zzSave == high or zzSave == low then zzcounthilo[1] + 1 else zzcounthilo[1];
def zzhilo = if zzSave == high or zzSave == low then zzcounthilo else zzcounthilo + 1;
def zzcounthigh = if zzSave == high then zzcount[1] else Double.NaN;
def zzcountlow =  if zzSave == low then zzcount[1] else Double.NaN;
def zzsave1 = if !IsNaN(zzSave) then zzSave else zzsave1[1];
def zzsave2 = zzsave1;
def priorzz0  = if zzsave2  != zzsave2[1]  then zzsave2[1]  else priorzz0[1];
def priorzz1  = if priorzz0 != priorzz0[1] then priorzz0[1] else priorzz1[1];
def priorzz2  = if priorzz1 != priorzz1[1] then priorzz1[1] else priorzz2[1];
def priorzz3  = if priorzz2 != priorzz2[1] then priorzz2[1] else priorzz3[1];
def priorzz4  = if priorzz3 != priorzz3[1] then priorzz3[1] else priorzz4[1];
def priorzz5  = if priorzz4 != priorzz4[1] then priorzz4[1] else priorzz5[1];
def priorzz6  = if priorzz5 != priorzz5[1] then priorzz5[1] else priorzz6[1];
def priorzz7  = if priorzz6 != priorzz6[1] then priorzz6[1] else priorzz7[1];
def priorzz8  = if priorzz7 != priorzz7[1] then priorzz7[1] else priorzz8[1];
def priorzz9  = if priorzz8 != priorzz8[1] then priorzz8[1] else priorzz9[1];
def priorzz10 = if priorzz9 != priorzz9[1] then priorzz9[1] else priorzz10[1];


plot Line1 = if isNaN(close) and !isnan(close[50]) then priorzz1[-1] else Double.NaN;
     Line1.SetDefaultColor(Color.YELLOW);
     Line1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line1.SetHiding(!ShowPivots);
     Line1.HideTitle();
     Line1.HideBubble();
plot Line2 = if isNaN(close) and !isnan(close[50]) then priorzz2[-1] else Double.NaN;
     Line2.SetDefaultColor(Color.YELLOW);
     Line2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line2.SetHiding(!ShowPivots);
     Line2.HideTitle();
     Line2.HideBubble();
plot Line3 = if isNaN(close) and !isnan(close[50]) then priorzz3[-1] else Double.NaN;
     Line3.SetDefaultColor(Color.YELLOW);
     Line3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line3.SetHiding(!ShowPivots);
     Line3.HideTitle();
     Line3.HideBubble();
plot Line4 = if isNaN(close) and !isnan(close[50]) then priorzz4[-1] else Double.NaN;
     Line4.SetDefaultColor(Color.YELLOW);
     Line4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line4.SetHiding(!ShowPivots);
     Line4.HideTitle();
     Line4.HideBubble();
plot Line5 = if isNaN(close) and !isnan(close[50]) then priorzz5[-1] else Double.NaN;
     Line5.SetDefaultColor(Color.YELLOW);
     Line5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line5.SetHiding(!ShowPivots);
     Line5.HideTitle();
     Line5.HideBubble();
plot Line6 = if isNaN(close) and !isnan(close[50]) then priorzz6[-1] else Double.NaN;
     Line6.SetDefaultColor(Color.YELLOW);
     Line6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line6.SetHiding(!ShowPivots);
     Line6.HideTitle();
     Line6.HideBubble();
plot Line7 = if isNaN(close) and !isnan(close[50]) then priorzz7[-1] else Double.NaN;
     Line7.SetDefaultColor(Color.YELLOW);
     Line7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line7.SetHiding(!ShowPivots);
     Line7.HideTitle();
     Line7.HideBubble();
plot Line8 = if isNaN(close) and !isnan(close[50]) then priorzz8[-1] else Double.NaN;
     Line8.SetDefaultColor(Color.YELLOW);
     Line8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line8.SetHiding(!ShowPivots);
     Line8.HideTitle();
     Line8.HideBubble();
plot Line9 = if isNaN(close) and !isnan(close[50]) then priorzz9[-1] else Double.NaN;
     Line9.SetDefaultColor(Color.YELLOW);
     Line9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line9.SetHiding(!ShowPivots);
     Line9.HideTitle();
     Line9.HideBubble();
plot Line10 = if isNaN(close) and !isnan(close[50]) then priorzz10[-1] else Double.NaN;
     Line10.SetDefaultColor(Color.YELLOW);
     Line10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
     Line10.SetHiding(!ShowPivots);
     Line10.HideTitle();
     Line10.HideBubble();
 

Attachments

  • ZigZag Pivots.jpg
    ZigZag Pivots.jpg
    163.2 KB · Views: 125
Hello, I love this program from someone else post but It shows & display too much in 30 days...180 days, I can't able see candle in the chart, It's a little bother my eyes to view. Can you able help me please to change only one day showing display ? I appreciate your time & attention this matter. Thanks. post bellow:


#https://usethinkscript.com/threads/finding-major-pivot-points.15354/
#Finding "major" pivot points

# Find "major" pivot points
# higher time frames , day, 4hr, hr , 15m


#----------------------------
# Find "major" pivot points
# higher time frames , day, 4hr, hr , 15m


#/////////////////////////
# sub1
# peak / valley at agg time x bars

script pv {
input len = 1;
input lastbn = 1;

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

def offset = Min(len - 1, lastbn - bn);
#--------------------------
# valley section
#def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
#def valley1 = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);
def valley1;
if len == 0 then {
valley1 = 0;
} else {
valley1 = (low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset));
}

# peak section
#def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
#def peak1 = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);
def peak1;
if len == 0 then {
peak1 = 0;
} else {
peak1 = (high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset));
}

plot peak = peak1;
plot valley = valley1;
}

#/////////////////////////




#------------------------
def na = double.nan;
def bn = BarNumber();


def lastbn = highestall(if isnan(close) then 0 else bn);
def lastcls = if lastbn then close else lastcls[1];
#def lastbar = (!isnan(close) and isnan(close[-1]));



DefineGlobalColor("agg1col", getcolor(1));
DefineGlobalColor("agg2col", getcolor(5));
DefineGlobalColor("agg3col", getcolor(8));
DefineGlobalColor("agg4col", getcolor(6));

# x.SetDefaultColor(GlobalColor("xxx");




#---------------------------------
# get chart agg time
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#---------------------------------

input agg1 = AggregationPeriod.day;
def agg1min = agg1/60000;
def min1 = if agg1min > 240 then 390 else agg1min;
def agg1ratio = min1/chartmin;
input agg1_pivot_bars = 10;
def agg1bars = roundup(agg1_pivot_bars * agg1ratio , 0);

input agg2 = AggregationPeriod.four_hours;
def agg2min = agg2/60000;
def min2 = if agg2min > 240 then 390 else agg2min;
def agg2ratio = agg2min/chartmin;
input agg2_pivot_bars = 10;
def agg2bars = roundup(agg2_pivot_bars * agg2ratio , 0);

input agg3 = AggregationPeriod.HOUR;
def agg3min = agg3/60000;
def min3 = if agg3min > 240 then 390 else agg3min;
def agg3ratio = agg3min/chartmin;
input agg3_pivot_bars = 10;
def agg3bars = roundup(agg3_pivot_bars * agg3ratio , 0);

input agg4 = AggregationPeriod.fifteen_min;
def agg4min = agg4/60000;
def min4 = if agg4min > 240 then 390 else agg4min;
def agg4ratio = agg4min/chartmin;
input agg4_pivot_bars = 10;
def agg4bars = roundup(agg4_pivot_bars * agg4ratio , 0);

input agg5 = AggregationPeriod.five_min;
def agg5min = agg5/60000;
def min5 = if agg5min > 240 then 390 else agg5min;
def agg5ratio = agg5min/chartmin;
input agg5_pivot_bars = 10;
def agg5bars = roundup(agg5_pivot_bars * agg5ratio , 0);


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

input labels_period_stats = yes;
addlabel(labels_period_stats, " ", color.black);
addlabel(labels_period_stats, "chart " + chartmin + " min", color.magenta);

addlabel(agg1bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg1bars > 0 and labels_period_stats, "agg 1" , color.white);
addlabel(agg1bars > 0 and labels_period_stats, min1 + " min", GlobalColor("agg1col"));
addlabel(agg1bars > 0 and labels_period_stats, "ratio " + agg1ratio, GlobalColor("agg1col"));
addlabel(agg1bars > 0 and labels_period_stats, "agg qty " + agg1_pivot_bars, GlobalColor("agg1col"));
addlabel(agg1bars > 0 and labels_period_stats, "bars " + agg1bars, GlobalColor("agg1col"));

addlabel(agg2bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg2bars > 0 and labels_period_stats, "agg 2" , color.white);
addlabel(agg2bars > 0 and labels_period_stats, min2 + " min", GlobalColor("agg2col"));
addlabel(agg2bars > 0 and labels_period_stats, "ratio " + agg2ratio, GlobalColor("agg2col"));
addlabel(agg2bars > 0 and labels_period_stats, "agg qty " + agg2_pivot_bars, GlobalColor("agg2col"));
addlabel(agg2bars > 0 and labels_period_stats, "bars " + agg2bars, GlobalColor("agg2col"));

addlabel(agg3bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg3bars > 0 and labels_period_stats, "agg 3" , color.white);
addlabel(agg3bars > 0 and labels_period_stats, min3 + " min", GlobalColor("agg3col"));
addlabel(agg3bars > 0 and labels_period_stats, "ratio " + agg3ratio, GlobalColor("agg3col"));
addlabel(agg3bars > 0 and labels_period_stats, "agg qty " + agg3_pivot_bars, GlobalColor("agg3col"));
addlabel(agg3bars > 0 and labels_period_stats, "bars " + agg3bars, GlobalColor("agg3col"));

addlabel(agg4bars > 0 and labels_period_stats, " ", color.black);
addlabel(agg4bars > 0 and labels_period_stats, "agg 4" , color.white);
addlabel(agg4bars > 0 and labels_period_stats, min4 + " min", GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, "ratio " + agg4ratio, GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, "agg qty " + agg4_pivot_bars, GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, "bars " + agg4bars, GlobalColor("agg4col"));
addlabel(agg4bars > 0 and labels_period_stats, " ", color.black);



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

# peaks_valleys_template_00c
#https://usethinkscript.com/threads/...y-demand-zones-for-thinkorswim.172/#post-7048
# post10 robert payne
# find peaks and valleys
# length includes current bar

#def na = double.nan;
#def bn = BarNumber();
#def lastbn = highestall(if isnan(close) then 0 else bn);
#def lastcls = if lastbn then close else lastcls[1];
##def lastbar = (!isnan(close) and isnan(close[-1]));


#input len = 4;
#def offset = Min(len - 1, lastbn - bn);
##--------------------------
## valley section
##def Valley = low < Lowest(low[1], len) and low < Lowest(low[-len], len);
#def valley = low < Lowest(low[1], len - 1) and low == GetValue(Lowest(low, len), -offset);
## peak section
##def Peak = high > highest(high[1], len) and high > highest(high[-len], len);
#def peak = high > highest(high[1], len - 1) and high == GetValue(highest(high, len), -offset);




def peak1 = pv(agg1bars , lastbn).peak;
def valley1 = pv(agg1bars , lastbn).valley;

def peak2 = pv(agg2bars , lastbn).peak;
def valley2 = pv(agg2bars , lastbn).valley;

def peak3 = pv(agg3bars , lastbn).peak;
def valley3 = pv(agg3bars , lastbn).valley;

def peak4 = pv(agg4bars , lastbn).peak;
def valley4 = pv(agg4bars , lastbn).valley;

def peak5 = pv(agg5bars , lastbn).peak;
def valley5 = pv(agg5bars , lastbn).valley;

def y = 30;
def f1 = 5;
def f2 = f1 + (1*y);
def f3 = f1 + (2*y);
def f4 = f1 + (3*y);
def f5 = f1 + (4*y);

def tik = ticksize();


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

input show_peak_valley_arrows = yes;
def spva = show_peak_valley_arrows;


plot zv1 = if spva and Valley1 then low - (f1 * tik) else na;
zv1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv1.SetDefaultColor(GlobalColor("agg1col"));
zv1.SetLineWeight(2);

plot zp1 = if spva and peak1 then high + (f1 * tik) else na;
zp1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp1.SetDefaultColor(GlobalColor("agg1col"));
zp1.SetLineWeight(2);


plot zv2 = if spva and Valley2 then low - (f2 * tik) else na;
zv2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv2.SetDefaultColor(GlobalColor("agg2col"));
zv2.SetLineWeight(2);

plot zp2 = if spva and peak2 then high + (f2 * tik) else na;
zp2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp2.SetDefaultColor(GlobalColor("agg2col"));
zp2.SetLineWeight(2);


plot zv3 = if spva and Valley3 then low - (f3 * tik) else na;
zv3.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv3.SetDefaultColor(GlobalColor("agg3col"));
zv3.SetLineWeight(2);

plot zp3 = if spva and peak3 then high + (f3 * tik) else na;
zp3.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp3.SetDefaultColor(GlobalColor("agg3col"));
zp3.SetLineWeight(2);


plot zv4 = if spva and Valley4 then low - (f4 * tik) else na;
zv4.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv4.SetDefaultColor(GlobalColor("agg4col"));
zv4.SetLineWeight(2);

plot zp4 = if spva and peak4 then high + (f4 * tik) else na;
zp4.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp4.SetDefaultColor(GlobalColor("agg4col"));
zp4.SetLineWeight(2);

plot zv5 = if spva and Valley5 then low - (f5 * tik) else na;
zv5.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zv5.SetDefaultColor(GlobalColor("agg4col"));
zv5.SetLineWeight(2);

plot zp5 = if spva and peak5 then high + (f5 * tik) else na;
zp5.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zp5.SetDefaultColor(GlobalColor("agg4col"));
zp5.SetLineWeight(2);

# end
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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