0% found this document useful (0 votes)
54 views6 pages

PunkChainer Levels PunkAlgo 3.0

Uploaded by

Son Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views6 pages

PunkChainer Levels PunkAlgo 3.0

Uploaded by

Son Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

//@version=5

indicator("PunkChainer™ Levels 2.0 [PunkAlgo 3.0]", overlay=true)

// FVG Module

showfvg = input.bool(false, "Show Smart MTF FVG", group = "🧊 FVG MTF Module")
changelvl = input.bool(true, "Move box levels with price touch", group='FVG MTF
Module')
changecolor = input.bool(true, "Change box color with price touch", group='FVG MTF
Module')
extend_r = input.bool(true, "Extend boxes to the right", group='FVG MTF Module')
plotLabel = input.bool(defval=false, title='Plot OB Label', inline='FVG label',
group='Style')
LabelColor = input.color(defval=color.gray, title='Color', inline='FVG label',
group='Style')
LabelSize = input.string(defval=size.tiny, title="Size", options=[size.huge,
size.large, size.small, size.tiny, size.auto, size.normal], inline='FVG label',
group='Style')
BullColor = input.color(defval=color.new(#00dbff, 90), title='Bullish FVG Color',
inline='Set Custom Color', group='Style')
BearColor = input.color(defval=color.new(#0c3299, 90), title='Bearish FVG Color',
inline='Set Custom Color', group='Style')
BullColorTested = input.color(defval=color.new(color.gray, 90), title='Tested
Bullish FVG Color', inline='Set Custom Color', group='Style')
BearColorTested = input.color(defval=color.new(color.gray, 90), title='Tested
Bearish FVG Color', inline='Set Custom Color', group='Style')

var box[] bull_box = array.new_box()


var box[] bear_box = array.new_box()

tf1 = input.bool(false, "1", group='Timeframe')


tf2 = input.bool(false, "3", group='Timeframe')
tf3 = input.bool(false, "5", group='Timeframe')
tf4 = input.bool(true, "15", group='Timeframe')
tf5 = input.bool(false, "30", group='Timeframe')
tf6 = input.bool(false, "45", group='Timeframe')
tf7 = input.bool(true, "60", group='Timeframe')
tf8 = input.bool(false, "120", group='Timeframe')
tf9 = input.bool(false, "180", group='Timeframe')
tf10 = input.bool(true, "240", group='Timeframe')
tf11 = input.bool(true, "D", group='Timeframe')
tf12 = input.bool(true, "W", group='Timeframe')

find_box(t) =>
var int x = na
var float _top = na
var float _bottom = na
var int _time = na
if barstate.isconfirmed
x := low[2] >= high ? -1 : low >= high[2] ? 1 : 0
_top := x > 0 ? low : x < 0 ? low[2] : 0
_bottom := x > 0 ? high[2] : x < 0 ? high : 0
_time := time - t * 60000 * 2
[_time, _top, _bottom, x]

create_box(_time, _top, _bottom, x, TF) =>


_col = x > 0 ? BullColor : BearColor
_extend = extend_r ? extend.right : extend.none
_text = plotLabel ? TF : na
box boxOB = na
if x != 0
boxOB := box.new(left=_time, top=_top, right=time, extend=_extend ,
bottom=_bottom, bgcolor=_col, border_color = na, text=_text,
text_halign=text.align_right, text_size=LabelSize, text_color=LabelColor, xloc =
xloc.bar_time)
if x > 0
array.push(bull_box, boxOB)
if x < 0
array.push(bear_box, boxOB)

control_box(_boxes, bearbull) =>


if array.size(_boxes) > 0
for i = array.size(_boxes) - 1 to 0 by 1
_box = array.get(_boxes, i)
_boxLow = box.get_bottom(_box)
_boxHigh = box.get_top(_box)
if (bearbull > 0 and low < _boxLow) or (bearbull < 0 and high >
_boxHigh)
box.delete(_box)
array.set(_boxes, i, na)
else
if bearbull > 0 and low < _boxHigh
if changelvl
box.set_top(_box, low)
if changecolor
box.set_bgcolor(_box, BullColorTested)
if bearbull < 0 and high > _boxLow
if changelvl
box.set_bottom(_box, high)
if changecolor
box.set_bgcolor(_box, BullColorTested)
box.set_right(_box, time)
if array.size(_boxes) > 0
for i = array.size(_boxes) - 1 to 0 by 1
if na(array.get(_boxes, i))
array.remove(_boxes, i)

[_time1, _top1, _bottom1, xtf1] = request.security(syminfo.tickerid, "1",


find_box(1))
[_time2, _top2, _bottom2, xtf2] = request.security(syminfo.tickerid, "3",
find_box(3))
[_time3, _top3, _bottom3, xtf3] = request.security(syminfo.tickerid, "5",
find_box(5))
[_time4, _top4, _bottom4, xtf4] = request.security(syminfo.tickerid, "15",
find_box(15))
[_time5, _top5, _bottom5, xtf5] = request.security(syminfo.tickerid, "30",
find_box(30))
[_time6, _top6, _bottom6, xtf6] = request.security(syminfo.tickerid, "45",
find_box(45))
[_time7, _top7, _bottom7, xtf7] = request.security(syminfo.tickerid, "60",
find_box(60))
[_time8, _top8, _bottom8, xtf8] = request.security(syminfo.tickerid, "120",
find_box(120))
[_time9, _top9, _bottom9, xtf9] = request.security(syminfo.tickerid, "180",
find_box(180))
[_time10, _top10, _bottom10, xtf10] = request.security(syminfo.tickerid, "240",
find_box(240))
[_time11, _top11, _bottom11, xtf11] = request.security(syminfo.tickerid, "D",
find_box(1440))
[_time12, _top12, _bottom12, xtf12] = request.security(syminfo.tickerid, "W",
find_box(10080))

if showfvg
if tf1 and timeframe.change("1")
create_box(_time1, _top1, _bottom1, xtf1, "1")
if tf2 and timeframe.change("3")
create_box(_time2, _top2, _bottom2, xtf2, "3")
if tf3 and timeframe.change("5")
create_box(_time3, _top3, _bottom3, xtf3, "5")
if tf4 and timeframe.change("15")
create_box(_time4, _top4, _bottom4, xtf4, "15")
if tf5 and timeframe.change("30")
create_box(_time5, _top5, _bottom5, xtf5, "30")
if tf6 and timeframe.change("45")
create_box(_time6, _top6, _bottom6, xtf6, "45")
if tf7 and timeframe.change("60")
create_box(_time7, _top7, _bottom7, xtf7, "60")
if tf8 and timeframe.change("120")
create_box(_time8, _top8, _bottom8, xtf8, "120")
if tf9 and timeframe.change("180")
create_box(_time9, _top9, _bottom9, xtf9, "180")
if tf10 and timeframe.change("240")
create_box(_time10, _top10, _bottom10, xtf10, "240")
if tf11 and timeframe.change("D")
create_box(_time11, _top11, _bottom11, xtf11, "D")
if tf12 and timeframe.change("W")
create_box(_time12, _top12, _bottom12, xtf12, "W")

control_box(bull_box, 1)
control_box(bear_box, -1)

// Support and Resistances

enableSR = input(true, "SR On/Off", group="🧊 Support and Resistances")


colorSup = input(color.new(#00DBFF,20), "Support Color", group="Support and
Resistances")
colorRes = input(color.new(#9598a1,50), "Resistance Color", group="Support and
Resistances")
strengthSR = input.int(2, "S/R Strength", 1, group="Support and Resistances")
lineStyle = input.string("Dotted", "Line Style", ["Solid", "Dotted", "Dashed"],
group="Support and Resistances")
lineWidth = input.int(1, "S/R Line Width", 1, group="Support and Resistances")
useZones = input(true, "Zones On/Off", group="Support and Resistances")
useHLZones = input(true, "High Low Zones On/Off", group="Support and
ResistancesSR")
zoneWidth = input.int(1, "Zone Width %", 0, tooltip="it's calculated using % of
the distance between highest/lowest in last 300 bars", group="Support and
Resistances")
expandSR = input(true, "Expand Support and Resistances")
// Functions
percWidth(len, perc) => (ta.highest(len) - ta.lowest(len)) * perc / 100
// Get components
rb = 10
prd = 284
ChannelW = 10
label_loc = 55
style = lineStyle == "Solid" ? line.style_solid : lineStyle == "Dotted" ?
line.style_dotted : line.style_dashed
ph = ta.pivothigh(rb, rb)
pl = ta.pivotlow (rb, rb)
sr_levels = array.new_float(21, na)
prdhighest = ta.highest(prd)
prdlowest = ta.lowest(prd)
cwidth = percWidth(prd, ChannelW)
zonePerc = percWidth(300, zoneWidth)
aas = array.new_bool(41, true)
u1 = 0.0, u1 := nz(u1[1])
d1 = 0.0, d1 := nz(d1[1])
highestph = 0.0, highestph := highestph[1]
lowestpl = 0.0, lowestpl := lowestpl[1]
var sr_levs = array.new_float(21, na)
label hlabel = na, label.delete(hlabel[1])
label llabel = na, label.delete(llabel[1])
var sr_lines = array.new_line(21, na)
var sr_linesH = array.new_line(21, na)
var sr_linesL = array.new_line(21, na)
var sr_linesF = array.new_linefill(21, na)
var sr_labels = array.new_label(21, na)
if ph or pl
for x = 0 to array.size(sr_levels) - 1
array.set(sr_levels, x, na)
highestph := prdlowest
lowestpl := prdhighest
countpp = 0
for x = 0 to prd
if na(close[x])
break
if not na(ph[x]) or not na(pl[x])
highestph := math.max(highestph, nz(ph[x], prdlowest), nz(pl[x],
prdlowest))
lowestpl := math.min(lowestpl, nz(ph[x], prdhighest), nz(pl[x],
prdhighest))
countpp += 1
if countpp > 40
break
if array.get(aas, countpp)
upl = (ph[x] ? high[x + rb] : low[x + rb]) + cwidth
dnl = (ph[x] ? high[x + rb] : low[x + rb]) - cwidth
u1 := countpp == 1 ? upl : u1
d1 := countpp == 1 ? dnl : d1
tmp = array.new_bool(41, true)
cnt = 0
tpoint = 0
for xx = 0 to prd
if na(close[xx])
break
if not na(ph[xx]) or not na(pl[xx])
chg = false
cnt += 1
if cnt > 40
break
if array.get(aas, cnt)
if not na(ph[xx])
if high[xx + rb] <= upl and high[xx + rb] >= dnl
tpoint += 1
chg := true
if not na(pl[xx])
if low[xx + rb] <= upl and low[xx + rb] >= dnl
tpoint += 1
chg := true
if chg and cnt < 41
array.set(tmp, cnt, false)
if tpoint >= strengthSR
for g = 0 to 40 by 1
if not array.get(tmp, g)
array.set(aas, g, false)
if ph[x] and countpp < 21
array.set(sr_levels, countpp, high[x + rb])
if pl[x] and countpp < 21
array.set(sr_levels, countpp, low[x + rb])
// Plot
var line highest_ = na, line.delete(highest_)
var line lowest_ = na, line.delete(lowest_)
var line highest_fill1 = na, line.delete(highest_fill1)
var line highest_fill2 = na, line.delete(highest_fill2)
var line lowest_fill1 = na, line.delete(lowest_fill1)
var line lowest_fill2 = na, line.delete(lowest_fill2)
hi_col = close >= highestph ? colorSup : colorRes
lo_col = close >= lowestpl ? colorSup : colorRes
if enableSR
highest_ := line.new(bar_index - 311, highestph, bar_index, highestph,
xloc.bar_index, expandSR ? extend.both : extend.right, hi_col, style, lineWidth)
lowest_ := line.new(bar_index - 311, lowestpl , bar_index, lowestpl ,
xloc.bar_index, expandSR ? extend.both : extend.right, lo_col, style, lineWidth)
if useHLZones
highest_fill1 := line.new(bar_index - 311, highestph + zonePerc, bar_index,
highestph + zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
highest_fill2 := line.new(bar_index - 311, highestph - zonePerc, bar_index,
highestph - zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
lowest_fill1 := line.new(bar_index - 311, lowestpl + zonePerc , bar_index,
lowestpl + zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
lowest_fill2 := line.new(bar_index - 311, lowestpl - zonePerc , bar_index,
lowestpl - zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
linefill.new(highest_fill1, highest_fill2, color.new(hi_col, 80))
linefill.new(lowest_fill1 , lowest_fill2 , color.new(lo_col, 80))
if ph or pl
for x = 0 to array.size(sr_lines) - 1
array.set(sr_levs, x, array.get(sr_levels, x))
for x = 0 to array.size(sr_lines) - 1
line.delete(array.get(sr_lines, x))
line.delete(array.get(sr_linesH, x))
line.delete(array.get(sr_linesL, x))
linefill.delete(array.get(sr_linesF, x))
if array.get(sr_levs, x) and enableSR
line_col = close >= array.get(sr_levs, x) ? colorSup : colorRes
array.set(sr_lines, x, line.new(bar_index - 355, array.get(sr_levs, x),
bar_index, array.get(sr_levs, x), xloc.bar_index, expandSR ? extend.both :
extend.right, line_col, style, lineWidth))
if useZones
array.set(sr_linesH, x, line.new(bar_index - 355, array.get(sr_levs, x)
+ zonePerc, bar_index, array.get(sr_levs, x) + zonePerc, xloc.bar_index, expandSR ?
extend.both : extend.right, na))
array.set(sr_linesL, x, line.new(bar_index - 355, array.get(sr_levs, x)
- zonePerc, bar_index, array.get(sr_levs, x) - zonePerc, xloc.bar_index, expandSR ?
extend.both : extend.right, na))
array.set(sr_linesF, x, linefill.new(array.get(sr_linesH, x),
array.get(sr_linesL, x), color.new(line_col, 80)))
for x = 0 to array.size(sr_labels) - 1
label.delete(array.get(sr_labels, x))
if array.get(sr_levs, x) and enableSR
lab_loc = close >= array.get(sr_levs, x) ? label.style_label_up :
label.style_label_down
lab_col = close >= array.get(sr_levs, x) ? colorSup : colorRes
array.set(sr_labels, x, label.new(bar_index + label_loc, array.get(sr_levs,
x), str.tostring(math.round_to_mintick(array.get(sr_levs, x))), color=lab_col ,
textcolor=#000000, style=lab_loc))
hlabel := enableSR ? label.new(bar_index + label_loc +
math.round(math.sign(label_loc)) * 20, highestph, "High Level : " +
str.tostring(highestph), color=hi_col, textcolor=#000000,
style=label.style_label_down) : na
llabel := enableSR ? label.new(bar_index + label_loc +
math.round(math.sign(label_loc)) * 20, lowestpl , "Low Level : " +
str.tostring(lowestpl) , color=lo_col, textcolor=#000000,
style=label.style_label_up ) : na

You might also like