Squeeze Box [DW]

DonovanWall · study · 82 行 · 点赞 1,970 · TradingView 原页

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

Pine Script

//@version=2
study(title="Squeeze Box [DW]", overlay=true, linktoseries=true)
//by Donovan Wall
 
//This is an experimental study designed using data from Bollinger Bands to determine price squeeze ranges and active levels of support and resistance.
//First, a set of Bollinger Bands using a Coefficient of Variation weighted moving average as the basis is calculated.
//Then, the relative percentage of current bandwidth to maximum bandwidth over the specified sampling period determines the relative squeeze.
//The box is outlined by drawing the current highest and lowest source value over the sampling period whenever a squeeze is active.
//I've included the COVWMA in the visualization for additional confirmation of price activity.
 
//Custom Bar color scheme is included.
 
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 
//Source
src = input(defval=hlc3, title="Source") 
 
//Period
per  = input(defval=21, minval=1, title="Sampling Period")
 
//Standard Deviations
ndev = input(defval=2, minval=1, title="Number of Deviations for Squeeze Calculation")
 
//Relative Squeeze Threshold
sr = input(defval=50, minval=0, maxval=100, step=0.01, title="Relative Squeeze % Threshold")
 
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 
//COVWMA
covwma(a, b) =>
    cov    = stdev(a, b)/sma(a, b)
    cw     = a*cov
    covwma = sum(cw, b)/sum(cov, b)
cma  = covwma(src, per)
 
//Bollinger Bands
bu = cma + stdev(src, per)*ndev
bd = cma - stdev(src, per)*ndev
 
//Bandwidth
bw = (bu - bd)
 
//Squeeze Percentage
buh  = highest(bu, per)
bdl  = lowest(bd, per)
brng = buh - bdl
sqp  = 100*bw/brng
 
//Squeeze Box
sqz  = (sqp < sr) ? 1 : 0
boxh = sqz ? highest(src, per) : src
boxl = sqz ? lowest(src, per) : src
bh   = valuewhen(sqz, boxh, 1)
bl   = valuewhen(sqz, boxl, 1)
 
//Colors
boxcolor = src > bh ? lime : src < bl ? red : orange
bhcolor  = sqz ? boxcolor : na
blcolor  = sqz ? boxcolor : na
barcolor = (src > bh) and (src > cma) ? lime : (src > bh) and (src < cma) ? green : (src < bl) and (src < cma) ? red : (src < bl) and (src > cma) ? maroon : orange 
cmacolor = (cma > bh) ? lime : (cma < bl) ? red : orange
 
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Plots
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
 
//Squeeze Box
bhplot = plot(bh, color=boxcolor, title="Box High Level (Color 0 = Box is an Active Support Zone, Color 1 = Box is an Active Resistance Zone, Color 2 = Price is Within Box)")
blplot = plot(bl, color=boxcolor, title="Box Low Level (Color 0 = Box is an Active Support Zone, Color 1 = Box is an Active Resistance Zone, Color 2 = Price is Within Box)")
 
//COVWMA
cmaplot = plot(cma, color=cmacolor, style=circles, title="COVWMA (Color 0 = Uptrend, Color 1 = Downtrend, Color 2 = Neutral)")
 
//Fill
fill(bhplot, blplot, color=boxcolor, transp=70, title="Box Fill (Same Color Scheme Calculation as Box High and Low)")
 
//Bar Color
barcolor(barcolor, title="Bar Color (Color 0 = Uptrend, Color 1 = Pullback From Uptrend, Color 2 = Downtrend, Color 3 = Pullback From Downtrend, Color 4 = Within Box)")

← 返回列表