Makit0_Squeeze_PRO_Arrows_v0.5BETA

makit0 · study · 128 行 · 点赞 1,154 · TradingView 原页

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

Pine Script

//@version=3
//
//@author Makit0
// 
//script based in:
// original John Carter's ideas (SQUEEZE & SQUEEZE PRO) https://www.simplertrading.com/
// LazyBear's script (Squeeze Momentum Indicator) https://www.tradingview.com/script/nqQ1DT5a-Squeeze-Momentum-Indicator-LazyBear/
//
// USE IT IN CONJUNCTION WITH THE SQUEEZE PRO INDICATOR
// 
// This system is based in the volatility reversion to the mean: volatility contraction leads to volatility expansion and the other way on
// The arrows signal is a warning of volatility compression, more often than not this leads to a expansion of volatility and a move in the action price usually bigger than the expected move
// Be aware of the trend direction don't take the arrows direction as certanty, use instead the momentum histogram in the Squeeze PRO Indicator to see the slope direction
// By default the arrows are setted at 5 dots, they fire in the sixth dot after 5 dots of the same color. Try differents values to get more or less signals
// 
// There are 3 levels of compression:
// Level 1: ORANGE, the lesser compresion level
// Level 2: RED, the normal level marked by the original squeeze indicator
// Level 3: YELLOW, the max compression level
// The more the compression the bigger the after move
// 
// Simple and Exponential Moving Averages
// There are 2 groups of Moving Averages within the indicator, the 8 & 21 EMAs and the 50, 100 & 200 SMAs
// They are disabled by default, turn it on at your peace
// 
// 
study(title="Makit0_Squeeze_PRO_Arrows_v0.5BETA", shorttitle = "SQZPRO_ARRW", overlay=true)
 
//variables
source = close
length = 20
ma = sma(source,length)
devBB = stdev(source,length)
devKC = sma(tr,length)
dots_trigger = input(defval=5,minval=1,maxval=20,title='Dot Number Trigger')
emas = input(false,title='EMAs (8 & 21)')
smas = input(false,title='SMAs (50, 100 & 200)')
 
//Bollinger 2x
upBB = ma + devBB * 2
lowBB = ma - devBB * 2
 
//Keltner 2x
upKCWide = ma + devKC * 2
lowKCWide = ma - devKC * 2
 
//Keltner 1.5x
upKCNormal = ma + devKC * 1.5
lowKCNormal = ma - devKC * 1.5
 
//Keltner 1x
upKCNarrow = ma + devKC
lowKCNarrow = ma - devKC
 
sqzOnWide  = (lowBB >= lowKCWide) and (upBB <= upKCWide) //WIDE SQUEEZE: ORANGE
sqzOnNormal  = (lowBB >= lowKCNormal) and (upBB <= upKCNormal) //NORMAL SQUEEZE: RED
sqzOnNarrow  = (lowBB >= lowKCNarrow) and (upBB <= upKCNarrow) //NARROW SQUEEZE: YELLOW
sqzOffWide = (lowBB < lowKCWide) and (upBB > upKCWide) //FIRED WIDE SQUEEZE
sqzOffNormal = (lowBB < lowKCNormal) and (upBB > upKCNormal) //FIRED NORMAL SQUEEZE
sqzOffNarrow = (lowBB < lowKCNarrow) and (upBB > upKCNarrow) //FIRED NARROW SQUEEZE
noSqz  = (sqzOnWide == false) and (sqzOffWide == false) //NO SQUEEZE
 
//Wide Dots counter
wide = 0.0
wide := nz(wide[1])
if (sqzOffWide)
    wide := 0
else
    if (sqzOnWide)
        wide := wide + 1
 
//Normal Dots counter        
normal = 0.0
normal := nz(normal[1])
if (sqzOffNormal)
    normal := 0
else
    if (sqzOnNormal)
        normal := normal + 1        
 
//Narrow Dots counter    
narrow = 0.0
narrow := nz(narrow[1])
if (sqzOffNarrow)
    narrow := 0
else
    if (sqzOnNarrow)
        narrow := narrow + 1
 
//Momentum Oscillator
mom = linreg(source  -  avg(avg(highest(high, length), lowest(low, length)),sma(close,length)),length,0)
 
//Arrows
arrows = (wide[1] == dots_trigger) or (normal[1] == dots_trigger) or (narrow[1] == dots_trigger)
arrowsup = arrows and (mom > 0)
arrowsdown = arrows and (mom < 0)
 
//Arrows color
acolor = (narrow[1] == dots_trigger) ? yellow : (normal[1] == dots_trigger) ? red : (wide[1] == dots_trigger) ? orange : lime
 
//SIGNAL
plotshape(arrowsdown,title='Short',style=shape.triangledown,location=location.abovebar,color=acolor,size=size.small, transp=0)    
plotshape(arrowsup,title='Long',style=shape.triangleup,location=location.belowbar,color=acolor,size=size.small, transp=0)
 
 
//EMAS
show_emas(emas) =>
    if (emas)
        EMA8 = ema(close, 8)
        EMA21 = ema(close, 21)
        [EMA8,EMA21]
        
[EMA8,EMA21] = show_emas(emas)
plot(EMA8,title="EMA 8",color=yellow)
plot(EMA21,title="EMA 21",color=white)
 
//SMAs
show_smas(smas) =>
    if (smas)
        SMA50 = sma(close,50)
        SMA100 = sma(close,100)
        SMA200 = sma(close,200)
        [SMA50,SMA100,SMA200]
        
[SMA50,SMA100,SMA200] = show_smas(smas)
plot(SMA50,title="SMA 50",color=white,linewidth=2)
plot(SMA100,title="SMA 100",color=aqua,linewidth=2)
plot(SMA200,title="SMA 200",color=aqua,linewidth=3)

← 返回列表