Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This code is not mine this volume profile is by @kv4coins all the contributions for him, i just add 2 emas that TradingLatino uses
- //edited by LupownTrader
- //@version=4
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- //// STUDY
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- study(title = "Volume Profile & 2 EMA",
- shorttitle = "VP & EMA's",
- overlay = true,
- precision = 4,
- linktoseries = true,
- max_bars_back = 1000,
- max_lines_count = 500)
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- //// INPUTS
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- vp_lookback = input(defval = 200,
- title = "Volume Lookback Depth/ Velas atras [10-1000]",
- type = input.integer,
- minval = 10,
- maxval = 1000)
- vp_max_bars = input(defval = 500,
- title = "Number of Bars / ancho [10-500]",
- type = input.integer,
- minval = 10,
- maxval = 500)
- vp_bar_mult = input(defval = 50,
- title = "Bar Length Multiplier / largo [10-100]",
- type = input.integer,
- minval = 10,
- maxval = 100)
- vp_bar_offset = input(defval = 50,
- title = "Bar Horizontal Offset / Distancia con grafico [0-100]",
- type = input.integer,
- minval = 0,
- maxval = 100)
- vp_bar_width = input(defval = 2,
- title = "Bar Width / ancho [1-20]",
- type = input.integer,
- minval = 1,
- maxval = 20)
- // As suggested by @NXT2017
- vp_delta_type = input(defval = "Both",
- title = "Delta Type",
- type = input.string,
- options = ['Both', 'Bullish', 'Bearish'])
- vp_poc_show = input(defval = true,
- title = "Show POC Line",
- type = input.bool)
- vp_bar_color = input(defval = color.new(#9ac8db, 60) ,
- title = "Bar Color",
- type = input.color)
- vp_poc_color = input(defval = color.new(color.white, 10),
- title = "POC Color",
- type = input.color)
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- //// 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 = highest(high, vp_lookback)
- float vp_LL = lowest(low, vp_lookback)
- if barstate.islast
- float vp_HL = (vp_HH - vp_LL) / vp_N_BARS
- for j = 1 to (vp_N_BARS + 1)
- array.set(vp_a_P, (j-1), (vp_LL + vp_HL * j))
- for i = 0 to (vp_lookback - 1)
- int Dc = 0
- array.fill(vp_a_D, 0.0)
- for j = 0 to (vp_N_BARS - 1)
- float Pj = array.get(vp_a_P, j)
- if low[i] < Pj and high[i] > Pj and (vp_delta_type == "Bullish" ?
- close[i] >= open[i] : (vp_delta_type == "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
- for j = 0 to (vp_N_BARS - 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)
- float Vj = array.get(vp_a_V, j)
- int Aj = round(vp_bar_mult * Vj / vp_Vmax)
- array.set(vp_a_W, j, Aj)
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- //// PLOTING
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- if barstate.isfirst
- vp_first := time
- vp_change = change(time)
- vp_x_loc = timenow + round(vp_change * vp_bar_offset)
- f_setup_bar(n) =>
- x1 = ((vp_VmaxId == n) and vp_poc_show) ? max(time[vp_lookback], vp_first) :
- (timenow + 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)
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- //// END
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // EMAS
- EMA1 = input(20, minval=1, title="EMA1")
- EMA2 = input(55, minval=1, title="EMA2")
- EMA3 = input(100, minval=1, title="EMA3")
- EMA4 = input(200, minval=1, title="EMA4")
- plot(ema(close, EMA1), color=#2962ff, linewidth=1, title = "EMA 1")
- plot(ema(close, EMA2), color=#B45F04, linewidth=2, title= "EMA 2")
- plot(ema(close, EMA3), color=#fff176, linewidth=2, title = "EMA 3")
- plot(ema(close, EMA4), color=#43ff72, linewidth=2, title= "EMA 4")
Advertisement
Add Comment
Please, Sign In to add comment