Good evening all,
I currently use the below and switch between Daily, Weekly and Monthly using the below function:
dtf = input("D", title = "Time Frame", type = input.resolution)
Is there anyway of turning the below into a function so I could use security() to pick and choose what input.resolution to plot from below "//////OUTPUTS/" in the code.
I have set the below up to work on BTCUSD if you look and test the code.
I would like for example to plot using security() the daily weekly and monthly POC (and various other plots).
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
study("Security Help", overlay = true)
va_percent = input(0.68, title = "Value Area", type = input.float,
minval = 0.1, maxval = 1, step = 0.1)
offset_val = input(title="Label Offset", type=input.integer, defval=6)
dtf = input("D", title = "Time Frame", type = input.resolution)
resolution = input(1, title = "Resolution", type = input.float)
dOpen = security(syminfo.tickerid, "D", open, lookahead = barmerge.lookahead_on)
plot(dOpen, " dOpen", change(dOpen) ? na : color.blue, offset = 0)
plotshape(dOpen, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="dOpen", offset = offset_val, transp=20, title="dOpen")
is_new_bar(t) =>
change(time(t)) != 0
round_to_nearest(v, x) =>
round(v / x) * x
tick_size = max(syminfo.mintick, resolution)
var a = array.new_float(0)
a_min = 0.0, a_min := nz(a_min[1], round_to_nearest(low, tick_size))
a_max = 0.0, a_max := nz(a_max[1], round_to_nearest(high, tick_size))
d_switch = is_new_bar(dtf)
if d_switch
a_min := low
a_max := high
array.clear(a)
// Scaled min max
v_min = int(round_to_nearest(low - a_min, tick_size) / tick_size)
v_max = int(round_to_nearest(high - a_min, tick_size) / tick_size)
// Scaled candle range
ticks = v_max - v_min
vol = volume / (ticks == 0 ? 1 : ticks)
for i = v_min to max(v_max - 1, v_min)
// Insert new low value
if i < 0
array.insert(a, i - v_min, vol)
continue
// Adjust index
offset = v_min < 0 ? abs(v_min) : 0
index = int(i + offset)
// Push new high value
if index >= array.size(a)
array.push(a, vol)
continue
// Update existing value
v = array.get(a, index)
array.set(a, index, v + vol)
// Array bounds
a_min := min(a_min, round_to_nearest(low, tick_size))
a_max := max(a_max, round_to_nearest(high, tick_size))
a_size = array.size(a)
// { POC
poc_index = -1
poc_prev = -1.0
sum_vol = 0.0
for i = 0 to a_size - 1
poc_current = array.get(a, i)
sum_vol := sum_vol + poc_current
if poc_current > poc_prev
poc_prev := poc_current
poc_index := i
// }
// { VA
va_high_index = poc_index
va_low_index = poc_index
va_vol_cap = sum_vol * va_percent
sum_va_vol = array.get(a, poc_index)
for i = 1 to a_size - 1
above = 0.0
if va_high_index + 1 < a_size - 1
above := above + nz(array.get(a, (va_high_index + 1)), 0.0)
if va_high_index + 2 < a_size - 1
above := above + nz(array.get(a, (va_high_index + 2)), 0.0)
below = 0.0
if va_low_index - 1 > 0
below := below + nz(array.get(a, (va_low_index - 1)), 0.0)
if va_low_index - 2 > 0
below := below + nz(array.get(a, (va_low_index - 2)), 0.0)
if above > below
va_high_index := min(va_high_index + 2, a_size - 1)
sum_va_vol := sum_va_vol + above
else
va_low_index := max(va_low_index - 2, 0)
sum_va_vol := sum_va_vol + below
if sum_va_vol >= va_vol_cap or (va_low_index <= 0 and va_high_index >= a_size - 1)
break
// }
float p_poc = 0.0
float p_va_h = 0.0
float p_va_l = 0.0
float d_poc = 0.0
float d_va_h = 0.0
float d_va_l = 0.0
d_poc := poc_index * tick_size + a_min
d_va_h := va_high_index * tick_size + a_min
d_va_l := va_low_index * tick_size + a_min
if is_new_bar(dtf)
p_poc := d_poc[1]
p_va_h := d_va_h[1]
p_va_l := d_va_l[1]
else
p_poc := p_poc[1]
p_va_h := p_va_h[1]
p_va_l := p_va_l[1]
//////OUTPUTS
plot(d_poc, color = color.red, title = "dPOC")
plotshape(d_poc, style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, show_last=1, text="dPOC", offset = offset_val, transp=20, title="dPOC")
plot(a_max, "dHigh", change(a_max) ? na : color.blue, offset = 0)
plotshape(a_max, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="dHigh", offset = offset_val, transp=20, title="dHigh")
plot(a_min, "dLow", change(a_min) ? na : color.blue, offset = 0)
plotshape(a_min, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="dLow", offset = offset_val, transp=20, title="dLow")
plot_d_va_high = plot(d_va_h, color = color.blue, transp = 60, title = "dVAH")
plotshape(d_va_h, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="dVAH", offset = offset_val, transp=20, title="dVAH")
plot_d_va_low = plot(d_va_l, color = color.blue, transp = 60, title = "dVAL")
plotshape(d_va_l, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="dVAL", offset = offset_val, transp=20, title="dVAL")
plot(p_poc, " pd_POC", change(p_poc) ? na : color.red, offset = 0)
plotshape(p_poc, style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, show_last=1, text="pdPOC", offset = offset_val, transp=20, title="pdPOC")
ccvplot_p_va_h = plot(p_va_h, " pdVAH", change(p_va_h) ? na : color.green, offset = 0)
plotshape(p_va_h, style=shape.labeldown, location=location.absolute, color=color.green, textcolor=color.white, show_last=1, text="pdVAH", offset = offset_val, transp=20, title="pdVAH")
ccvplot_p_va_l = plot(p_va_l, " pdVAL", change(p_va_l) ? na : color.green, offset = 0)
plotshape(p_va_l, style=shape.labeldown, location=location.absolute, color=color.green, textcolor=color.white, show_last=1, text="pdVAL", offset = offset_val, transp=20, title="pdVAL")
plot(dOpen, " dOpen", change(dOpen) ? na : color.blue, offset = 0)
plotshape(dOpen, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="dOpen", offset = offset_val, transp=20, title="dOpen")
plot_p_va_h = plot(p_va_h, " pdVAH", change(p_va_h) ? na : color.blue, offset = 0)
plotshape(p_va_h, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="pdVAH", offset = offset_val, transp=20, title="pdVAH")
plot_p_va_l = plot(p_va_l, " pdVAL", change(p_va_l) ? na : color.blue, offset = 0)
plotshape(p_va_l, style=shape.labeldown, location=location.absolute, color=color.blue, textcolor=color.white, show_last=1, text="pdVAL", offset = offset_val, transp=20, title="pdVAL")
################## UPDATE ###############
Below is what I have coded so far and have to reuse the same code and change the input.resolution.
I would be very grateful if anyone can assist with making this into a function.
########Update 01/05/2021 - 1650 UK ####
The ideas I have in mind are:
No.1 To display a monitoring panel like in the below link:
https://uk.tradingview.com/script/hyMIeYGK-Initial-Balance-Monitoring-Panel/
The monitoring panel would indicate if the dOpen (for several symbols) opens outside of the pdVAL or pdVAL.
No.2 To display the outputs (plots) for different timeframes (currently I update the settings from Daily to Weekly/12 hour/6 hour/4hour. I have tried to replicate it in this link below: https://uk.tradingview.com/script/CYyx8unI-Mini-CCVs/
Also the below picture is the same indictor used 3 times to plot daily/weekly/monthly plots:
(The below picture is a bit busy but I would only chose to use certain information).

