All in one

Biticon · study · 99 行 · 点赞 185 · TradingView 原页

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

Pine Script

//@version=3
study("All in one",overlay=true)
source=input(close)
gt=input(title="Show Bollinger Bands?", type=bool, defval=false)
l = input(title="Show Ema", type=bool, defval=false)
length22=input(11,title="Fast ema length")
length3=input(22,title="Slow ema length/channel center line")
out22=ema(source,length22)
out3=ema(source,length3)
BB_sdev = input(2.0, minval=0.001, maxval=50, title="Bollinger bands mult")
dev = BB_sdev * stdev(source, length3)
upperbb = sma(source, length3) + dev
lowerbb = sma(source, length3) - dev
plot(gt? upperbb : na, title="Upper BB", color=#2B8A84)
plot(gt? lowerbb : na, title="Lower BB", color=#2B8A84)
bg = input(title="Show Keltner Channels?", type=bool, defval=false)
Kmult = input(2.7,step=0.1, title="Keltner Range")
Krangema = ema(tr, length3)
Kupper = out3 + Krangema * Kmult
Klower = out3 - Krangema * Kmult
plot(bg? Kupper : na,style=line, color=orange, linewidth=2,title="Keltner Upper")
plot(bg? Klower : na,style=line, color=orange, linewidth=2,title="Keltner Lower")
b = input(title="Show envelope?", type=bool, defval=false)
coef=input(2,step=0.5,title="Envelope coefficent %")
upchanline=out3  +(out3*coef/100)
downchanline=out3  -(out3*coef/100)
plot(b? upchanline : na, color=black, linewidth=1, transp=0, style=line,show_last=100, title="Envelope Upper")
plot(b? downchanline : na, color=black, linewidth=1, transp=0, style=line,show_last=100, title="Envelope Lower")
g = input(title="Show Sma", type=bool, defval=false)
length33=input(11,title="Length for SMA")
out4=sma(source,length33)
out5=sma(source,50)
out6=sma(source,100)
out7=sma(source,200)
p11 = plot( g ? out4 : na,color=maroon, linewidth=1, transp=0, linewidth=1, style=line, title="Simple Moving Average")
p22 = plot( g ? out5 : na,color=blue, linewidth=1, transp=0, linewidth=1, style=line, title="50 day SMA")
plot( g ? out6 : na,color=teal, linewidth=1, transp=0, linewidth=1, style=line, title="100 day SMA")
plot( g ? out7 : na,color=purple, linewidth=1, transp=0, linewidth=1, style=line, title="200 day SMA")
fill(p11,p22,color=out4>out5 ? green:red)
p23= plot(l ? out22 : na,color=out22>out22[1] ? green : red, linewidth=1, transp=0, linewidth=1, style=line, title="Ema fast")
p33 =plot(l ? out3 : na,color=out3>out3[1]? #8cd98c : #cc9900, linewidth=1, transp=0, linewidth=1, style=line, title="Ema slow")
fill(p23,p33,color=out22>out3 ? green:red)
 
// MACD Options
macd_length_fast   = 12
macd_length_slow   = 26
macd_length_signal = 9
// Calculate MACD
macd_ma_fast       = ema(source, macd_length_fast)
macd_ma_slow       = ema(source, macd_length_slow)
macd               = macd_ma_fast  - macd_ma_slow
macd_signal        = ema(macd, macd_length_signal)
macd_histogram     = macd - macd_signal
 
// Calculate Elder Impulse
elder_bulls        = (out22[0] > out22[1]) and (macd_histogram[0] > macd_histogram[1])
elder_bears        = (out22[0] < out22[1]) and (macd_histogram[0] < macd_histogram[1])
elder_color        = elder_bulls? green: elder_bears ? red: blue
barcolor(elder_color)
 
//
startCalc = 2 * .01
incrementCalc = 2 * .01
maximumCalc = 2 * .10
sar = sar(startCalc, incrementCalc, maximumCalc)
m = input(title="Show Sar", type=bool, defval=false)
plot(m ? sar : na, title="SAR", style=cross,transp=0, linewidth=1,color=blue)
coeff = input(2, "CoEff short stop",step=0.25, type=float)
coeff2 = input(2, "CoEff long stop",step=0.25, type=float)
lookbackLength = input(10, "LookBackLength", type=integer)
countShort = high > high[1] ? 1 : 0
diffShort = high > high[1] ? high - high[1] : 0
totalCountShort = sum(countShort, lookbackLength)
totalSumShort = sum(diffShort, lookbackLength)
penAvgShort = (totalSumShort / totalCountShort)
safetyShort = high[1] + (penAvgShort[1] * coeff)
finalSafetyShort = min(min(safetyShort, safetyShort[1]), safetyShort[2])
count = low < low[1] ? 1 : 0
diff = low < low[1] ? low[1] - low : 0
totalCount = sum(count, lookbackLength)
totalSum = sum(diff, lookbackLength)
penAvg = (totalSum / totalCount)
safety = low[1] - (penAvg[1] * coeff2)
finalSafetyLong = max(max(safety, safety[1]), safety[2])
h = input(title="Show Elder Safe Zone", type=bool, defval=false)
p7 = plot(h?finalSafetyShort:na, "Short Stop", color=lime,transp=0)
p8 = plot(h?finalSafetyLong:na, "Long Stop", color=#ff00ff, transp=0)
//calculate stop value chandelier
i = input(title="Show Chandelier?", type=bool, defval=true)
Length=input(title="Look Back Period", type=integer, defval=22)
Mult=input(title="ATR Multiplier", type=integer, defval=3)
short_stop = lowest(Length)+Mult*atr(Length)
long_stop  = highest(Length)-Mult*atr(Length)
shortvs=0.0
shortvs:=na(shortvs[1]) ? short_stop : iff(close>shortvs[1], short_stop , min(short_stop,shortvs[1]))
longvs=0.0
longvs:=na(longvs[1]) ? long_stop : iff(close<longvs[1], long_stop, max(long_stop,longvs[1]))
plot(i?longvs:na, color=fuchsia, style=circles, linewidth=1)
plot(i?shortvs:na, color=blue, style=circles, linewidth=1)

← 返回列表