Hello im trying to find the highest and lowest value of ttm squeeze range. i tried using ta.highiest but kept getting study error. i wanted to try save it in a list, then use .sort to order it.
//@version=5
strategy(title="ttm Keltner Channels x Bollingerbands ", shorttitle="ttm", overlay=true)
//-----------------------------------//
// kc settings //
//----------------------------------//
import TradingView/ta/7
length = input.int(20, minval=1)
mult = input(2.0, "Multiplier")
src = input(close, title="Source")
exp = input(true, "Use Exponential MA", display = display.data_window)
BandsStyle = input.string("Average True Range", options = ["Average True Range", "True Range", "Range"], title="Bands Style", display = display.data_window)
atrlength = input(10, "ATR Length", display = display.data_window)
esma(source, length)=>
s = ta.sma(source, length)
e = ta.ema(source, length)
exp ? e : s
ma = esma(src, length)
rangema = BandsStyle == "True Range" ? ta.tr(true) : BandsStyle == "Average True Range" ? ta.atr(atrlength) : ta.rma(high - low, length)
upper = ma + rangema * mult
lower = ma - rangema * mult
u = plot(upper, color=#2962FF, title="Upper")
plot(ma, color=#2962FF, title="Basis")
l = plot(lower, color=#2962FF, title="Lower")
fill(u, l, color=color.rgb(33, 150, 243, 95), title="Background")
///////////////////////////////////////////////////////////////////////////
//-----------------------------------//
// bb settings //
//----------------------------------//
lengthbb = input.int(20, minval=1)
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
srcbb = input(close, title="Source")
multbb = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
ma(sourcebb, lengthbb, _type) =>
switch _type
"SMA" => ta.sma(sourcebb, lengthbb)
"EMA" => ta.ema(sourcebb, lengthbb)
"SMMA (RMA)" => ta.rma(sourcebb, lengthbb)
"WMA" => ta.wma(sourcebb, lengthbb)
"VWMA" => ta.vwma(sourcebb, lengthbb)
basis = ma(src, lengthbb, maType)
dev = mult * ta.stdev(srcbb, lengthbb)
upperbb = basis + dev
lowerbb = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500, display = display.data_window)
plot(basis, "Basis", color=#2962FF, offset = offset)
p1 = plot(upperbb, "Upper", color=#F23645, offset = offset)
p2 = plot(lowerbb, "Lower", color=#089981, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
//////////////////////////////////////////////////////////////////////////////////////
//-----------------------------------//
// ttm settings //
//----------------------------------//
ttmsqueeze = upperbb < upper and lowerbb > lower // ttm squeeze range
notttmsqueeze = not ttmsqueeze // no squeeze happening
ttmopen = (ttmsqueeze and not ttmsqueeze[1] )// open of ttm
ttmclose = (notttmsqueeze and not notttmsqueeze[1]) // close of ttm
plotshape(ttmsqueeze, color = color.blue)
plotshape(ttmopen , color= color.green)
plotshape(ttmclose , color= color.red)
///////////////////////////////////////////////////////////////////////////////////////
// Find the hightest & lowest price of range
var float ttmopen_price = na // set to 0 to be updated
if (ttmopen) // when ttm first appears
ttmopen_price := open // holds the price of ttmopen
var float ttmclose_price = na // set to 0 to be updated
if (ttmclose) // when ttm appears last
ttmclose_price := close // holds the price of ttclose
var float currentsqueeze =na // loop that thorugh ttmsqueeze
if (notttmsqueeze == not true) //when notttmsqueeze isnt equal to not true
currentsqueeze := close // update currentsqueeze to current close
// find highest number in the range in of ttmopen_price and ttmclose_price
// get each vaule in ttmsqueeze range
// put in range
//sort each vaule high to low
//ideas
// for loops // loop through save list and use sort to order high to low
//araay.size // get elements
//array.sort // set ascending order
//array,range // get range
//ta.barsince // use to get length of bars
idea to use for loops to loop through currentsqueeze and save list and use sort to order high to low. I also trying to use ta.barsince to get use as the length for ta.highiest
2