PunkChainer ToolKit 4.0 PunkAlgo 3.0
PunkChainer ToolKit 4.0 PunkAlgo 3.0
///
// Pre-DEFINE
//
//---------------------------------------------------
var COLOR_TRANSP = color.new(#ffffff,100)
var COLOR_BLACK = color.new(#000000,0)
//---------------------------------------------------
var basicgr = "🧊 PunkAlgo Smart Fibonacci"
var fb_tooltip = "\nDepth ; The minimum number of bars that will be taken into
account when calculating the indicator.\n\nDeviation ; a multiplier that affects
how much the price should deviate from the previous pivot in order for the bar to
become a new pivot.\n"
// INPUT
//---------------------------------------------------------------------------------
------------------------------------------------------------------
view_gr = '🔴🟠🟡🟢🔵'
//---------------------------------------------------------------------------------
------------------------------------------------------------------
//---------------------------------------------------------------------------------
------------------------------------------------------------------
//---------------------------------------------------------------------------------
------------------------------------------------------------------
[k_volume,k_open,k_close,k_high,k_low,k_hlc3,k_hlcc4,k_ohlc4,k_hl2,k_close_mintick,
k_trtrue,k_atr14,k_atr14_mintick,k_rsipvt14]
= request.security(syminfo.tickerid ,'',
[volume,open,close,high,low,hlc3,hlcc4,ohlc4,hl2,str.tostring(close,format.mintick)
,ta.tr(true),ta.atr(14),str.tostring(ta.atr(14),format.mintick),ta.rsi(ta.pvt,14)]
)
//
// Background
//
//
// pre-define
-----------------------------------------------------------------------------------
---
var line fb_lineLast = na
var label fb_label_start_last = na
var label fb_label_end_last = na
var int fb_iLast = 0
var int fb_iPrev = 0
var float fb_pLast = 0
var fb_isHighLast = false // otherwise the last pivot is a low
pivot
// pivot
-----------------------------------------------------------------------------------
---
high_none = ta.highest(high,fb_depth) > nz(high[fb_depth/2])
fb_iH = high_none ? int(na) : bar_index[fb_depth/2]
fb_pH = high_none ? float(na) : nz(high[fb_depth/2])
low_none = ta.lowest (low ,fb_depth) < nz(low [fb_depth/2])
fb_iL = low_none ? int(na) : bar_index[fb_depth/2]
fb_pL = low_none ? float(na) : nz(low [fb_depth/2])
//---------------------------------------------------------------------------------
-----
calc_dev(_base_price, _price) => 100 * (_price - _base_price) / _price
//---------------------------------------------------------------------------------
-----
// Volume Profile
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 (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 += 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)
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) =>
if vp_profile_show
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)