CCI Super Bands

Ankit_1618 · study · 75 行 · 点赞 1,070 · 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/
// © Ankit_1618
 
//@version=4
study("CCI Super Bands", overlay=true)
//CCI = Commodity Channel Index
 
src = input(close, title="Source")
cci_l = input(50, title="CCI Period Length")
atr_l = input(5, title="ATR Length")
level = input(0, title="Threshold Level For CCI ")
sd_length = input(20, minval=1, title="StDev Length")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
 
 
cci = cci(src, cci_l)
atr = atr(atr_l)
 
var st =0.
 
if cci>=level 
    st := low - atr
 
if cci<=level 
    st := high + atr
 
 
var tu =0.
var td =0.
var optimal_line =0.
 
if cci>=level and cci[1]<level
    tu := td[1]
 
if cci<=level and cci[1]>level
    td := tu[1]
 
if cci>level
    tu := low - atr
    if tu<tu[1] and cci[1]>=level
        tu := tu[1]
        
if cci<level
    td := high + atr
    if td>td[1] and cci[1]<=level
        td := td[1]
        
optimal_line := max(tu, td)
 
// Creating a Price Channel, 
 
avg_st8 = ema(st,8)
avg_st13 = ema(st,13)
avg_st21 = ema(st,21)
avg_st34 = ema(st,21)
avg_st55 = ema(st,55)
avg_st89 = ema(st,89)
avg_st144 = ema(st,144)
avg_st233 = ema(st,233)
 
average_weighting = (optimal_line + avg_st8 + avg_st13 + avg_st21 + avg_st34 + avg_st55 + avg_st89 + avg_st144 + avg_st233  ) / 9
 
basis = sma(average_weighting, sd_length)
dev = mult * stdev(average_weighting, sd_length)
upper = basis + dev
lower = basis - dev
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
plot(basis, "Basis", color=#872323, offset = offset)
p1 = plot(upper, "Upper", color=color.teal, offset = offset)
p2 = plot(lower, "Lower", color=color.teal, offset = offset)
 
optimal_color = close>optimal_line and close>upper ? color.green : close<optimal_line and close>upper ? color.green : close<optimal_line and close<lower ? color.red :  close>optimal_line and close<lower ? color.red : color.yellow       
 
plot(optimal_line, color=optimal_color, linewidth=2)
fill(p1, p2, title = "Background", color=optimal_color, transp=80)

← 返回列表