TimKutch

TTM_Squeeze

This is my version of the Squeeze indicator from Trade the Markets ( TTM             ) and John Carter.
Remove from Favorite Scripts Add to Favorite Scripts
study(title="TTM_Squeeze_LinReg", shorttitle="TTM_Squeeze_LinReg", overlay=false)

source = close
ROC_length = input(title="RoC Length", defval=14, minval=1)
length = input(title="Length", type=integer, defval=22)
offset = input(title="Offset", type=integer, defval=0)

rate = 100 * mom(source, ROC_length)/source[ROC_length]
lsma = linreg(rate, length, offset)

isOne()   => lsma>0 and lsma>lsma[1]
isTwo()   => lsma>0 and lsma<lsma[1]
isThree() => lsma<0 and lsma<lsma[1]
isFour()  => lsma<0 and lsma>lsma[1]

plot(lsma, linewidth=4, style=histogram, color=isOne() ? aqua : isTwo() ? blue : isThree() ? red : isFour() ? yellow : gray, title="ROC")

K_source = close
Keltner_useTrueRange = input(title="True Range", defval=true)
Keltner_length = input(title="Keltner Length", defval=20, minval=1)
Keltner_multiple = input(title="Keltner Multiple", defval=1.5)
K_ma = ema(K_source, Keltner_length)
K_range = Keltner_useTrueRange ? tr : high - low
K_rangema = ema(K_range, Keltner_length)
K_upper = K_ma + K_rangema * Keltner_multiple
K_lower = K_ma - K_rangema * Keltner_multiple
K_width = K_upper - K_lower

B_source = close
Bollinger_length = input(title="Bollinger Length", defval=20, minval=1)
Bollinger_multiple = input(title="Bollinger Multiple", defval=2.0, minval=0.001, maxval=50)
B_basis = sma(B_source, Bollinger_length)
B_dev = Bollinger_multiple * stdev(B_source, Bollinger_length)
B_upper = B_basis + B_dev
B_lower = B_basis - B_dev
B_width= B_upper - B_lower

dot_red = iff(B_width < K_width, 0, na)
dot_green = iff(B_width > K_width, 0, na)

plot(dot_red, style=circles, color=red, linewidth=3)
plot(dot_green, style=circles, color=lime, linewidth=3)
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out