Combined Moving Averages + Squeeze & Volume Spike Signals

TrendFriendIndicators · study · 121 行 · 点赞 1,388 · TradingView 原页

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

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FriendOfTheTrend
 
//@version=5
indicator("Combined Moving Averages + Squeeze & Volume Spike Signals", shorttitle="Combined Moving Averages", overlay=true)
signalsOn = input.bool(true, title="Signals On/Off")
squeezeOn = input.bool(true, title="Squeeze Signals On/Off")
squeezeValue = input.float(.6, maxval=1, step=.01, title="Squeeze Value Multiplier", tooltip="This is the number to multiply the median gap of the cloud. The lower the number, the tighter the moving average squeeze will have to be to give a squeeze signal.")
ma1On = input.bool(true, title="MA #1 On/Off")
length1 = input.int(10, title="Moving Average Length #1")
source1 = input.source(close, title="Indicator Source #1")
aboveColor1 = input.color(color.lime, title="Price Above MA #1 Color")
belowColor1 = input.color(color.red, title="Price Below MA #1 Color")
ma2On = input.bool(true, title="MA #2 On/Off")
length2 = input.int(50, title="Moving Average Length #2")
source2 = input.source(close, title="Indicator Source #2")
aboveColor2 = input.color(color.lime, title="Price Above MA #2 Color")
belowColor2 = input.color(color.red, title="Price Below MA #2 Color")
ma3On = input.bool(true, title="MA #3 On/Off")
length3 = input.int(100, title="Moving Average Length #3")
source3 = input.source(close, title="Indicator Source #3")
aboveColor3 = input.color(color.lime, title="Price Above MA #3 Color")
belowColor3 = input.color(color.red, title="Price Below MA #3 Color")
ma4On = input.bool(true, title="MA #4 On/Off")
length4 = input.int(500, title="Moving Average Length #4")
source4 = input.source(close, title="Indicator Source #4")
aboveColor4 = input.color(color.lime, title="Price Above MA #4 Color")
belowColor4 = input.color(color.red, title="Price Below MA #4 Color")
 
//Combined Moving Averages Calculations
sma1 = ta.sma(source1, length1)
ema1 = ta.ema(source1, length1)
wma1 = ta.wma(source1, length1)
vwma1 = ta.vwma(source1, length1)
hma1 = ta.hma(source1, length1)
rma1 = ta.rma(source1, length1)
 
ma1 = (sma1 + ema1 + wma1 + vwma1 + hma1 + rma1) / 6
 
sma2 = ta.sma(source2, length2)
ema2 = ta.ema(source2, length2)
wma2 = ta.wma(source2, length2)
vwma2 = ta.vwma(source2, length2)
hma2 = ta.hma(source2, length2)
rma2 = ta.rma(source2, length2)
 
ma2 = (sma2 + ema2 + wma2 + vwma2 + hma2 + rma2) / 6
 
sma3 = ta.sma(source3, length3)
ema3 = ta.ema(source3, length3)
wma3 = ta.wma(source3, length3)
vwma3 = ta.vwma(source3, length3)
hma3 = ta.hma(source3, length3)
rma3 = ta.rma(source3, length3)
 
ma3 = (sma3 + ema3 + wma3 + vwma3 + hma3 + rma3) / 6
 
sma4 = ta.sma(source4, length4)
ema4 = ta.ema(source4, length4)
wma4 = ta.wma(source4, length4)
vwma4 = ta.vwma(source4, length4)
hma4 = ta.hma(source4, length4)
rma4 = ta.rma(source4, length4)
 
ma4 = (sma4 + ema4 + wma4 + vwma4 + hma4 + rma4) / 6
 
//Cloud Squeeze
squeeze = false
 
diff = ma2 > ma3 ? ma2 - ma3 : ma3 - ma2
medianDiff = ta.median(diff, 200)
 
if diff < (medianDiff*squeezeValue)
    squeeze := true
 
bgcolor(squeezeOn and squeeze ? color.rgb(255, 235, 59, 90) : na)
 
//Volume Spike Signals
volumeMedian = ta.median(volume, 10)
volumeBuy  = false
highVolumeBuy = false
 
if volume > volumeMedian and volume < volumeMedian*2
    volumeBuy := true
if volume > volumeMedian*2
    highVolumeBuy := true
 
//Line & Cloud Colors
redCloud = false
greenCloud = false
 
if ma2 > ma3
    greenCloud := true
else
    redCloud := true
 
//Plots
plot(ma1On ? ma1 : na, title="Moving Average #1", color=ma1 > ma1[1] ? aboveColor1 : belowColor1, style=plot.style_line, linewidth=2)
ma50 = plot(ma2On ? ma2 : na, title="Moving Average #2", color=greenCloud ? aboveColor2 : belowColor2, style=plot.style_line, linewidth=3)
ma100 = plot(ma3On ? ma3 : na, title="Moving Average #3", color=greenCloud ? aboveColor3 : belowColor3, style=plot.style_line, linewidth=3)
plot(ma4On ? ma4 : na, title="Moving Average #4", color=ma4 > ma4[1] ? aboveColor4 : belowColor4, style=plot.style_line, linewidth=4)
 
fill(ma50, ma100, color=greenCloud and highVolumeBuy ? color.rgb(0, 230, 119, 10) : greenCloud and volumeBuy ? color.rgb(0, 230, 119, 50) : greenCloud ? color.rgb(0, 230, 119, 80) : redCloud and highVolumeBuy ? color.rgb(255, 82, 82, 10) : redCloud and volumeBuy ? color.rgb(255, 82, 82, 50) : redCloud ? color.rgb(255, 82, 82, 80) : na)
 
//Signals
candleInCloud = false
greenCandle = close > open
redCandle = open > close
 
if greenCloud and greenCandle
    if close > ma3 and open < ma2
        candleInCloud := true
if redCloud and redCandle
    if close < ma3 and open > ma2
        candleInCloud := true
 
upSignal = greenCandle and greenCloud and volumeBuy and candleInCloud and ma2 > ma2[1] and ma3 > ma3[1] or greenCandle and greenCloud and highVolumeBuy and candleInCloud and ma2 > ma2[1] and ma3 > ma3[1] 
downSignal = redCandle and redCloud and volumeBuy and candleInCloud and ma2 < ma2[1]  and ma3 < ma3[1] or redCandle and redCloud and highVolumeBuy and candleInCloud and ma2 < ma2[1] and ma3 < ma3[1] 
 
plotshape(signalsOn ? upSignal : na, title="Buy Signal", style=shape.labelup, location=location.belowbar, color=color.lime, size=size.normal)
plotshape(signalsOn ? downSignal : na, title="Sell Signal", style=shape.labeldown, location=location.abovebar, color=color.red, size=size.normal)

← 返回列表