Volume Expansions

eykpunter · study · 62 行 · 点赞 18 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © eykpunter
 
//@version=6
indicator("Volume Expansions","V Expand",false)
 
colC1=input.color(color.black,"Much Volume 120%-150%",group="Signal Marker Colors", inline="C")
colC2=input.color(color.rgb(241, 148, 8),"High Volume 150%-180%",group="Signal Marker Colors", inline="C")
colC3=input.color(color.red,"Huge Volume 180%-210%",group="Signal Marker Colors", inline="C")
colC4=input.color(color.maroon,"Extreme Volume over 210%",group="Signal Marker Colors", inline="C")
 
 
//=================================================================================================================================================
//volume calculations
 
//==Check for presence of volume in the instrument
vavg=ta.sma(volume,3)               //volume level
vmeds=ta.median(volume,5)           //new normal
norvol=ta.median(volume[1],30)    //old normal
highfocus=vavg>norvol and vmeds>norvol    //considarable volume rize
lowfocus =vavg<norvol and vmeds<norvol   //considarble low volume
eqsize=volume[1] == volume[2] and volume[1] == volume[3] and volume[1] == volume[4]
occur=highfocus or lowfocus?1:0
present= math.sum(occur,30)>4 and not eqsize   //no occurrences means no relevant volume; this also excludes fake volume
 
//======Current volume as percent of usual volume, i.e. median of 50 periods
medvol=ta.median(volume[1], 50)/100    //1 percent of median volume
 
 
curvol=volume/medvol        //current volume as percent of median volume
 
//======create High Volume markers
 
//===calculate volume cohorts
modvol=curvol<=120? 0: curvol<=150? 1: curvol<=180? 2: curvol<=210? 3: curvol>210? 4: 0  //assign Volume percents to cohorts
 
//=====volume cohorts booleans
v0=modvol==0     //unremarkable volume
v1=modvol==1     //much volume 120-150 percent (gray)
v2=modvol==2     //high volume 150-180 percent (orange)
v3=modvol==3     //huge volume 180-210 percent (blue)
v4=modvol==4     //extreme volume above 210 percent (maroon)
//======assign colors
volcol=v0? color.new(#168396, 3):v1? colC1: v2? colC2: v3? colC3: v4? colC4: na 
 
//======assign direction
//===tick direction
compare=ta.highest(close[1],2)      //level to calculate direction
closup=close>=compare               //direction up
closdn=close<compare                //direction down
 
curvolplot=closup?curvol:-curvol
 
plot(present?curvolplot:na,"V rel",volcol,style=plot.style_columns)
 
var novol = table.new(position.middle_center,1,1,color.new(color.white,100),color.new(color.white,100),1)
 
if present==false
    table.clear(novol,0,0,0,0)
    table.cell(novol,0,0,"no volume")
else
    table.clear(novol,0,0,0,0)

← 返回列表