// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © QuantCT //@version=4 study("ACD - Layers 1 & 2", overlay=true) session = input(title="Market Session", type=input.session, defval="0000-0000") is_crypto_session = input(title="24/7 Session(ONLY for Cryptos)", defval=true) atr_period = input(title="Daily ATR Period", defval=10, minval=2) atr_pct_a = input(title="ATR % A", defval=0.1, minval=0.05, maxval=1) atr_pct_c = input(title="ATR % C", defval=0.15, minval=0.05, maxval=1) higher_pivot_Period = input(title="Higher Pivot Period", defval=3, minval=2) is_newbar(res, sess) => t = time(res, sess) na(t[1]) and not na(t) or t[1] < t if (is_crypto_session) session := session + ":1234567" newbar = is_newbar("D", session) var float or_up = na var float or_down = na var float a_up = na var float a_down = na var float c_up = na var float c_down = na var float p1_high = na var float p1_low = na var float pn_high = na var float pn_low = na var lagged_high = array.new_float(0) var lagged_low = array.new_float(0) var lagged_close = array.new_float(0) [dh, dl, dc] = security(syminfo.tickerid, "D", [high, low, close]) ind = atr(atr_period) atr_ind = security(syminfo.tickerid, "D", ind) a = atr_ind * atr_pct_a c = atr_ind * atr_pct_c if newbar array.push(lagged_high, dh[1]) array.push(lagged_low, dl[1]) array.push(lagged_close, dc[1]) or_up := high or_down := low a_up := or_up + a a_down := or_down - a c_up := or_up + c c_down := or_down - c x = (dh[1] + dl[1] + dc[1]) / 3 // Pivot Price y = (dh[1] + dl[1]) / 2 // Second Number d = abs(x - y) // Pivot Differential p1_high := x + d p1_low := x - d lagged_arrays_size = array.size(lagged_high) slice_from_index = lagged_arrays_size - higher_pivot_Period if lagged_arrays_size >= higher_pivot_Period nh_slice = array.slice(lagged_high, slice_from_index, lagged_arrays_size) nl_slice = array.slice(lagged_low, slice_from_index, lagged_arrays_size) nc_slice = array.slice(lagged_close, slice_from_index, lagged_arrays_size) nh = array.max(nh_slice) nl = array.min(nl_slice) nc = array.get(nc_slice, array.size(nc_slice) - 1) xn = (nh + nl + nc) / 3 yn = (nh + nl) / 2 dn = abs(xn - yn) pn_high := xn + dn pn_low := xn - dn plot(or_up, style=plot.style_line, linewidth=1, color=color.aqua) plot(or_down, style=plot.style_line, linewidth=1, color=color.aqua) plot(a_up, style=plot.style_line, linewidth=1, color=color.blue, transp=50) plot(a_down, style=plot.style_line, linewidth=1, color=color.blue, transp=50) plot(c_up, style=plot.style_line, linewidth=1, color=color.white, transp=50) plot(c_down, style=plot.style_line, linewidth=1, color=color.white, transp=50) p1h_plot = plot(p1_high, style=plot.style_line, linewidth=1, color=color.yellow, transp=80) p1l_plot = plot(p1_low, style=plot.style_line, linewidth=1, color=color.yellow, transp=80) fill(p1h_plot, p1l_plot, color=color.yellow, transp=80) pnh_plot = plot(pn_high, style=plot.style_line, linewidth=1, color=color.red, transp=80) pnl_plot = plot(pn_low, style=plot.style_line, linewidth=1, color=color.red, transp=80) fill(pnh_plot, pnl_plot, color=color.red, transp=80)