-
Notifications
You must be signed in to change notification settings - Fork 1
/
volume-candle.pine
35 lines (32 loc) · 1.18 KB
/
volume-candle.pine
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
//@version=5
indicator("Volume Candle", "VC")
MAX_TRANS = 100
AVG_TRANS = 50
avgLength = input.int(20, "Average Length", minval=1, maxval=200)
maxTransLimit = input.int(80, "Max Transparency", minval=70, maxval=100)
upColor = input.color(color.teal, "Up Color")
downColor = input.color(color.red, "Down Color")
float trans = 0
if ta.tr(true) != 0 and not na(volume) and volume != 0
float sum = 0
count = 0
for i = 0 to avgLength - 1
if na(volume[i])
continue
sum := sum + volume[i]
count += 1
float avgVolume = 0
if count > 0
avgVolume := sum / count
float deviationRate = 1
if avgVolume > 0
deviationRate := (volume - avgVolume) / avgVolume
deviationRate := deviationRate > 1 ? 1 : deviationRate
deviationRate := deviationRate < -1 ? -1 : deviationRate
float diffTrans = (MAX_TRANS - AVG_TRANS) * deviationRate
trans := AVG_TRANS - diffTrans
trans := trans > maxTransLimit ? maxTransLimit : trans
upColor := color.new(upColor, trans)
downColor := color.new(downColor, trans)
color = close >= open ? upColor : downColor
plotcandle(open, high, low, close, color=color, wickcolor=color, bordercolor=color)