# Indicator For TOS
# @AlgoAlpha
#indicator("Dynamic Supply and Demand Zones [AlgoAlpha]", "AlgoAlpha - 📦Dynamic Supply/Demand",
#Hint dynamic: If true, the indicator adjusts its lookback such that it considers data from the previous major pivot point to present.
# Converted by Sam4Cok@Samer800 - 11/2024 - Not Exact conv.
# Updated Label Location - Sam4Cok@Samer800 - 11/2024
input labelOptions = {"Left", "Right", Default "Center", "Don't Show"};
input dynamic = yes; # "Use Dynamic Look-Back"
input lookback = 200;
input Resolution = 40; #, "Resolution"
input ZoneTolerance = 0.93; #,"Zone Tolerance",toolti
def na = Double.NaN;
def last = isNaN(close);
def n = if BarNumber() < 1 then 1 else BarNumber();
def bar = if !last then n else Bar[1];
def res = Min(Max(Resolution, 1), 50);
def zone = Min(Max(ZoneTolerance, 0.01), 1);
Script Pivot {
input series = close;
input leftBars = 10;
input rightBars = 10;
input isHigh = yes;
def na = Double.NaN;
def HH = series == Highest(series, leftBars + 1);
def LL = series == Lowest(series, leftBars + 1);
def pivotRange = (leftBars + rightBars + 1);
def leftEdgeValue = if series[pivotRange] ==0 then na else series[pivotRange];
def pvtCond = !isNaN(series) and leftBars > 0 and rightBars > 0 and !isNaN(leftEdgeValue);
def barIndexH = if pvtCond then
fold i = 1 to rightBars + 1 with p=1 while p do
series > GetValue(series, - i) else na;
def barIndexL = if pvtCond then
fold j = 1 to rightBars + 1 with q=1 while q do
series < GetValue(series, - j) else na;
def PivotPoint;
if isHigh {
PivotPoint = if HH and barIndexH then series else na;
} else {
PivotPoint = if LL and barIndexL then series else na;
}
plot pvt = PivotPoint;
}
def ph = pivot(high[lookback], lookback, lookback, yes);
def pl = pivot(low[lookback], lookback, lookback, no);
def nPh = !isNaN(ph);
def nPl = !isNaN(pl);
def x1 = if (nPh or nPl) then lookback else x1[1] + 1;
def x = if x1 > lookback then x1 else lookback;
def len1 = if dynamic then x else lookback;
def sartCond = bar >= highestAll(bar - len1);
def highs = if sartCond then Max(highs[1], high) else highs[1];
def lows = if sartCond then Min(if(lows[1], lows[1], low), low) else lows[1];
def maxx = highestAll(InertiaAll(highs, 2));
def minn = highestAll(InertiaAll(lows, 2));
def step = (maxx - minn) / res;
plot hh = if sartCond and !last then maxx else na;
plot ll = if sartCond and !last then minn else na;
hh.SetDefaultColor(Color.RED);
ll.SetDefaultColor(Color.GREEN);
AddCloud(hh, ll, CreateColor(26,26,26));
def lvl00 = minn;
def lvl01 = if res < 1 then na else minn + ((01)*step);
def lvl02 = if res < 2 then na else minn + ((02)*step);
def lvl03 = if res < 3 then na else minn + ((03)*step);
def lvl04 = if res < 4 then na else minn + ((04)*step);
def lvl05 = if res < 5 then na else minn + ((05)*step);
def lvl06 = if res < 6 then na else minn + ((06)*step);
def lvl07 = if res < 7 then na else minn + ((07)*step);
def lvl08 = if res < 8 then na else minn + ((08)*step);
def lvl09 = if res < 9 then na else minn + ((09)*step);
def lvl10 = if res < 10 then na else minn + ((10)*step);
def lvl11 = if res < 11 then na else minn + ((11)*step);
def lvl12 = if res < 12 then na else minn + ((12)*step);
def lvl13 = if res < 13 then na else minn + ((13)*step);
def lvl14 = if res < 14 then na else minn + ((14)*step);
def lvl15 = if res < 15 then na else minn + ((15)*step);
def lvl16 = if res < 16 then na else minn + ((16)*step);
def lvl17 = if res < 17 then na else minn + ((17)*step);
def lvl18 = if res < 18 then na else minn + ((18)*step);
def lvl19 = if res < 19 then na else minn + ((19)*step);
def lvl20 = if res < 20 then na else minn + ((20)*step);
def lvl21 = if res < 21 then na else minn + ((21)*step);
def lvl22 = if res < 22 then na else minn + ((22)*step);
def lvl23 = if res < 23 then na else minn + ((23)*step);
def lvl24 = if res < 24 then na else minn + ((24)*step);
def lvl25 = if res < 25 then na else minn + ((25)*step);
def lvl26 = if res < 26 then na else minn + ((26)*step);
def lvl27 = if res < 27 then na else minn + ((27)*step);
def lvl28 = if res < 28 then na else minn + ((28)*step);
def lvl29 = if res < 29 then na else minn + ((29)*step);
def lvl30 = if res < 30 then na else minn + ((30)*step);
def lvl31 = if res < 31 then na else minn + ((31)*step);
def lvl32 = if res < 32 then na else minn + ((32)*step);
def lvl33 = if res < 33 then na else minn + ((33)*step);
def lvl34 = if res < 34 then na else minn + ((34)*step);
def lvl35 = if res < 35 then na else minn + ((35)*step);
def lvl36 = if res < 36 then na else minn + ((36)*step);
def lvl37 = if res < 37 then na else minn + ((37)*step);
def lvl38 = if res < 38 then na else minn + ((38)*step);
def lvl39 = if res < 39 then na else minn + ((39)*step);
def lvl40 = if res < 40 then na else minn + ((40)*step);
def lvl41 = if res < 41 then na else minn + ((41)*step);
def lvl42 = if res < 42 then na else minn + ((42)*step);
def lvl43 = if res < 43 then na else minn + ((43)*step);
def lvl44 = if res < 44 then na else minn + ((44)*step);
def lvl45 = if res < 45 then na else minn + ((45)*step);
def lvl46 = if res < 46 then na else minn + ((46)*step);
def lvl47 = if res < 47 then na else minn + ((47)*step);
def lvl48 = if res < 48 then na else minn + ((48)*step);
def lvl49 = if res < 49 then na else minn + ((49)*step);
def lvl50 = if res < 50 then na else minn + ((50)*step);
#Script nz {
#input src = close;
# def nzL = if isNaN(src) then 0 else src;
# plot out = highestAll(inertiaAll(nzL, 2));
#}
Script vol {
input lvl1 = low;
input lvl2 = high;
input len = 1;
def x = if isNaN(len) then 1 else len;
def bin0 = fold i = 0 to x with p=1 do
p + (if !(GetValue(low,i)>lvl1 or GetValue(high,i)<lvl2) then GetValue(volume,i) else 0);
def nzL = if isNaN(bin0) then 1 else bin0;
def bin = highestAll(inertiaAll(nzL, 2));
plot out = bin;
}
def bin00 = vol(lvl01, lvl00, x);
def bin01 = vol(lvl02, lvl01, x);
def bin02 = vol(lvl03, lvl02, x);
def bin03 = vol(lvl04, lvl03, x);
def bin04 = vol(lvl05, lvl04, x);
def bin05 = vol(lvl06, lvl05, x);
def bin06 = vol(lvl07, lvl06, x);
def bin07 = vol(lvl08, lvl07, x);
def bin08 = vol(lvl09, lvl08, x);
def bin09 = vol(lvl10, lvl09, x);
def bin10 = vol(lvl11, lvl10, x);
def bin11 = vol(lvl12, lvl11, x);
def bin12 = vol(lvl13, lvl12, x);
def bin13 = vol(lvl14, lvl13, x);
def bin14 = vol(lvl15, lvl14, x);
def bin15 = vol(lvl16, lvl15, x);
def bin16 = vol(lvl17, lvl16, x);
def bin17 = vol(lvl18, lvl17, x);
def bin18 = vol(lvl19, lvl18, x);
def bin19 = vol(lvl20, lvl19, x);
def bin20 = vol(lvl21, lvl20, x);
def bin21 = vol(lvl22, lvl21, x);
def bin22 = vol(lvl23, lvl22, x);
def bin23 = vol(lvl24, lvl23, x);
def bin24 = vol(lvl25, lvl24, x);
def bin25 = vol(lvl26, lvl25, x);
def bin26 = vol(lvl27, lvl26, x);
def bin27 = vol(lvl28, lvl27, x);
def bin28 = vol(lvl29, lvl28, x);
def bin29 = vol(lvl30, lvl29, x);
def bin30 = vol(lvl31, lvl30, x);
def bin31 = vol(lvl32, lvl31, x);
def bin32 = vol(lvl33, lvl32, x);
def bin33 = vol(lvl34, lvl33, x);
def bin34 = vol(lvl35, lvl34, x);
def bin35 = vol(lvl36, lvl35, x);
def bin36 = vol(lvl37, lvl36, x);
def bin37 = vol(lvl38, lvl37, x);
def bin38 = vol(lvl39, lvl38, x);
def bin39 = vol(lvl40, lvl39, x);
def bin40 = vol(lvl41, lvl40, x);
def bin41 = vol(lvl42, lvl41, x);
def bin42 = vol(lvl43, lvl42, x);
def bin43 = vol(lvl44, lvl43, x);
def bin44 = vol(lvl45, lvl44, x);
def bin45 = vol(lvl46, lvl45, x);
def bin46 = vol(lvl47, lvl46, x);
def bin47 = vol(lvl48, lvl47, x);
def bin48 = vol(lvl49, lvl48, x);
def bin49 = vol(lvl50, lvl49, x);
def iskey00 = (bin00 < bin01*zone);
def iskey01 = (bin01 < bin00*zone) and (if res == 2 then yes else bin01 < bin02*zone);
def iskey02 = (bin02 < bin01*zone) and (if res == 3 then yes else bin02 < bin03*zone);
def iskey03 = (bin03 < bin02*zone) and (if res == 4 then yes else bin03 < bin04*zone);
def iskey04 = (bin04 < bin03*zone) and (if res == 5 then yes else bin04 < bin05*zone);
def iskey05 = (bin05 < bin04*zone) and (if res == 6 then yes else bin05 < bin06*zone);
def iskey06 = (bin06 < bin05*zone) and (if res == 7 then yes else bin06 < bin07*zone);
def iskey07 = (bin07 < bin06*zone) and (if res == 8 then yes else bin07 < bin08*zone);
def iskey08 = (bin08 < bin07*zone) and (if res == 9 then yes else bin08 < bin09*zone);
def iskey09 = (bin09 < bin08*zone) and (if res == 10 then yes else bin09 < bin10*zone);
def iskey10 = (bin10 < bin09*zone) and (if res == 11 then yes else bin10 < bin11*zone);
def iskey11 = (bin11 < bin10*zone) and (if res == 12 then yes else bin11 < bin12*zone);
def iskey12 = (bin12 < bin11*zone) and (if res == 13 then yes else bin12 < bin13*zone);
def iskey13 = (bin13 < bin12*zone) and (if res == 14 then yes else bin13 < bin14*zone);
def iskey14 = (bin14 < bin13*zone) and (if res == 15 then yes else bin14 < bin15*zone);
def iskey15 = (bin15 < bin14*zone) and (if res == 16 then yes else bin15 < bin16*zone);
def iskey16 = (bin16 < bin15*zone) and (if res == 17 then yes else bin16 < bin17*zone);
def iskey17 = (bin17 < bin16*zone) and (if res == 18 then yes else bin17 < bin18*zone);
def iskey18 = (bin18 < bin17*zone) and (if res == 19 then yes else bin18 < bin19*zone);
def iskey19 = (bin19 < bin18*zone) and (if res == 20 then yes else bin19 < bin20*zone);
def iskey20 = (bin20 < bin19*zone) and (if res == 21 then yes else bin20 < bin21*zone);
def iskey21 = (bin21 < bin20*zone) and (if res == 22 then yes else bin21 < bin22*zone);
def iskey22 = (bin22 < bin21*zone) and (if res == 23 then yes else bin22 < bin23*zone);
def iskey23 = (bin23 < bin22*zone) and (if res == 24 then yes else bin23 < bin24*zone);
def iskey24 = (bin24 < bin23*zone) and (if res == 25 then yes else bin24 < bin25*zone);
def iskey25 = (bin25 < bin24*zone) and (if res == 26 then yes else bin25 < bin26*zone);
def iskey26 = (bin26 < bin25*zone) and (if res == 27 then yes else bin26 < bin27*zone);
def iskey27 = (bin27 < bin26*zone) and (if res == 28 then yes else bin27 < bin28*zone);
def iskey28 = (bin28 < bin27*zone) and (if res == 29 then yes else bin28 < bin29*zone);
def iskey29 = (bin29 < bin28*zone) and (if res == 30 then yes else bin29 < bin30*zone);
def iskey30 = (bin30 < bin29*zone) and (if res == 31 then yes else bin30 < bin31*zone);
def iskey31 = (bin31 < bin30*zone) and (if res == 32 then yes else bin31 < bin32*zone);
def iskey32 = (bin32 < bin31*zone) and (if res == 33 then yes else bin32 < bin33*zone);
def iskey33 = (bin33 < bin32*zone) and (if res == 34 then yes else bin33 < bin34*zone);
def iskey34 = (bin34 < bin33*zone) and (if res == 35 then yes else bin34 < bin35*zone);
def iskey35 = (bin35 < bin34*zone) and (if res == 36 then yes else bin35 < bin36*zone);
def iskey36 = (bin36 < bin35*zone) and (if res == 37 then yes else bin36 < bin37*zone);
def iskey37 = (bin37 < bin36*zone) and (if res == 38 then yes else bin37 < bin38*zone);
def iskey38 = (bin38 < bin37*zone) and (if res == 39 then yes else bin38 < bin39*zone);
def iskey39 = (bin39 < bin38*zone) and (if res == 40 then yes else bin39 < bin40*zone);
def iskey40 = (bin40 < bin39*zone) and (if res == 41 then yes else bin40 < bin41*zone);
def iskey41 = (bin41 < bin40*zone) and (if res == 42 then yes else bin41 < bin42*zone);
def iskey42 = (bin42 < bin41*zone) and (if res == 43 then yes else bin42 < bin43*zone);
def iskey43 = (bin43 < bin42*zone) and (if res == 44 then yes else bin43 < bin44*zone);
def iskey44 = (bin44 < bin43*zone) and (if res == 45 then yes else bin44 < bin45*zone);
def iskey45 = (bin45 < bin44*zone) and (if res == 46 then yes else bin45 < bin46*zone);
def iskey46 = (bin46 < bin45*zone) and (if res == 47 then yes else bin46 < bin47*zone);
def iskey47 = (bin47 < bin46*zone) and (if res == 48 then yes else bin47 < bin48*zone);
def iskey48 = (bin48 < bin47*zone) and (if res == 49 then yes else bin48 < bin49*zone);
def iskey49 = (bin49 < bin48*zone);
def up00 = if iskey00 and lvl01 then lvl01 else na;
def up01 = if iskey01 and lvl02 then lvl02 else na;
def up02 = if iskey02 and lvl03 then lvl03 else na;
def up03 = if iskey03 and lvl04 then lvl04 else na;
def up04 = if iskey04 and lvl05 then lvl05 else na;
def up05 = if iskey05 and lvl06 then lvl06 else na;
def up06 = if iskey06 and lvl07 then lvl07 else na;
def up07 = if iskey07 and lvl08 then lvl08 else na;
def up08 = if iskey08 and lvl09 then lvl09 else na;
def up09 = if iskey09 and lvl10 then lvl10 else na;
def up10 = if iskey10 and lvl11 then lvl11 else na;
def up11 = if iskey11 and lvl12 then lvl12 else na;
def up12 = if iskey12 and lvl13 then lvl13 else na;
def up13 = if iskey13 and lvl14 then lvl14 else na;
def up14 = if iskey14 and lvl15 then lvl15 else na;
def up15 = if iskey15 and lvl16 then lvl16 else na;
def up16 = if iskey16 and lvl17 then lvl17 else na;
def up17 = if iskey17 and lvl18 then lvl18 else na;
def up18 = if iskey18 and lvl19 then lvl19 else na;
def up19 = if iskey19 and lvl20 then lvl20 else na;
def up20 = if iskey20 and lvl21 then lvl21 else na;
def up21 = if iskey21 and lvl22 then lvl22 else na;
def up22 = if iskey22 and lvl23 then lvl23 else na;
def up23 = if iskey23 and lvl24 then lvl24 else na;
def up24 = if iskey24 and lvl25 then lvl25 else na;
def up25 = if iskey25 and lvl26 then lvl26 else na;
def up26 = if iskey26 and lvl27 then lvl27 else na;
def up27 = if iskey27 and lvl28 then lvl28 else na;
def up28 = if iskey28 and lvl29 then lvl29 else na;
def up29 = if iskey29 and lvl30 then lvl30 else na;
def up30 = if iskey30 and lvl31 then lvl31 else na;
def up31 = if iskey31 and lvl32 then lvl32 else na;
def up32 = if iskey32 and lvl33 then lvl33 else na;
def up33 = if iskey33 and lvl34 then lvl34 else na;
def up34 = if iskey34 and lvl35 then lvl35 else na;
def up35 = if iskey35 and lvl36 then lvl36 else na;
def up36 = if iskey36 and lvl37 then lvl37 else na;
def up37 = if iskey37 and lvl38 then lvl38 else na;
def up38 = if iskey38 and lvl39 then lvl39 else na;
def up39 = if iskey39 and lvl40 then lvl40 else na;
def up40 = if iskey40 and lvl41 then lvl41 else na;
def up41 = if iskey41 and lvl42 then lvl42 else na;
def up42 = if iskey42 and lvl43 then lvl43 else na;
def up43 = if iskey43 and lvl44 then lvl44 else na;
def up44 = if iskey44 and lvl45 then lvl45 else na;
def up45 = if iskey45 and lvl46 then lvl46 else na;
def up46 = if iskey46 and lvl47 then lvl47 else na;
def up47 = if iskey47 and lvl48 then lvl48 else na;
def up48 = if iskey48 and lvl49 then lvl49 else na;
def up49 = if iskey49 and lvl50 then lvl50 else na;
#-----
def dn00 = if iskey00 and lvl00 then lvl00 else na;
def dn01 = if iskey01 and lvl01 then lvl01 else na;
def dn02 = if iskey02 and lvl02 then lvl02 else na;
def dn03 = if iskey03 and lvl03 then lvl03 else na;
def dn04 = if iskey04 and lvl04 then lvl04 else na;
def dn05 = if iskey05 and lvl05 then lvl05 else na;
def dn06 = if iskey06 and lvl06 then lvl06 else na;
def dn07 = if iskey07 and lvl07 then lvl07 else na;
def dn08 = if iskey08 and lvl08 then lvl08 else na;
def dn09 = if iskey09 and lvl09 then lvl09 else na;
def dn10 = if iskey10 and lvl10 then lvl10 else na;
def dn11 = if iskey11 and lvl11 then lvl11 else na;
def dn12 = if iskey12 and lvl12 then lvl12 else na;
def dn13 = if iskey13 and lvl13 then lvl13 else na;
def dn14 = if iskey14 and lvl14 then lvl14 else na;
def dn15 = if iskey15 and lvl15 then lvl15 else na;
def dn16 = if iskey16 and lvl16 then lvl16 else na;
def dn17 = if iskey17 and lvl17 then lvl17 else na;
def dn18 = if iskey18 and lvl18 then lvl18 else na;
def dn19 = if iskey19 and lvl19 then lvl19 else na;
def dn20 = if iskey20 and lvl20 then lvl20 else na;
def dn21 = if iskey21 and lvl21 then lvl21 else na;
def dn22 = if iskey22 and lvl22 then lvl22 else na;
def dn23 = if iskey23 and lvl23 then lvl23 else na;
def dn24 = if iskey24 and lvl24 then lvl24 else na;
def dn25 = if iskey25 and lvl25 then lvl25 else na;
def dn26 = if iskey26 and lvl26 then lvl26 else na;
def dn27 = if iskey27 and lvl27 then lvl27 else na;
def dn28 = if iskey28 and lvl28 then lvl28 else na;
def dn29 = if iskey29 and lvl29 then lvl29 else na;
def dn30 = if iskey30 and lvl30 then lvl30 else na;
def dn31 = if iskey31 and lvl31 then lvl31 else na;
def dn32 = if iskey32 and lvl32 then lvl32 else na;
def dn33 = if iskey33 and lvl33 then lvl33 else na;
def dn34 = if iskey34 and lvl34 then lvl34 else na;
def dn35 = if iskey35 and lvl35 then lvl35 else na;
def dn36 = if iskey36 and lvl36 then lvl36 else na;
def dn37 = if iskey37 and lvl37 then lvl37 else na;
def dn38 = if iskey38 and lvl38 then lvl38 else na;
def dn39 = if iskey39 and lvl39 then lvl39 else na;
def dn40 = if iskey40 and lvl40 then lvl40 else na;
def dn41 = if iskey41 and lvl41 then lvl41 else na;
def dn42 = if iskey42 and lvl42 then lvl42 else na;
def dn43 = if iskey43 and lvl43 then lvl43 else na;
def dn44 = if iskey44 and lvl44 then lvl44 else na;
def dn45 = if iskey45 and lvl45 then lvl45 else na;
def dn46 = if iskey46 and lvl46 then lvl46 else na;
def dn47 = if iskey47 and lvl47 then lvl47 else na;
def dn48 = if iskey48 and lvl48 then lvl48 else na;
def dn49 = if iskey49 and lvl49 then lvl49 else na;
def cond00 = if close > up00 then 1 else
if close < dn00 then 0 else cond00[1];
def cond01 = if close > up01 then 1 else
if close < dn01 then 0 else cond01[1];
def cond02 = if close > up02 then 1 else
if close < dn02 then 0 else cond02[1];
def cond03 = if close > up03 then 1 else
if close < dn03 then 0 else cond03[1];
def cond04 = if close > up04 then 1 else
if close < dn04 then 0 else cond04[1];
def cond05 = if close > up05 then 1 else
if close < dn05 then 0 else cond05[1];
def cond06 = if close > up06 then 1 else
if close < dn06 then 0 else cond06[1];
def cond07 = if close > up07 then 1 else
if close < dn07 then 0 else cond07[1];
def cond08 = if close > up08 then 1 else
if close < dn08 then 0 else cond08[1];
def cond09 = if close > up09 then 1 else
if close < dn09 then 0 else cond09[1];
def cond10 = if close > up10 then 1 else
if close < dn10 then 0 else cond10[1];
def cond11 = if close > up11 then 1 else
if close < dn11 then 0 else cond11[1];
def cond12 = if close > up12 then 1 else
if close < dn12 then 0 else cond12[1];
def cond13 = if close > up13 then 1 else
if close < dn13 then 0 else cond13[1];
def cond14 = if close > up14 then 1 else
if close < dn14 then 0 else cond14[1];
def cond15 = if close > up15 then 1 else
if close < dn15 then 0 else cond15[1];
def cond16 = if close > up16 then 1 else
if close < dn16 then 0 else cond16[1];
def cond17 = if close > up17 then 1 else
if close < dn17 then 0 else cond17[1];
def cond18 = if close > up18 then 1 else
if close < dn18 then 0 else cond18[1];
def cond19 = if close > up19 then 1 else
if close < dn19 then 0 else cond19[1];
def cond20 = if close > up20 then 1 else
if close < dn20 then 0 else cond20[1];
def cond21 = if close > up21 then 1 else
if close < dn21 then 0 else cond21[1];
def cond22 = if close > up22 then 1 else
if close < dn22 then 0 else cond22[1];
def cond23 = if close > up23 then 1 else
if close < dn23 then 0 else cond23[1];
def cond24 = if close > up24 then 1 else
if close < dn24 then 0 else cond24[1];
def cond25 = if close > up25 then 1 else
if close < dn25 then 0 else cond25[1];
def cond26 = if close > up26 then 1 else
if close < dn26 then 0 else cond26[1];
def cond27 = if close > up27 then 1 else
if close < dn27 then 0 else cond27[1];
def cond28 = if close > up28 then 1 else
if close < dn28 then 0 else cond28[1];
def cond29 = if close > up29 then 1 else
if close < dn29 then 0 else cond29[1];
def cond30 = if close > up30 then 1 else
if close < dn30 then 0 else cond30[1];
def cond31 = if close > up31 then 1 else
if close < dn31 then 0 else cond31[1];
def cond32 = if close > up32 then 1 else
if close < dn32 then 0 else cond32[1];
def cond33 = if close > up33 then 1 else
if close < dn33 then 0 else cond33[1];
def cond34 = if close > up34 then 1 else
if close < dn34 then 0 else cond34[1];
def cond35 = if close > up35 then 1 else
if close < dn35 then 0 else cond35[1];
def cond36 = if close > up36 then 1 else
if close < dn36 then 0 else cond36[1];
def cond37 = if close > up37 then 1 else
if close < dn37 then 0 else cond37[1];
def cond38 = if close > up38 then 1 else
if close < dn38 then 0 else cond38[1];
def cond39 = if close > up39 then 1 else
if close < dn39 then 0 else cond39[1];
def cond40 = if close > up40 then 1 else
if close < dn40 then 0 else cond40[1];
def cond41 = if close > up41 then 1 else
if close < dn41 then 0 else cond41[1];
def cond42 = if close > up42 then 1 else
if close < dn42 then 0 else cond42[1];
def cond43 = if close > up43 then 1 else
if close < dn43 then 0 else cond43[1];
def cond44 = if close > up44 then 1 else
if close < dn44 then 0 else cond44[1];
def cond45 = if close > up45 then 1 else
if close < dn45 then 0 else cond45[1];
def cond46 = if close > up46 then 1 else
if close < dn46 then 0 else cond46[1];
def cond47 = if close > up47 then 1 else
if close < dn47 then 0 else cond47[1];
def cond48 = if close > up48 then 1 else
if close < dn48 then 0 else cond48[1];
def cond49 = if close > up49 then 1 else
if close < dn49 then 0 else cond49[1];
def con00 = if sartCond and !last then cond00 else na;
def con01 = if sartCond and !last then cond01 else na;
def con02 = if sartCond and !last then cond02 else na;
def con03 = if sartCond and !last then cond03 else na;
def con04 = if sartCond and !last then cond04 else na;
def con05 = if sartCond and !last then cond05 else na;
def con06 = if sartCond and !last then cond06 else na;
def con07 = if sartCond and !last then cond07 else na;
def con08 = if sartCond and !last then cond08 else na;
def con09 = if sartCond and !last then cond09 else na;
def con10 = if sartCond and !last then cond10 else na;
def con11 = if sartCond and !last then cond11 else na;
def con12 = if sartCond and !last then cond12 else na;
def con13 = if sartCond and !last then cond13 else na;
def con14 = if sartCond and !last then cond14 else na;
def con15 = if sartCond and !last then cond15 else na;
def con16 = if sartCond and !last then cond16 else na;
def con17 = if sartCond and !last then cond17 else na;
def con18 = if sartCond and !last then cond18 else na;
def con19 = if sartCond and !last then cond19 else na;
def con20 = if sartCond and !last then cond20 else na;
def con21 = if sartCond and !last then cond21 else na;
def con22 = if sartCond and !last then cond22 else na;
def con23 = if sartCond and !last then cond23 else na;
def con24 = if sartCond and !last then cond24 else na;
def con25 = if sartCond and !last then cond25 else na;
def con26 = if sartCond and !last then cond26 else na;
def con27 = if sartCond and !last then cond27 else na;
def con28 = if sartCond and !last then cond28 else na;
def con29 = if sartCond and !last then cond29 else na;
def con30 = if sartCond and !last then cond30 else na;
def con31 = if sartCond and !last then cond31 else na;
def con32 = if sartCond and !last then cond32 else na;
def con33 = if sartCond and !last then cond33 else na;
def con34 = if sartCond and !last then cond34 else na;
def con35 = if sartCond and !last then cond35 else na;
def con36 = if sartCond and !last then cond36 else na;
def con37 = if sartCond and !last then cond37 else na;
def con38 = if sartCond and !last then cond38 else na;
def con39 = if sartCond and !last then cond39 else na;
def con40 = if sartCond and !last then cond40 else na;
def con41 = if sartCond and !last then cond41 else na;
def con42 = if sartCond and !last then cond42 else na;
def con43 = if sartCond and !last then cond43 else na;
def con44 = if sartCond and !last then cond44 else na;
def con45 = if sartCond and !last then cond45 else na;
def con46 = if sartCond and !last then cond46 else na;
def con47 = if sartCond and !last then cond47 else na;
def con48 = if sartCond and !last then cond48 else na;
def con49 = if sartCond and !last then cond49 else na;
def level00 = if !isNaN(con00) then if con00 then up00 else dn00 else na;
def level01 = if !isNaN(con01) then if con01 then up01 else dn01 else na;
def level02 = if !isNaN(con02) then if con02 then up02 else dn02 else na;
def level03 = if !isNaN(con03) then if con03 then up03 else dn03 else na;
def level04 = if !isNaN(con04) then if con04 then up04 else dn04 else na;
def level05 = if !isNaN(con05) then if con05 then up05 else dn05 else na;
def level06 = if !isNaN(con06) then if con06 then up06 else dn06 else na;
def level07 = if !isNaN(con07) then if con07 then up07 else dn07 else na;
def level08 = if !isNaN(con08) then if con08 then up08 else dn08 else na;
def level09 = if !isNaN(con09) then if con09 then up09 else dn09 else na;
def level10 = if !isNaN(con10) then if con10 then up10 else dn10 else na;
def level11 = if !isNaN(con11) then if con11 then up11 else dn11 else na;
def level12 = if !isNaN(con12) then if con12 then up12 else dn12 else na;
def level13 = if !isNaN(con13) then if con13 then up13 else dn13 else na;
def level14 = if !isNaN(con14) then if con14 then up14 else dn14 else na;
def level15 = if !isNaN(con15) then if con15 then up15 else dn15 else na;
def level16 = if !isNaN(con16) then if con16 then up16 else dn16 else na;
def level17 = if !isNaN(con17) then if con17 then up17 else dn17 else na;
def level18 = if !isNaN(con18) then if con18 then up18 else dn18 else na;
def level19 = if !isNaN(con19) then if con19 then up19 else dn19 else na;
def level20 = if !isNaN(con20) then if con20 then up20 else dn20 else na;
def level21 = if !isNaN(con21) then if con21 then up21 else dn21 else na;
def level22 = if !isNaN(con22) then if con22 then up22 else dn22 else na;
def level23 = if !isNaN(con23) then if con23 then up23 else dn23 else na;
def level24 = if !isNaN(con24) then if con24 then up24 else dn24 else na;
def level25 = if !isNaN(con25) then if con25 then up25 else dn25 else na;
def level26 = if !isNaN(con26) then if con26 then up26 else dn26 else na;
def level27 = if !isNaN(con27) then if con27 then up27 else dn27 else na;
def level28 = if !isNaN(con28) then if con28 then up28 else dn28 else na;
def level29 = if !isNaN(con29) then if con29 then up29 else dn29 else na;
def level30 = if !isNaN(con30) then if con30 then up30 else dn30 else na;
def level31 = if !isNaN(con31) then if con31 then up31 else dn31 else na;
def level32 = if !isNaN(con32) then if con32 then up32 else dn32 else na;
def level33 = if !isNaN(con33) then if con33 then up33 else dn33 else na;
def level34 = if !isNaN(con34) then if con34 then up34 else dn34 else na;
def level35 = if !isNaN(con35) then if con35 then up35 else dn35 else na;
def level36 = if !isNaN(con36) then if con36 then up36 else dn36 else na;
def level37 = if !isNaN(con37) then if con37 then up37 else dn37 else na;
def level38 = if !isNaN(con38) then if con38 then up38 else dn38 else na;
def level39 = if !isNaN(con39) then if con39 then up39 else dn39 else na;
def level40 = if !isNaN(con40) then if con40 then up40 else dn40 else na;
def level41 = if !isNaN(con41) then if con41 then up41 else dn41 else na;
def level42 = if !isNaN(con42) then if con42 then up42 else dn42 else na;
def level43 = if !isNaN(con43) then if con43 then up43 else dn43 else na;
def level44 = if !isNaN(con44) then if con44 then up44 else dn44 else na;
def level45 = if !isNaN(con45) then if con45 then up45 else dn45 else na;
def level46 = if !isNaN(con46) then if con46 then up46 else dn46 else na;
def level47 = if !isNaN(con47) then if con47 then up47 else dn47 else na;
def level48 = if !isNaN(con48) then if con48 then up48 else dn48 else na;
def level49 = if !isNaN(con49) then if con49 then up49 else dn49 else na;
AddCloud(level00, if con00 then dn00 else up00, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level01, if con01 then dn01 else up01, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level02, if con02 then dn02 else up02, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level03, if con03 then dn03 else up03, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level04, if con04 then dn04 else up04, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level05, if con05 then dn05 else up05, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level06, if con06 then dn06 else up06, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level07, if con07 then dn07 else up07, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level08, if con08 then dn08 else up08, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level09, if con09 then dn09 else up09, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level10, if con10 then dn10 else up10, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level11, if con11 then dn11 else up11, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level12, if con12 then dn12 else up12, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level13, if con13 then dn13 else up13, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level14, if con14 then dn14 else up14, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level15, if con15 then dn15 else up15, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level16, if con16 then dn16 else up16, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level17, if con17 then dn17 else up17, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level18, if con18 then dn18 else up18, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level19, if con19 then dn19 else up19, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level20, if con20 then dn20 else up20, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level21, if con21 then dn21 else up21, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level22, if con22 then dn22 else up22, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level23, if con23 then dn23 else up23, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level24, if con24 then dn24 else up24, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level25, if con25 then dn25 else up25, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level26, if con26 then dn26 else up26, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level27, if con27 then dn27 else up27, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level28, if con28 then dn28 else up28, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level29, if con29 then dn29 else up29, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level30, if con30 then dn30 else up30, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level31, if con31 then dn31 else up31, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level32, if con32 then dn32 else up32, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level33, if con33 then dn33 else up33, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level34, if con34 then dn34 else up34, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level35, if con35 then dn35 else up35, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level36, if con36 then dn36 else up36, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level37, if con37 then dn37 else up37, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level38, if con38 then dn38 else up38, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level39, if con39 then dn39 else up39, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level40, if con40 then dn40 else up40, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level41, if con41 then dn41 else up41, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level42, if con42 then dn42 else up42, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level43, if con43 then dn43 else up43, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level44, if con44 then dn44 else up44, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level45, if con45 then dn45 else up45, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level46, if con46 then dn46 else up46, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level47, if con47 then dn47 else up47, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level48, if con48 then dn48 else up48, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(level49, if con49 then dn49 else up49, Color.DARK_GREEN, Color.DARK_RED, yes);
#AddChartBubble(x, low, x, Color.RED, no);
def ph2 = if high == highs then bar else ph2[1];
def pl2 = if low == lows then bar else pl2[1];
plot hhPoint = if bar == highestAll(ph2) then high else na;
plot llPoint = if bar == highestAll(pl2) then low else na;
hhPoint.SetLineWeight(2);
llPoint.SetLineWeight(2);
hhPoint.SetPaintingStrategy(PaintingStrategy.POINTS);
llPoint.SetPaintingStrategy(PaintingStrategy.POINTS);
hhPoint.SetDefaultColor(Color.WHITE);
llPoint.SetDefaultColor(Color.WHITE);
def totVol = fold j = 0 to x with q do
q + GetValue(volume, j);
def m1 = Max(bin00,Max(bin01,Max(bin02,Max(bin03,Max(bin04,Max(bin05,Max(bin06,Max(bin07,Max(bin08, Max(bin09, bin10))))))))));
def m2 = Max(bin11,Max(bin12,Max(bin13,Max(bin14,Max(bin15,Max(bin16,Max(bin17,Max(bin18,Max(bin19, bin20)))))))));
def m3 = Max(bin21,Max(bin22,Max(bin23,Max(bin24,Max(bin25,Max(bin26,Max(bin27,Max(bin28,Max(bin29, bin30)))))))));
def m4 = Max(bin31,Max(bin32,Max(bin33,Max(bin34,Max(bin35,Max(bin36,Max(bin37,Max(bin38,Max(bin39, bin40)))))))));
def m5 = Max(bin41,Max(bin42,Max(bin43,Max(bin44,Max(bin45,Max(bin46,Max(bin47,Max(bin48, bin49))))))));
def maxBin = Max(m1, Max(m2, Max(m3, Max(m4, m5))));
def start = if !isNaN(hh) then start[1] + 1 else 0;
def center = (bar == highestAll(bar- floor(highestAll(start)/2)));
def loc;
Switch (labelOptions) {
Case "Left" :
loc = !isNaN(hh) and isNaN(hh[1]);
Case "Right" :
loc = isNaN(hh) and !isNaN(hh[1]);
Case "Don't Show" :
loc = no;
Default :
loc = center;
}
AddChartBubble(loc, (up00 + dn00) / 2, AsPercent(1 - bin00 / maxBin), Color.WHITE);
AddChartBubble(loc, (up01 + dn01) / 2, AsPercent(1 - bin01 / maxBin), Color.WHITE);
AddChartBubble(loc, (up02 + dn02) / 2, AsPercent(1 - bin02 / maxBin), Color.WHITE);
AddChartBubble(loc, (up03 + dn03) / 2, AsPercent(1 - bin03 / maxBin), Color.WHITE);
AddChartBubble(loc, (up04 + dn04) / 2, AsPercent(1 - bin04 / maxBin), Color.WHITE);
AddChartBubble(loc, (up05 + dn05) / 2, AsPercent(1 - bin05 / maxBin), Color.WHITE);
AddChartBubble(loc, (up06 + dn06) / 2, AsPercent(1 - bin06 / maxBin), Color.WHITE);
AddChartBubble(loc, (up07 + dn07) / 2, AsPercent(1 - bin07 / maxBin), Color.WHITE);
AddChartBubble(loc, (up08 + dn08) / 2, AsPercent(1 - bin08 / maxBin), Color.WHITE);
AddChartBubble(loc, (up09 + dn09) / 2, AsPercent(1 - bin09 / maxBin), Color.WHITE);
AddChartBubble(loc, (up10 + dn10) / 2, AsPercent(1 - bin10 / maxBin), Color.WHITE);
AddChartBubble(loc, (up11 + dn11) / 2, AsPercent(1 - bin11 / maxBin), Color.WHITE);
AddChartBubble(loc, (up12 + dn12) / 2, AsPercent(1 - bin12 / maxBin), Color.WHITE);
AddChartBubble(loc, (up13 + dn13) / 2, AsPercent(1 - bin13 / maxBin), Color.WHITE);
AddChartBubble(loc, (up14 + dn14) / 2, AsPercent(1 - bin14 / maxBin), Color.WHITE);
AddChartBubble(loc, (up15 + dn15) / 2, AsPercent(1 - bin15 / maxBin), Color.WHITE);
AddChartBubble(loc, (up16 + dn16) / 2, AsPercent(1 - bin16 / maxBin), Color.WHITE);
AddChartBubble(loc, (up17 + dn17) / 2, AsPercent(1 - bin17 / maxBin), Color.WHITE);
AddChartBubble(loc, (up18 + dn18) / 2, AsPercent(1 - bin18 / maxBin), Color.WHITE);
AddChartBubble(loc, (up19 + dn19) / 2, AsPercent(1 - bin19 / maxBin), Color.WHITE);
AddChartBubble(loc, (up20 + dn20) / 2, AsPercent(1 - bin20 / maxBin), Color.WHITE);
AddChartBubble(loc, (up21 + dn21) / 2, AsPercent(1 - bin21 / maxBin), Color.WHITE);
AddChartBubble(loc, (up22 + dn22) / 2, AsPercent(1 - bin22 / maxBin), Color.WHITE);
AddChartBubble(loc, (up23 + dn23) / 2, AsPercent(1 - bin23 / maxBin), Color.WHITE);
AddChartBubble(loc, (up24 + dn24) / 2, AsPercent(1 - bin24 / maxBin), Color.WHITE);
AddChartBubble(loc, (up25 + dn25) / 2, AsPercent(1 - bin25 / maxBin), Color.WHITE);
AddChartBubble(loc, (up26 + dn26) / 2, AsPercent(1 - bin26 / maxBin), Color.WHITE);
AddChartBubble(loc, (up27 + dn27) / 2, AsPercent(1 - bin27 / maxBin), Color.WHITE);
AddChartBubble(loc, (up28 + dn28) / 2, AsPercent(1 - bin28 / maxBin), Color.WHITE);
AddChartBubble(loc, (up29 + dn29) / 2, AsPercent(1 - bin29 / maxBin), Color.WHITE);
AddChartBubble(loc, (up30 + dn30) / 2, AsPercent(1 - bin30 / maxBin), Color.WHITE);
AddChartBubble(loc, (up31 + dn31) / 2, AsPercent(1 - bin31 / maxBin), Color.WHITE);
AddChartBubble(loc, (up32 + dn32) / 2, AsPercent(1 - bin32 / maxBin), Color.WHITE);
AddChartBubble(loc, (up33 + dn33) / 2, AsPercent(1 - bin33 / maxBin), Color.WHITE);
AddChartBubble(loc, (up34 + dn34) / 2, AsPercent(1 - bin34 / maxBin), Color.WHITE);
AddChartBubble(loc, (up35 + dn35) / 2, AsPercent(1 - bin35 / maxBin), Color.WHITE);
AddChartBubble(loc, (up36 + dn36) / 2, AsPercent(1 - bin36 / maxBin), Color.WHITE);
AddChartBubble(loc, (up37 + dn37) / 2, AsPercent(1 - bin37 / maxBin), Color.WHITE);
AddChartBubble(loc, (up38 + dn38) / 2, AsPercent(1 - bin38 / maxBin), Color.WHITE);
AddChartBubble(loc, (up39 + dn39) / 2, AsPercent(1 - bin39 / maxBin), Color.WHITE);
AddChartBubble(loc, (up40 + dn40) / 2, AsPercent(1 - bin40 / maxBin), Color.WHITE);
AddChartBubble(loc, (up41 + dn41) / 2, AsPercent(1 - bin41 / maxBin), Color.WHITE);
AddChartBubble(loc, (up42 + dn42) / 2, AsPercent(1 - bin42 / maxBin), Color.WHITE);
AddChartBubble(loc, (up43 + dn43) / 2, AsPercent(1 - bin43 / maxBin), Color.WHITE);
AddChartBubble(loc, (up44 + dn44) / 2, AsPercent(1 - bin44 / maxBin), Color.WHITE);
AddChartBubble(loc, (up45 + dn45) / 2, AsPercent(1 - bin45 / maxBin), Color.WHITE);
AddChartBubble(loc, (up46 + dn46) / 2, AsPercent(1 - bin46 / maxBin), Color.WHITE);
AddChartBubble(loc, (up47 + dn47) / 2, AsPercent(1 - bin47 / maxBin), Color.WHITE);
AddChartBubble(loc, (up48 + dn48) / 2, AsPercent(1 - bin48 / maxBin), Color.WHITE);
AddChartBubble(loc, (up49 + dn49) / 2, AsPercent(1 - bin49 / maxBin), Color.WHITE);
#-- END of CODE