CTTV TTM by NM

Profit_Through_Patience · study · 73 行 · 点赞 1,041 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=3
study(shorttitle="CTTV TTM", title="CTTV TTM by NM", overlay=false)
 
// ######################################################################################
// This script was created because the original TTM Squeeze script
// did trigger when only one of the Bollinger Bands was 
// in the Keltner channel. It now gives the option to use it as was
// or to force it to only give a signal when both BB are in the Keltner channels
// 
// Furthermore an alert was added to fire when we are squeezing
// no matter which option your choose (original or strict)
// To create an alert, click on the alerts in the right column on your screen
// then click on the +button to add an alert. 
// Select from the conditions "CTTV Squeeze" and "Once per bar close"
// Keep in mind that you set this alert for one instrument and one particular time frame
// If you would have any questions, contact me : 
// TradingView : @Nico.Muselle
// Twitch : @MrUnicornLlama
// ######################################################################################
 
strict = input(true, title="Enabled (original) or Disabled (strict)")
length = input(20, minval=1, title="BB Length")
/// ### ORIGINAL TTM ### ///
 
bband(length, mult) =>
	sma(close, length) + mult * stdev(close, length)
keltner(length, mult) =>
	ema(close, length) + mult * ema(tr, length)
	
diff = bband(length, 2) - keltner(length, 1)
 
 
/// ### BOLLINGER BANDS ### ///
 
src = input(close, title="Source")
mult = input(2.0, minval=0.001, maxval=50, title="StDev")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev
 
 
/// ### KELTNER CHANNELS ### ///
 
useTrueRange = input(true)
klength = input(20, minval=1, title="Keltner Length")
kmult = input(1.0, title="Multiplier")
ksrc = input(close, title="Keltner Source")
 
ma = ema(src, klength)
range = useTrueRange ? tr : high - low
rangema = ema(range, klength)
kupper = ma + rangema * kmult
klower = ma - rangema * kmult
c = blue
 
 
/// ### CALCULATIONS ### ///
 
e1 = (highest(high, length) + lowest(low, length)) / 2 + sma(close, length)
osc = linreg(close - e1 / 2, length, 0)
osc_color = osc[1] < osc[0] ? osc[0] >= 0 ? #00ffff : #cc00cc : osc[0] >= 0 ? #009b9b : #ff9bff
alert = strict and diff < 0 ? true : not strict and kupper > upper and klower < lower ? true : false
mid_color = alert ? red : green
 
/// ### PLOTS ### ///
 
plot(osc, color=osc_color, style=histogram, linewidth=2)
plot(0, color=mid_color, style=circles, linewidth=3)
 
/// ### ALERT ### ///
 
alertcondition(alert, title= "CTTV Squeeze", message="Squeeze alert")

← 返回列表