-
Notifications
You must be signed in to change notification settings - Fork 0
/
INDICADOR_VOLUME_PROFILE_4EMAS
158 lines (130 loc) · 7.44 KB
/
INDICADOR_VOLUME_PROFILE_4EMAS
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
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lea_127_0_0_1
//@version=5
// INDICATOR
//----------//
indicator(title = "VOLUME PROFILE + 4 EMAs(@lea_127_0_0_1, @Francrypto, @kv4coins)",
shorttitle = "VOLUME PROFILE + 4 EMAs",
overlay = true,
precision = 4,
linktoseries = true,
max_bars_back = 750,
max_lines_count = 500)
//----------//
//VOLUME PROFILE Code
//----------//
// VOLUME PROFILE (VP developed by @kv4coins)
//
// my changes to his code
// 1) bilingual titles: added spanish (SPA) ones
// 2) default value of 'vp_lookback': back 200 to avoid 'loop takes too long to execute' issue
// 3) default value of 'vp_bar_width': 2 so that it looks better
// 4) default value of 'vp_bar_mult': 60 so that it looks better
// 5) default value of 'vp_bar_offset': 62 for a simplified screen
// 6) default value of 'vp_poc_show': false for a simplified screen
// 7) max value of 'vp_lookback': 750 to avoid 'loop takes too long to execute' issue
// 8) max value of 'vp_bar_mult': 200 for a simplified screen
// 9) max value of 'vp_bar_offset': 200 for a simplified screen
// 10) placed 'vp_bar_color' in 75% transparent aqua and 'vp_poc_color' in a solid aqua
// 11) codded bullish and bearish 'bools' to avoid 'loop takes too long to execute' issue
// 12) added i_showVP option
//
// INPUTS
i_showVP = input(true, 'Show VP // Mostrar Perfil de Volumen')
vp_lookback = input.int(defval=200, title='VP Lookback Depth // Retrospectiva Profundidad del Perfil de Volumen [10-750]', minval=10, maxval=750)
vp_max_bars = input.int(defval=250, title='VP Number of Bars // Cantidad de Barras del Perfil de Volumen [10-500]', minval=10, maxval=500)
vp_bar_mult = input.int(defval=60, title='VP Bar Length Multiplier // Longitud de las Barras del Perfil de Volumen [10-200]', minval=10, maxval=200)
vp_bar_offset = input.int(defval=62, title='VP Bar Horizontal Offset // Distancia en Eje Horizontal de las Barras del Perfil de Volumen [0-200]', minval=0, maxval=200)
vp_bar_width = input.int(defval=2, title='VP Bar Width // Ancho de las Barras del Perfil de Volumen [1-20]', minval=1, maxval=20)
// As suggested by @NXT2017 to @kv4coins
vp_delta_type = input.string(defval='Both // Ambos', title='VP Delta Type // Variable Delta del Perfil de Volumen', options=['Both // Ambos', 'Bullish // Toros', 'Bearish // Osos'])
vp_poc_show = input(defval=false, title='VP Extend POC Line // Extender LÃnea del Punto de Control del Perfil de Volumen')
vp_bar_color = input(defval=color.new(color.aqua, 75), title='VP Bar Color // Color de la Barra del Perfil de Volumen')
vp_poc_color = input(defval=color.new(color.aqua, 0), title='VP POC Color // Color del Punto de control del Perfil de Volumen')
// VARIABLES
float vp_Vmax = 0.0
int vp_VmaxId = 0
int vp_N_BARS = vp_max_bars
var int vp_first = time
vp_a_P = array.new_float(vp_N_BARS + 1, 0.0)
vp_a_V = array.new_float(vp_N_BARS, 0.0)
vp_a_D = array.new_float(vp_N_BARS, 0.0)
vp_a_W = array.new_int(vp_N_BARS, 0)
// CALCULATIONS
float vp_HH = i_showVP ? ta.highest(high, vp_lookback) : na
float vp_LL = i_showVP ? ta.lowest(low, vp_lookback) : na
bool Bullish = vp_delta_type == 'Bullish // Toros'
bool Bearish = vp_delta_type == 'Bearish // Osos'
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 vp_lookback - 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 (Bullish ? close[i] >= open[i] : 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 := 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(vp_bar_mult * 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 * vp_bar_offset)
f_setup_bar(n) =>
x1 = vp_VmaxId == n and vp_poc_show ? math.max(time[vp_lookback], vp_first) : timenow + math.round(vp_change * (vp_bar_offset - 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 ? vp_poc_color : vp_bar_color, style=line.style_solid, width=vp_bar_width)
if barstate.islast
for i = 0 to vp_N_BARS - 1 by 1
f_setup_bar(i)
//----------//
//----------//
// EMA's (public domain)
// 1) bilingual titles: added spanish (SPA) ones
// 2) max value of EMA 1, 2, 3 & 4: 250 to avoid 'loop takes too long to execute' issue
// 3) default value of EMA 1 (10 periods), EMA 2 (21 periods), EMA 3 (55 periods) & EMA 4 (200 periods)
// 4) added bullish or bearish small crosses
// 5) added bullish or bearish big crosses
// 6) added i_showEMAS option
//
// VARIABLES
i_showEMAS = input(true, 'Show 4 EMAs // Mostrar 4 EMAs')
Length_Longitud_EMA_1 = input.int(8, '1° EMA length // 1° EMA longitud [1-250]', minval=1, maxval=250)
Length_Longitud_EMA_2 = input.int(21, '2° EMA length // 2° EMA longitud [1-250]', minval=1, maxval=250)
Length_Longitud_EMA_3 = input.int(55, '3° EMA length // 3° EMA longitud [1-250]', minval=1, maxval=250)
Length_Longitud_EMA_4 = input.int(200, '4° EMA length // 4° EMA longitud [1-250]', minval=1, maxval=250)
ShowCross_EMA_1_EMA2 = input(defval=true, title="1 & 2 EMAs Small crosses // Cruces pequeños de EMAs 1 y 2")
ShowCross_EMA_3_EMA4 = input(defval=true, title="3 & 4 EMAs Big Crosses // Cruces grandes de EMAs 3 y 4")
EMA1 = i_showEMAS ? ta.ema(close, Length_Longitud_EMA_1) : na
EMA2 = i_showEMAS ? ta.ema(close, Length_Longitud_EMA_2) : na
EMA3 = i_showEMAS ? ta.ema(close, Length_Longitud_EMA_3) : na
EMA4 = i_showEMAS ? ta.ema(close, Length_Longitud_EMA_4) : na
golden_cross_small = ta.cross(EMA2, EMA1) and EMA1[1] <= EMA2[1] and ShowCross_EMA_1_EMA2
death_cross_small = ta.cross(EMA2, EMA1) and EMA2[1] <= EMA1[1] and ShowCross_EMA_1_EMA2
golden_cross = ta.cross(EMA4, EMA3) and EMA3[1] <= EMA4[1] and ShowCross_EMA_3_EMA4
death_cross = ta.cross(EMA4, EMA3) and EMA4[1] <= EMA3[1] and ShowCross_EMA_3_EMA4
// PLOTING
plot(EMA1, color=color.new(#4caf50, 25), linewidth=2, title='1° Exponential Moving Average // 1° Media Móvil Exponencial')
plot(EMA2, color=color.new(#ffeb3b, 25), linewidth=2, title='2° Exponential Moving Average // 2° Media Móvil Exponencial')
plot(EMA3, color=color.new(#ffa600, 0), linewidth=2, title='3° Exponential Moving Average // 3° Media Móvil Exponencial')
plot(EMA4, color=color.new(#e91e63, 0), linewidth=2, title='4° Exponential Moving Average // 4° Media Móvil Exponencial')
plot(ShowCross_EMA_1_EMA2 ? (ta.cross(EMA1, EMA2) ? EMA1 : na) : na, color=EMA2 - EMA1 > 0 ? color.red : color.lime, style=plot.style_circles, linewidth=4)
plot(ShowCross_EMA_3_EMA4 ? (ta.cross(EMA3, EMA4) ? EMA3 : na) : na, color=EMA4 - EMA3 > 0 ? color.red : color.lime, style=plot.style_cross, linewidth=4)
//----------//