TMO with TTM Squeeze

sskcharts · study · 58 行 · 点赞 1,022 · TradingView 原页

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

Pine Script

// @version=4
// © ssksubam
// TMO with TTM Squeeze
 
//////////////////////////////////////////////////
// True Momentum Oscillator 
 
study("TMO with TTM Squeeze", "TMO & TTM-Squeeze", overlay=false)
 
tmolength = input(21, title="TMO Length")
calcLength = input(5, title="TMO Calc length")
smoothLength = input(3, title="TMO Smooth length")
 
data = 0
for i = 1 to tmolength-1
    if close > open[i]
        data := data + 1
    if close < open[i]
        data := data - 1
    
EMA5 = ema(data, calcLength)
Main = ema(EMA5, smoothLength)
Signal = ema(Main, smoothLength)
cBias = Main > Signal ? color.green : color.red
 
ob = hline(round(70), title="overbought cutoff line", color=#b2b5be, linestyle=hline.style_solid)
os = hline(-round(70), title="oversold cutoff line", color=#b2b5be, linestyle=hline.style_solid)
upper = hline(100, title="OB Line", color=color.red, linestyle=hline.style_solid)
lower = hline(-100, title="OS Line", color=color.green, linestyle=hline.style_solid)
//zero = hline(0, title="Zero Line", color=#a8aab1, linestyle=hline.style_solid)
 
mainLine = plot(100*Main/tmolength, title="Main Line", color=cBias)
signalLine = plot(100*Signal/tmolength, title="Signal Line", color=cBias)
 
fill(mainLine, signalLine, title="Main and Signal Area", color=cBias, transp=25)
fill(ob, upper, title="OB Zone", color=color.red)
fill(os, lower, title="OS Zone", color=color.green)
 
//////////////////////////////////////////////////
// TTM Squeeze 
 
ttmsqlength = input(title="TTM Squeeze Length", type=input.integer, defval=20, minval=0)
bband(length, mult) =>
    sma(close, ttmsqlength) + mult * stdev(close, length)
keltner(length, mult) =>
    sma(close, ttmsqlength) + mult * sma(tr, length)
 
e1 = (highest(high, ttmsqlength) + lowest(low, ttmsqlength)) / 2 + sma(close, ttmsqlength)
osc = linreg(close - e1 / 2, ttmsqlength, 0)
diff = bband(ttmsqlength, 2) - keltner(ttmsqlength, 1.5)
osc_color = osc[1] < osc[0] ? osc[0] >= 0 ? #00ffff : #cc00cc : osc[0] >= 0 ? #009b9b : #ff9bff
mid_color = diff >= 0 ? #2aaf2f : color.red
 
//plot(osc, color=osc_color, style=histogram, linewidth=2)
//plot(0, color=mid_color, style=plot.style_circles, linewidth=3)
plot(0, title="Squeeze", style=plot.style_circles, linewidth=3, color=mid_color, transp=0)
 
//////////////////////////////////////////////////

← 返回列表