EMA20 MA50 MA200 + T3-CCI + HeikinAshi

KryptoNight · study · 82 行 · 点赞 1,317 · TradingView 原页

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

Pine Script

//@version=4
study("EMA20 MA50 MA200 + T3-CCI + HeikinAshi", shorttitle="3MAs + T3-CCI", overlay=true, precision=4)
 
show_MAs = input(true, title="checked - show MAs, unchecked - show T3-CCI")
useHA = input(false, title="Heikin Ashi mode")
t_src = useHA ? heikinashi(syminfo.tickerid) : syminfo.tickerid
p_src = input(close, title="Price Source")
src = security(t_src, timeframe.period, p_src)
 
//============== //* 3 MAs *// =========================================================================================================
ma1_len  = input(20,    title="MA1 Period (20)")
ma1_type = input(true,  title="MA1 Exponential")
ma1 = ma1_type? ema(src,ma1_len) : sma(src,ma1_len)
ma2_len  = input(50,    title="MA2 Period (50)")
ma2_type = input(false, title="MA2 Exponential")
ma2 = ma2_type? ema(src,ma2_len) : sma(src,ma2_len)
ma3_len  = input(200,   title="MA3 Period (200)")
ma3_type = input(false, title="MA3 Exponential")
ma3 = ma3_type? ema(src,ma3_len) : sma(src,ma3_len)
plot(show_MAs ? ma1 : na, color=#FF0000, transp=0, style=plot.style_line, title=" MA20 ",  linewidth=2)
plot(show_MAs ? ma2 : na, color=#0000FF, transp=0, style=plot.style_line, title=" MA50 ",  linewidth=2)
plot(show_MAs ? ma3 : na, color=#008000, transp=0, style=plot.style_line, title=" MA200 ", linewidth=2)
//============== //* 3 MAs *// =========================================================================================================
 
 
//============== //* T3-CCI *// ========================================================================================================
plot(not show_MAs?+200:na, title=" +200 Line ", color=#ff0000, transp=0, style=plot.style_linebr, linewidth=1)
plot(not show_MAs?+100:na, title=" +100 Line ", color=#800000, transp=0, style=plot.style_linebr, linewidth=1)
plot(not show_MAs?   0:na, title=" Zero Line ", color=#ff0000, transp=0, style=plot.style_linebr, linewidth=1)
plot(not show_MAs?-100:na, title=" -100 Line ", color=#800000, transp=0, style=plot.style_linebr, linewidth=1)
plot(not show_MAs?-200:na, title=" -200 Line ", color=#ff0000, transp=0, style=plot.style_linebr, linewidth=1)
float e1 = na
float e2 = na
float e3 = na
float e4 = na
float e5 = na
float e6 = na
float pos = na
CCI_Period = input(14, minval=1, title="CCI period")
T3_Period = input(5, minval=1, title="T3 period")
b = input(0.618, title="T3-CCI b")
cci_lim1 = input(-50, title="T3-CCI Buy Alert Filter")
cci_lim2 = input(+50, title="T3-CCI Sell Alert Filter")
b2 = b*b
b3 = b2*b
c1 = -b3
c2 = (3*(b2 + b3))
c3 = -3*(2*b2 + b + b3)
c4 = (1 + 3*b + b3 + 3*b2)
nn = iff(T3_Period < 1, 1, T3_Period)
nr = 1 + 0.5*(nn - 1)
w1 = 2 / (nr + 1)
w2 = 1 - w1    
xcci = cci(src, CCI_Period)
e1 := w1*xcci + w2*nz(e1[1])
e2 := w1*e1 + w2*nz(e2[1])
e3 := w1*e2 + w2*nz(e3[1])
e4 := w1*e3 + w2*nz(e4[1])
e5 := w1*e4 + w2*nz(e5[1])
e6 := w1*e5 + w2*nz(e6[1])
xccir = c1*e6 + c2*e5 + c3*e4 + c4*e3
cciHcolor = xccir>=0?color.new(#018c0b,25):color.new(#ff0006,25)
xccir_col = xccir>=0?(xccir>=xccir[1]?color.new(#00ffff,0):color.new(#1330ff,0)):(xccir>=xccir[1]? color.new(#00ffff,0):color.new(#1330ff,0))
plot(not show_MAs?xccir:na,color=cciHcolor,transp=50,title=" T3-CCI-Histogram ", style=not show_MAs?plot.style_histogram:plot.style_line, linewidth=2)
plot(not show_MAs?xccir:na,color=xccir_col,transp=00,title=" T3-CCI ", style=plot.style_line, linewidth=2) // Entry signal when moving above -100, sell signal when going below 100
//============== //* /T3-CCI *// =======================================================================================================
 
 
//============== //* Alerts *// ========================================================================================================
lc = xccir[1]<cci_lim1 and xccir>=cci_lim1 and ma1>ma2 and ma2>ma3
plotshape(show_MAs?lc:na, color=color.lime, style=shape.triangleup, transp=20, location=show_MAs?location.belowbar:location.bottom, size=size.small)
plotshape(not show_MAs?lc:na, color=color.lime, style=shape.triangleup, transp=20, location=location.bottom, size=size.tiny)
alertcondition(lc, title='*** BUY alert ***', message='*** BUY alert ***')
sc = xccir[1]>=cci_lim2 and xccir<cci_lim2 and ma1<ma2 and ma2<ma3
plotshape(show_MAs?sc:na, color=color.red, style=shape.triangledown, transp=20, location=show_MAs?location.abovebar:location.bottom, size=size.small)
plotshape(not show_MAs?sc:na, color=color.red, style=shape.triangledown, transp=20, location=location.top, size=size.tiny)
alertcondition(sc, title='*** SELL alert ***', message='*** SELL alert ***')
 
// // single plot alerts required by other indicators, such as the Risk Management Wrapper (https://www.tradingview.com/script/6MYLOs5H-Ultimate-Risk-Management-System/)
// plot(lc?+1:sc?-1:na, title="BUY SELL alerts", color=le_se==-1?color.red:color.green, style=plot.style_areabr) // uncomment to activate
alertcondition(lc?+1:sc?-1:na, title='*** BUY or SELL alert ***', message='*** BUY or SELL alert ***')
//============== //* Alerts *// ========================================================================================================

← 返回列表