-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVolumn Profile.pinescript
More file actions
160 lines (131 loc) · 7.14 KB
/
Volumn Profile.pinescript
File metadata and controls
160 lines (131 loc) · 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//@version=5
//=============================================================================================
// Creator: Woverine
//
// Source Code: https://github.com/RyKaj/PineScript/tree/main
//
// Purpose:
// Woverine - Volume Profile
//
//=============================================================================================
indicator(title='Woverine - Volume Profile', shorttitle='VP', overlay=true, precision=4, linktoseries=true, max_bars_back=1000, max_lines_count=500)
//-------------------------------------------------------------------------------------------------------------------------
// Plot colors
// https://chir.ag/projects/name-that-color/#6195ED
// https://kodify.net/tradingview/colours/basic-colours/
//-------------------------------------------------------------------------------------------------------------------------
// color colorAquaIsland = #B2DFDB
// color colorAzureRadiance = #0094ff
// color colorBlack = #363A45
// color colorBlazeOrange = #ff6a00
// color colorBlue = #2196F3
// color colorBlueChill = #088A8D
// color colorBlushPink = #fd7fe6
// color colorBurntSienna = #EF5350
// color colorCandelLight = #FCD917
// color colorCoral = #FF7F50
// color colorCyan = #17FFFF
// color colorDeathCross = #e32636
// color colorFreshEggplant = #800080
// color colorFruitSalad = #4CAF50
// color colorGoldenCross = #61ed77
color colorGray = #787B86
// color colorJapaneseLaurel = #008000
// color colorGreen = #4CAF50
// color colorJungleGreen = #39ff14
// color colorKeyLimePie = #BCBB26
// color colorLilacBush = #9575cd
// color colorLime = #00E676
color colorOrange = #FF9800
// color colorParsley = #0E4813
// color colorPastelPink = #FFCDD2
// color colorPurple = #9C27B0
// color colorRed = #FF5252
// color colorRobinEggBlue = #00C9C9
// color colorRoseBudCherry = #880e4f
// color colorRusticRed = #4E0404
// color colorSaratoga = #505010
// color colorSpringGreen = #00E676
// color colorStarship = #F2F131
// color colorTamarillo = #991515
// color colorTeal = #00897B
// color colorTealBlue = #055355
// color colorTrendyGreen = #86851b
// color colorWhite = #FFFFFF
//-------------------------------------------------------------------------------------------------------------------------
// INPUTS
//-------------------------------------------------------------------------------------------------------------------------
int iLoopBack = input.int( defval=200, title='Volume Lookback Depth [10-1000]', minval=10, maxval=1000 )
int iMaxBars = input.int( defval=500, title='Number of Bars [10-500]', minval=10, maxval=500 )
int iBarMultiLength = input.int( defval=50, title='Bar Length Multiplier [10-100]', minval=10, maxval=100 )
int iBarOffset = input.int( defval=30, title='Bar Horizontal Offset [0-100]', minval=0, maxval=100 )
int iBarWidth = input.int( defval=2, title='Bar Width [1-20]', minval=1, maxval=20 )
string sDeltaType = input.string( defval='Both', title='Delta Type', options=['Both', 'Bullish', 'Bearish'] )
bool bShowPointofControlBar = input( defval=true, title='Show Point Of Control Line' )
color colorPointofControl = input( defval=color.new( colorGray , 60), title='Bar Color' )
color colorPointofControlBar = input( defval=color.new( colorOrange, 10), title='Point of Control Color' )
//-------------------------------------------------------------------------------------------------------------------------
// VARIABLES
//-------------------------------------------------------------------------------------------------------------------------
float vp_Vmax = 0.0
int vp_VmaxId = 0
int vp_N_BARS = iMaxBars
var int vp_first = time
float[] vp_a_P = array.new_float( vp_N_BARS + 1, 0.0 )
float[] vp_a_V = array.new_float( vp_N_BARS, 0.0 )
float[] vp_a_D = array.new_float( vp_N_BARS, 0.0 )
int[] vp_a_W = array.new_int( vp_N_BARS, 0 )
//-------------------------------------------------------------------------------------------------------------------------
// Functions
//-------------------------------------------------------------------------------------------------------------------------
// configBar() =>
// x1 = vp_VmaxId == n and bShowPointofControlBar ? math.max(time[iLoopBack], vp_first) : timenow + math.round(vp_change * (iBarOffset - array.get(vp_a_W, n)))
// ys = array.get(vp_a_P, n)
// line.new(x1=x1, y1=ys, x2=vp_x_loc, y2=ys, xloc=xloc.bar_time, extend=extend.none, color=vp_VmaxId == n ? colorPointofControlBar : colorPointofControl, style=line.style_solid, width=iBarWidth)
// x1 = vp_VmaxId == n and bShowPointofControlBar ? math.max(time[iLoopBack], vp_first) : timenow + math.round(vp_change * (iBarOffset - array.get(vp_a_W, n)))
// ys = array.get(vp_a_P, n)
// line.new(x1=x1, y1=ys, x2=vp_x_loc, y2=ys, xloc=xloc.bar_time, extend=extend.none, color=vp_VmaxId == n ? colorPointofControlBar : colorPointofControl, style=line.style_solid, width=iBarWidth)
//-------------------------------------------------------------------------------------------------------------------------
// CALCULATIONS
//-------------------------------------------------------------------------------------------------------------------------
float vp_HH = ta.highest( high, iLoopBack )
float vp_LL = ta.lowest( low, iLoopBack )
if barstate.islast
float vp_HL = ( vp_HH - vp_LL ) / vp_N_BARS
for j = 1 to vp_N_BARS + 1 by 1
array.set( vp_a_P, j - 1, vp_LL + vp_HL * j )
for i = 0 to iLoopBack - 1 by 1
int Dc = 0
array.fill( vp_a_D, 0.0 )
for j = 0 to vp_N_BARS - 1 by 1
float Pj = array.get( vp_a_P, j )
if low[i] < Pj and high[i] > Pj and ( sDeltaType == 'Bullish' ? close[i] >= open[i] : sDeltaType == 'Bearish' ? close[i] <= open[i] : true )
float Dj = array.get( vp_a_D, j )
float dDj = Dj + nz( volume[i] )
array.set( vp_a_D, j, dDj )
Dc += 1
Dc
for j = 0 to vp_N_BARS - 1 by 1
float Vj = array.get( vp_a_V, j )
float Dj = array.get( vp_a_D, j )
float dVj = Vj + ( Dc > 0 ? Dj / Dc : 0.0 )
array.set( vp_a_V, j, dVj )
vp_Vmax := array.max( vp_a_V )
vp_VmaxId := array.indexof( vp_a_V, vp_Vmax )
for j = 0 to vp_N_BARS - 1 by 1
float Vj = array.get( vp_a_V, j )
int Aj = math.round( iBarMultiLength * Vj / vp_Vmax )
array.set( vp_a_W, j, Aj )
//-------------------------------------------------------------------------------------------------------------------------
// PLOTING
//-------------------------------------------------------------------------------------------------------------------------
if barstate.isfirst
vp_first := time
vp_first
vp_change = ta.change( time )
vp_x_loc = timenow + math.round( vp_change * iBarOffset )
if barstate.islast
for i = 0 to vp_N_BARS - 1 by 1
x1 = vp_VmaxId == i and bShowPointofControlBar ? math.max( time[ iLoopBack ], vp_first ) : timenow + math.round( vp_change * ( iBarOffset - array.get( vp_a_W, i) ) )
ys = array.get( vp_a_P, i )
line.new( x1=x1, y1=ys, x2=vp_x_loc, y2=ys, xloc=xloc.bar_time, extend=extend.none, color=vp_VmaxId == i ? colorPointofControlBar : colorPointofControl, style=line.style_solid, width=iBarWidth )