Alternate normalization study, not complex
EDIT ------------
the new study assumes there are less than 1000 bars on the chart. if it has more, then the 2 instances of this,
def barsBack = 1000;
will have to be adjusted. (each in a sub script)
I was looking for a normalization script to use in a project and was looking at various studies.
the studies I found, used highestall() and lowestall() on every bar, and were complex.
I recently found a post that listed a study by mobius, for a different way to make a priceline. thank you @Pensar for posting it.
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
I ended up modifying it to find a lowest low. post #9
I went back to the normalization studies and combined it with the above and came up with the second study below, what I am calling the alternate method.
it does not use highestall() or lowestall().
it is not complex.
it finds the highest and lowest numbers only on barnumber 1, then reuses them for the remaining bars.
the first study is what I am calling a standard normalization study.
the second study is my modified version.
=========================================================
example of standard normalize code
https://usethinkscript.com/threads/how-to-compare-stock-charts-in-thinkorswim.1249/page-2#post-53385
post 35
it scales a set of numbers (prices) to be within a new range of numbers.
it uses highestall() and lowestall(), on every bar
it is complex
=========================================================
alternate code
it scales a set of numbers (prices) to be within a new range of numbers.
it uses a large negative offset, to create a variable that has the highest high value, set in every bar. similar to a priceline study. same is done for lowest low.
it does not use highestall() or lowestall()
it is not complex
=========================================================
compare the standard method and this alternative method. the lines are the same.
hal_norm
EDIT ------------
the new study assumes there are less than 1000 bars on the chart. if it has more, then the 2 instances of this,
def barsBack = 1000;
will have to be adjusted. (each in a sub script)
I was looking for a normalization script to use in a project and was looking at various studies.
the studies I found, used highestall() and lowestall() on every bar, and were complex.
I recently found a post that listed a study by mobius, for a different way to make a priceline. thank you @Pensar for posting it.
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
I ended up modifying it to find a lowest low. post #9
I went back to the normalization studies and combined it with the above and came up with the second study below, what I am calling the alternate method.
it does not use highestall() or lowestall().
it is not complex.
it finds the highest and lowest numbers only on barnumber 1, then reuses them for the remaining bars.
the first study is what I am calling a standard normalization study.
the second study is my modified version.
=========================================================
example of standard normalize code
https://usethinkscript.com/threads/how-to-compare-stock-charts-in-thinkorswim.1249/page-2#post-53385
post 35
it scales a set of numbers (prices) to be within a new range of numbers.
it uses highestall() and lowestall(), on every bar
it is complex
Ruby:
# normalize_std_00
#https://usethinkscript.com/threads/how-to-compare-stock-charts-in-thinkorswim.1249/page-2#post-53385
#post 35
declare lower;
script normalizePlot {
input data = close;
# input newRngMin = -1;
# input newRngMax = 1;
input newRngMin = 0;
input newRngMax = 100;
def HHData = HighestAll( data );
def LLData = LowestAll( data );
plot nr = ((( newRngMax - newRngMin ) * ( data - LLData )) / ( HHData - LLData )) + newRngMin;
}
plot z = normalizePlot();
z.SetStyle(Curve.MEDIUM_DASH);
z.SetDefaultColor(Color.yellow);
z.setlineweight(1);
z.hidebubble();
#
=========================================================
alternate code
it scales a set of numbers (prices) to be within a new range of numbers.
it uses a large negative offset, to create a variable that has the highest high value, set in every bar. similar to a priceline study. same is done for lowest low.
it does not use highestall() or lowestall()
it is not complex
Ruby:
# normalize_alt_00_cln
#-------------------------
# halcyonguy
# 21-11-28
# rescale a data set
# create normalize formulas without highestall(), lowestall()
#-------------------------
# ref
# https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
# Line At Price Mobius
#input barsBack = 1000;
#def c = if !IsNaN(close) and IsNaN(close[-1])
# then close
# else c[1];
#plot line = if isNaN(close[-barsBack])
# then c[-barsBack]
# else Double.NaN;
# ------------------------------------------------------
# if bar 1 then
# .. find the highest and lowest price levels on the chart.
# .. calculate a scaled price.
# else (if not the first bar)
# .. use the previous highest and lowest price levels to calculate a scaled price.
declare lower;
#-----------------------------------------
# find highest high
#-----------------------------------------
script hi_level {
def barsBack = 1000;
def high1 = if barnumber() == 1 then high else if high > high1[1] then high else high1[1];
def high2 = if !IsNaN(close) and IsNaN(close[-1]) then high1 else high2[1];
def highline = if isNaN(close[-barsBack]) then high2[-barsBack] else Double.NaN;
plot zh = highline;
}
#-----------------------------------------
# find lowest low
#-----------------------------------------
script lo_level {
def barsBack = 1000;
def low1 = if barnumber() == 1 then low else if low < low1[1] then low else low1[1];
def low2 = if !IsNaN(close) and IsNaN(close[-1]) then low1 else low2[1];
def lowline = if isNaN(close[-barsBack]) then low2[-barsBack] else Double.NaN;
plot zl = lowline;
}
#-----------------------------------------
# normalize
#-----------------------------------------
# start with a copy of code from post #1 https://usethinkscript.com/threads/how-to-plot-a-study-as-a-normalized-index-that-has-0-100-values-e-g-like-moneyflowindex.4289/
# plot a study as a normalized index that has 0-100% values lmk99
script normalizePlot {
input hi = 0;
input lo = 0;
input data = close;
input RngMin = 0;
input RngMax = 100;
def en = if (hi == 0 or lo == 0 ) then 0 else 1;
# if en , then calc stuff
plot nr = if !en then double.nan else ((( RngMax - RngMin ) * ( data - lo )) / ( hi - lo )) + RngMin;
}
#-----------------------------------------
# main section
#-----------------------------------------
def bn = barnumber();
def na = double.nan;
# find the highest and lowest levels of original data
def hi;
def lo;
def nz;
if bn == 1 then {
# call sub scripts to find highest and lowest prices on chart
hi = hi_level();
lo = lo_level();
# rescale the close
# normalizePlot( data hi, data lo, price (default is close), new Rng Min (default 0), new Rng Max (default 100) )
nz = normalizePlot( hi, lo, close);
} else {
hi = hi[1];
lo = lo[1];
nz = normalizePlot( hi, lo, close);
}
#-----------------------
# plot normalized line
plot nz2 = nz;
# plot the highest and lowest levels of original data
input plot_highest_lowest_lines = no;
plot zhi = if plot_highest_lowest_lines then hi else na;
plot zlo = if plot_highest_lowest_lines then lo else na;
addlabel(1, "Original data, Highest: " + hi + " , Lowest: " + lo, color.yellow);
#
=========================================================
compare the standard method and this alternative method. the lines are the same.
hal_norm
Last edited: