HAlgo Pieki
HAlgo Pieki
0
at https://mozilla.org/MPL/2.0/
// Thanks to Efrem for Market Structure | StratifyTrade - formerly know as
HunterAlgos
// © Pieki
//@version=5
// # ========================================================================= #
// # | Pieki Algo V2 Indicator |
// # ========================================================================= #
indicator(title = "Pieki Algo [2.0]", shorttitle = "Pieki Algo", overlay = true,
max_bars_back = 500 ,max_lines_count = 500, max_labels_count = 500,
max_boxes_count = 500)
// # ========================================================================= #
// # | Pieki Algo V2 Indicator |
// # ========================================================================= #
// Risk Managments
gr_risk = "RISK MANAGEMENT"
levels = input.bool(false, "Show TP/SL Levels" , group = gr_risk , inline = "1")
lvlLines = input.bool(false, "Show Lines ", inline="2", group = gr_risk)
linesStyle = input.string("SOLID", "", ["SOLID", "DASHED", "DOTTED"], inline="2",
group = gr_risk)
atrRisk = input.int(1, "Risk % ", 1, group = gr_risk , inline="3")
lvlDecimals = input.int(2, "Decimals", 1, 8, inline="3", group = gr_risk)
// ICT KILL Zones
gr_ict = "ICT KILL ZONES"
i_tz = input.string('GMT-5', title= 'Timezone', options=['GMT-
11', 'GMT-10', 'GMT-9', 'GMT-8', 'GMT-7', 'GMT-6', 'GMT-5', 'GMT-4', 'GMT-3', 'GMT-
2', 'GMT-1', 'GMT', 'GMT+1', 'GMT+2', 'GMT+3', 'GMT+330', 'GMT+4', 'GMT+430',
'GMT+5', 'GMT+530', 'GMT+6', 'GMT+7', 'GMT+8', 'GMT+9', 'GMT+10', 'GMT+11',
'GMT+12'], tooltip='e.g. \'America/New_York\', \'Asia/Tokyo\', \'GMT-
4\', \'GMT+9\'...', group=gr_ict, inline = "1")
i_history_period = input.int(1, 'History', minval=0, maxval=100, group =
gr_ict, inline = "1" )
var bool canPlot = (timeframe.isminutes and timeframe.multiplier <= 60) or
timeframe.isseconds
i_show = i_history_period > 0 and canPlot
i_lookback = 12 * 60
LoSB = input(false, title="3-4 am", group = gr_ict,inline = "2")
NYSB = input(false, title="10-11 am", group = gr_ict,inline = "2")
NYPM = input(false, title="2-3 Pm", group = gr_ict,inline = "2")
LSBcolor = input.color(color.new(#5d606b,0),title="", group = gr_ict,inline
= "2")
LSBstyle = input.string ("Dashed", "", options=["Solid", "Dotted", "Dashed"],
group = gr_ict,inline = "2")
LST = LSBstyle == "Solid" ? line.style_solid : LSBstyle == "Dotted" ?
line.style_dotted : line.style_dashed
i_show_sess1 = input.bool(defval= true, title ="" ,group=gr_ict,
inline="a") and i_show
i_sess1Text = input.string ("Asian Range", title ="" ,group=gr_ict,
inline="a")
i_sess1_color = input.color(defval=color.new(#2a2e39, 0), title="",
group=gr_ict, inline="a")
i_sess1 = input.session('1900-2400', 'Time', group=gr_ict,
inline="a")
var i_sess1_extend ='× No'
var i_sess1_op = true
i_show_sess2 = input.bool(defval= true, title ="" , group=gr_ict,
inline="b") and i_show
i_sess2Text = input.string ("London", title ="" , group=gr_ict,
inline="b")
i_sess2_color = input.color(defval=color.new(#5b9cf6, 0), title="",
group=gr_ict, inline="b")
i_sess2 = input.session('0200-0500', "Time" , group=gr_ict,
inline="b")
var i_sess2_extend ='× No'
var i_sess2_op = true
i_show_sess3 = input.bool(defval= true, title ="" ,group=gr_ict,
inline="t") and i_show
i_sess3Text = input.string ("New York", title ="" ,group=gr_ict,
inline="t")
i_sess3_color = input.color(defval=color.new(#22ab94, 0), title="",
group=gr_ict, inline="t")
i_sess3 = input.session('0700-1000', "Time" , group=gr_ict,
inline="t")
var i_sess3_extend ='× No'
var i_sess3_op = true
i_show_sess4 = input.bool(defval= false , title ="" ,group=gr_ict,
inline="h" ) and i_show
i_sess4Text = input.string ("New York cl", title ="" ,group=gr_ict,
inline="h")
i_sess4_color = input.color(defval=color.new(#ec407a, 0), title="",
group=gr_ict, inline="h")
i_sess4 = input.session('1300-1600', "Time" , group=gr_ict,
inline="h")
var i_sess4_extend ='× No'
var i_sess4_op = true
i_show_sess5 = input.bool(defval= false , title ="" ,group=gr_ict,
inline="hz" ) and i_show
i_sess5Text = input.string ("input name", title ="" ,group=gr_ict,
inline="hz")
i_sess5_color = input.color(defval=color.new(#ba68c8, 0), title="",
group=gr_ict, inline="hz")
i_sess5 = input.session('1600-1630', "Time" , group=gr_ict,
inline="hz")
var i_sess5_extend ='× No'
var i_sess5_op = true
i_sess_box_style = input.string('Sandwich', 'Style', options=['Box',
'Sandwich'], group=gr_ict, inline="q")
i_sess_border_style = input.string(line.style_solid, 'Line style',
options=[line.style_solid, line.style_dotted, line.style_dashed], group=gr_ict,
inline="q")
i_sess_border_width = input.int(1, 'Thickness', minval=0, group=gr_ict,
inline="qq")
i_sess_bgopacity = input.int(94, 'Transp', minval=0, maxval=100, step=1,
group=gr_ict, tooltip='Setting the 100 is no background color', inline="qq")
f_get_label_position (_y, _side) =>
switch _y
'top' => _side == 'outside' ? label.style_label_lower_left :
label.style_label_upper_left
'bottom' => _side == 'outside' ? label.style_label_upper_left :
label.style_label_lower_left
i_label_show = input.bool(true, 'Show labels', group=gr_ict,
inline='label_show') and i_show
i_label_size = str.lower(input.string('Small', '', options=['Auto',
'Tiny', 'Small', 'Normal', 'Large', 'Huge'], group=gr_ict, inline='label_show'))
i_label_position_y = str.lower(input.string('Top', '', options=['Top',
'Bottom'], group=gr_ict, inline='label_show'))
i_label_position_s = str.lower(input.string('Outside', '', options=['Inside',
'Outside'], group=gr_ict, inline='label_show'))
i_label_position = f_get_label_position(i_label_position_y,
i_label_position_s)
i_label_format_name = input.bool(true, 'Name', group=gr_ict,
inline='label_format')
i_label_format_day = input.bool(false, 'Day', group=gr_ict,
inline='label_format')
i_label_format_price = input.bool(false, 'Price', group=gr_ict,
inline='label_format')
i_label_format_pips = input.bool(false, 'Pips', group=gr_ict,
inline='label_format')
// # ============================[SIGNALS]============================ #
supertrend(_close, factor, atrLen) =>
atr = ta.atr(atrLen)
upperBand = _close + factor * atr
lowerBand = _close - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ?
lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ?
upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
[superTrend, direction]
sma1 = ta.sma(close, 8)
sma2 = ta.sma(close, 9)
sma3 = ta.sma(close, 13)
[supertrend, direction] = supertrend(close, sigsensiviti*2, 11)
buy = bull and showsignal ? label.new(bar_index, y1, sma1 >= sma2 ? "▲ +" : "▲",
xloc.bar_index, yloc.price, bullish, label.style_label_up, color.white,
size.normal) : na
sell = bear and showsignal ? label.new(bar_index, y2, sma1 <= sma2 ? "▼ +" : "▼",
xloc.bar_index, yloc.price, bearish, label.style_label_down, color.white,
size.normal) : na
// # ============================[BAR COLOR]============================ #
atrb = 10 * ta.atr(sigsensiviti)
longStop = hl2 - atrb * 1
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = hl2 + atrb * 1
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) :
shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and close > shortStopPrev ? 1 : dir == 1 and close <
longStopPrev ? -1 : dir
barcolor(colorbar ? (dir == 1 ? bullish : bearish) : na)
// # ============================[Wave Trend]============================ #
wma = ta.wma(close, wavelenght)
wma1 = ta.wma(close, wavelenght)
a = 3 * wma - 2 * wma1
a1 = ta.sma(close, wavelenght)
diff = a - a1
x = diff
len = 100
xMax = ta.highest(x, len)
xMin = ta.lowest(x, len)
range_ = xMax - xMin
y = x / range_
g = math.round(y*40)
color1 = color.from_gradient(g, -2, 2, bearish, bullish)
tw1 = plot(wavetrend ? a : na, 'WaveTrend 1', color1, 2, editable = false)
tw2 = plot(wavetrend ? a1 : na, 'WaveTrend 2', color1, 2, editable = false)
fill(tw1, tw2, color = color1)
// # ============================[Trend Lines]============================ #
//Downtrendline
var int phx1 = na
var float phslope = na
var float phy1 = na
var float upper = na
var float plotH = na
var bool isOnH = false
//Uptrendline
var int plx1 = na
var float plslope = na
var float ply1 = na
var float lower = na
var float plotL = na
var bool isOnL = false
phy1 := ph
phx1 := n - trendlilenght
upper += phslope
plotH := not na(ph) and ta.change(phslope) ? na : srcBl[1] > upper[1] ? na :
upper
bs_H = ta.barssince(na(plotH))
if not na(pl)
if pl > ply1
[normalised_slope, slope, angle] = calculate_slope(plx1, n - trendlilenght,
ply1, pl)
testLine.set_xy1(plx1, ply1), testLine.set_xy2(n, pl + slope *
trendlilenght)
src = source, max_bars_back(src, 2000)
isOnL := false
broken = false
if angle > 0.1 and angle < 90
for i = trendlilenght to n - plx1
if src[i] < testLine.get_price(n - i)
broken := true
break
if not broken
plslope := slope
isOnL := true
lower := pl + slope * trendlilenght
line.new(plx1, ply1, n, pl + slope * trendlilenght,
color=bullish, style=line.style_dotted)
ply1 := pl
plx1 := n - trendlilenght
lower += plslope
plotL := not na(pl) and ta.change(plslope) ? na : srcBr[1] < lower[1] ? na :
lower
bs_L = ta.barssince(na(plotL))
// # ============================[VolumeProfile]============================ #
// Get Components
import algotraderdev/contrast/1
int BASE_OFFSET = 20 + 80
int LABEL_OFFSET = BASE_OFFSET + 2
int START_TIME = switch volumeprofile
volumeprofile => chart.left_visible_bar_time
USE_SECOND_BASED_TIMEFRAMES = false
int MIN_TIMEFRAME_IN_SECONDS = USE_SECOND_BASED_TIMEFRAMES ? 1 : 60
// Function
maxIndex(float[] a) =>
if a.size() == 0
na
float max = a.first()
int maxIndex = 0
for [i, v] in a
if v > max
max := v
maxIndex := i
maxIndex
const int DIRECTION_NONE = 0
const int DIRECTION_BUY = 1
const int DIRECTION_SELL = -1
type Candle
float high
float low
float volume
int direction
type Marker
polyline poly
line extendedLine
label label
method set(Marker this, string name, int left, int right, float price, color bg,
float height) =>
if not na(this.poly)
this.poly.delete()
float bottom = price - height / 2
float top = bottom + height
chart.point[] points = array.from(
chart.point.from_index(left, bottom),
chart.point.from_index(left, top),
chart.point.from_index(right, top),
chart.point.from_index(right, bottom))
this.poly := polyline.new(points, line_color = bg, fill_color = bg)
if not na(this.extendedLine)
this.extendedLine.delete()
if volumeprofile
this.extendedLine := line.new(
x1 = left,
y1 = price,
x2 = right,
y2 = price,
extend = extend.left,
style = line.style_dotted,
color = bg)
if na(this.label)
this.label.delete()
string txt = str.format('{0}: {1}', name, math.round_to_mintick(price))
this.label := label.new(
x = bar_index + LABEL_OFFSET,
y = price,
text = txt,
style = label.style_label_left,
size = size.small,
color = bg,
textcolor = bg.contrast(0.6))
this
type VP
Candle[] candles
float minPrice
float maxPrice
float step
polyline poly
polyline buyPoly
polyline sellPoly
map<string, Marker> markers
method init(VP this) =>
this.candles := array.new<Candle>()
this.markers := map.new<string, Marker>()
this
method getBucketIndex(VP this, float price) =>
math.min(math.floor((price - this.minPrice) / this.step), volumerows - 1)
method getBucketedPrice(VP this, int index) =>
(index + 0.5) * this.step + this.minPrice
method mark(VP this, string name, float price, int left, color bg, float height) =>
int right = bar_index + BASE_OFFSET
Marker marker = this.markers.get(name)
if na(marker)
marker := Marker.new().set(name = name, left = left, right = right, price =
price, bg = bg, height = height)
method store(VP this, Candle candle) =>
this.candles.push(candle)
this.minPrice := na(this.minPrice) ? candle.low : math.min(this.minPrice,
candle.low)
this.maxPrice := na(this.maxPrice) ? candle.high : math.max(this.maxPrice,
candle.high)
this.step := (this.maxPrice - this.minPrice) / volumerows
method drawHistogram(VP this, int[] xs, int baseX, float step, float height, color
color) =>
chart.point[] points = array.new<chart.point>()
float gap = (step - height) / 2
for [i, x] in xs
float lo = i * step + gap + this.minPrice
float hi = lo + height
points.push(chart.point.from_index(index = baseX, price = lo))
points.push(chart.point.from_index(index = x, price = lo))
points.push(chart.point.from_index(index = x, price = hi))
points.push(chart.point.from_index(index = baseX, price = hi))
polyline.new(points, closed = true, line_color = color, fill_color = color)
method update(VP this) =>
float step = (this.maxPrice - this.minPrice) / volumerows
float[] dist = array.new_float(volumerows, 0)
float[] deltaDist = array.new_float(volumerows, 0)
for c in this.candles
int start = this.getBucketIndex(c.low)
int end = this.getBucketIndex(c.high)
int buckets = end - start + 1
// Plot
if not na(this.poly)
this.poly.delete()
this.poly := volumeprofile ? this.drawHistogram(xs, baseX, step, height,
color.new(#5d606b77,45)) : na
if volumeprofile
int[] buyXs = array.new_int()
int[] sellXs = array.new_int()
for vol in deltaDist
int width = math.round(math.abs(vol) / maxVol * 80)
int x = baseX - width
buyXs.push(vol > 0 ? x : baseX)
sellXs.push(vol < 0 ? x : baseX)
if not na(this.buyPoly)
this.buyPoly.delete()
this.buyPoly := this.drawHistogram(buyXs, baseX, step, height,
color.new(#089981, 50))
if not na(this.sellPoly)
this.sellPoly.delete()
this.sellPoly := this.drawHistogram(sellXs, baseX, step, height,
color.new(#f23645,50))
if volumeprofile
float valPercentile = (100 - 70) / 100 / 2
float vahPercentile = 1 - valPercentile
int valIndex = cumdist.binary_search_leftmost(totalVolume * valPercentile)
this.mark(
name = 'VAL',
price = this.getBucketedPrice(valIndex),
left = xs.get(valIndex),
bg = color.blue,
height = height)
if volumeprofile
int pocIndex = maxIndex(dist)
this.mark(
name = 'POC',
price = this.getBucketedPrice(pocIndex),
left = xs.get(pocIndex),
bg = color.yellow,
height = height)
var VP vp = VP.new().init()
if not na(cs)
for c in cs
vp.store(c)
if barstate.islast
vp.update()
// # ============================[Liquidity]============================ #
// Get Components
mitiOptions = "Remove"
displayStyle_liq = "Boxes"
hh = close
ll = close
timediff=(time[1]-time[101])/100
atr_liq = ta.atr(300)
float thold_liq = atr_liq * (2.5 / 10)
// Functions
tf_multi(tf) =>
ts = timeframe.in_seconds("")
htfs = timeframe.in_seconds(tf)
htfs/ts
display_limit_line(_array) =>
if array.size(_array) > 6/2
a = array.shift(_array)
line.delete(a)
display_limit_box(_array) =>
if array.size(_array) > 6/2
a = array.shift(_array)
box.delete(a)
remove_mitigated_lines(_array, _hl) =>
m = false
if array.size(_array) > 0
for i = array.size(_array) - 1 to 0 by 1
l = array.get(_array, i)
if _hl == "High" and hh > line.get_y1(l)
array.remove(_array, i)
if mitiOptions == "Show"
line.new(line.get_x1(l),line.get_y1(l),time,line.get_y1(l),
xloc=xloc.bar_time, color = color.new(#f23645,50), style=line.style_solid, width =
2)
line.delete(l)
m := true
if _hl == "Low" and ll < line.get_y1(l)
array.remove(_array, i)
if mitiOptions == "Show"
line.new(line.get_x1(l),line.get_y1(l),time,line.get_y1(l),
xloc=xloc.bar_time, color = color.new(#089981,50), style=line.style_solid, width =
2)
line.delete(l)
m := true
display_limit_line(_array)
m
remove_mitigated_boxes(_array, _hl) =>
m = false
if array.size(_array) > 0
for i = array.size(_array) - 1 to 0 by 1
l = array.get(_array, i)
if _hl == "High" and hh > box.get_top(l)
array.remove(_array, i)
if mitiOptions == "Show"
box.new(box.get_left(l),box.get_top(l),time,box.get_bottom(l),
xloc=xloc.bar_time, bgcolor = color.new(#f23645, 90), border_color =
color.new( #f23645, 90), border_style = line.style_solid)
box.delete(l)
m := true
if _hl == "Low" and ll < box.get_top(l)
array.remove(_array, i)
if mitiOptions == "Show"
box.new(box.get_left(l),box.get_top(l),time,box.get_bottom(l),
xloc=xloc.bar_time, bgcolor = color.new(#089981, 90), border_color =
color.new(#089981, 90), border_style = line.style_solid)
box.delete(l)
m := true
display_limit_box(_array)
m
extend_line_to_current(lineArray) =>
if array.size(lineArray) > 0
for i = array.size(lineArray) - 1 to 0 by 1
l = array.get(lineArray, i)
timeExt = timenow + ((timediff)*30)
line.set_x2(l, timeExt)
extend_box_to_current(boxArray) =>
if array.size(boxArray) > 0
for i = array.size(boxArray) - 1 to 0 by 1
b = array.get(boxArray, i)
timeExt = timenow + ((timediff)*30)
box.set_right(b, timeExt)
// ----------------------------------------------------
// Higher TimeFrame
// ----------------------------------------------------
// Varibles
// Lines
var highLineArrayHTF = array.new_line()
var lowLineArrayHTF = array.new_line()
// Boxes
var highBoxArrayHTF = array.new_box()
var lowBoxArrayHTF = array.new_box()
// Get HTF
[_time, _open, _high, _low, _close] = request.security(syminfo.tickerid, htfTF,
[time, open, high, low, close])
// Pivots
pivotHighHTF = ta.pivothigh(_high, 8*tf_multi(htfTF), 8+tf_multi(htfTF))
pivotLowHTF = ta.pivotlow(_low, 8*tf_multi(htfTF), 8+tf_multi(htfTF))
if liquidity
timeExt = time+((time[1]-time[2])*10)
dis = 8+tf_multi(htfTF)
if pivotHighHTF
if displayStyle_liq == "Lines"
array.push(highLineArrayHTF,
line.new(_time[dis],_high[dis],_time[+1],_high[dis],color = color.new(#f23645,50),
style=line.style_solid, xloc=xloc.bar_time, extend=extend.none, width = 2))
else
y1 = _high[dis]-thold_liq//math.max(_open[dis], _close[dis])
array.push(highBoxArrayHTF,
box.new(_time[dis],_high[dis],_time[+1],y1,bgcolor = color.new(#f23645,50) ,
border_color=color.new(#f23645,90), xloc=xloc.bar_time, border_style =
line.style_solid, extend=extend.none, border_width = 2,text="$",text_halign =
text.align_center,text_color = color.white,text_size = size.small))
if pivotLowHTF
if displayStyle_liq == "Lines"
array.push(lowLineArrayHTF,
line.new(_time[dis],_low[dis],_time[+1],_low[dis],color = color.new(#089981,50),
style=line.style_solid, xloc=xloc.bar_time, extend=extend.none, width = 2))
else
y1 = _low[dis]+thold_liq//math.min(_open[dis], _close[dis])
array.push(lowBoxArrayHTF,
box.new(_time[dis],_low[dis],_time[+1],y1,bgcolor = color.new(#089981,50),
border_color=color.new(#089981,90), xloc=xloc.bar_time, border_style =
line.style_solid, extend=extend.none, border_width = 2,text="$",text_halign =
text.align_center,text_color = color.white,text_size = size.small))
// ----------------------------------------------------
// Run Functions
// ----------------------------------------------------
highLineAlertHTF = remove_mitigated_lines(highLineArrayHTF, "High")
lowLineAlertHTF = remove_mitigated_lines(lowLineArrayHTF, "Low")
highBoxAlertHTF = remove_mitigated_boxes(highBoxArrayHTF, "High")
lowBoxAlertHTF = remove_mitigated_boxes(lowBoxArrayHTF, "Low")
extend_line_to_current(highLineArrayHTF)
extend_line_to_current(lowLineArrayHTF)
extend_box_to_current(highBoxArrayHTF)
extend_box_to_current(lowBoxArrayHTF)
// # ============================[VWAP]============================ #
vwapLength = 20
vwapValue = ta.vwma(close, vwapLength)
plot(vwap ? vwapValue : na, color=color.orange, title="VWAP")
// # ============================[DASHBOARD]============================ #
indicatorTF = "Chart"
// -- MTF Function
f_chartTfInMinutes() =>
float _resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
// Wywołanie funkcji
adxTrend = detectADXTrend()
// MTF
TF1Bull = securityNoRep(syminfo.tickerid, "1" , adxTrend)
TF3Bull = securityNoRep(syminfo.tickerid, "3" , adxTrend)
TF5Bull = securityNoRep(syminfo.tickerid, "5" , adxTrend)
TF10Bull = securityNoRep(syminfo.tickerid, "10" , adxTrend)
TF15Bull = securityNoRep(syminfo.tickerid, "15" , adxTrend)
TF30Bull = securityNoRep(syminfo.tickerid, "30" , adxTrend)
TF60Bull = securityNoRep(syminfo.tickerid, "60" , adxTrend)
TF120Bull = securityNoRep(syminfo.tickerid, "120" , adxTrend)
TF240Bull = securityNoRep(syminfo.tickerid, "240" , adxTrend)
TF720Bull = securityNoRep(syminfo.tickerid, "720" , adxTrend)
TFDBull = securityNoRep(syminfo.tickerid, "1440", adxTrend)
// -- Optimal Sensitivity
knnSensitivity(close, sensitivity, k) =>
data = request.security(syminfo.tickerid, "D", close)
input_data = ta.sma(data, 20)
distance = math.abs(close - input_data)
array_size = 100
percentVol = 40 * calcDev + 30
// -- Squeeze
conv = 50
lengthsq = 20
srcs = close
// Get components
cond(_offset) =>
top = ta.highest(high, 10)
bot = ta.lowest(low, 10)
osc = ta.ema(hlc3, 5) - ta.ema(ohlc4, 20)
oscRis = osc > osc[1]
oscFal = osc < osc[1]
oscA0 = osc > 0
oscB0 = osc < 0
oscTop = oscFal and oscRis[1]
oscBot = oscRis and oscFal[1]
bullR = oscB0 and oscBot and ((osc > ta.valuewhen(oscB0 and oscBot, osc, 1)
and bot < ta.valuewhen(oscB0 and oscBot, bot, 1)))
bearR = oscA0 and oscTop and ((osc < ta.valuewhen(oscA0 and oscTop, osc, 1)
and top > ta.valuewhen(oscA0 and oscTop, top, 1)))
bullH = oscB0 and oscBot and ((osc < ta.valuewhen(oscB0 and oscBot, osc, 1)
and bot > ta.valuewhen(oscB0 and oscBot, bot, 1)))
bearH = oscA0 and oscTop and ((osc > ta.valuewhen(oscA0 and oscTop, osc, 1)
and top < ta.valuewhen(oscA0 and oscTop, top, 1)))
[sqzOn, sqzOff] = sqz(20, 2, 20, 2, close)
[_hist1, _line1, upper1, lower1] = qqe(6, 6, 3, close, 50, 0.001)
[_hist2, _line2, upper2, lower2] = qqe(6, 5, 1.618, close, 50, 1)
[_, _, tvr] = ta.dmi(14, 14)
[osc[_offset], oscRis[_offset], oscFal[_offset], oscA0[_offset],
oscB0[_offset], oscTop[_offset], oscBot[_offset], bullR[_offset], bearR[_offset],
bullH[_offset], bearH[_offset], sqzOn[_offset], sqzOff[_offset], _hist1[_offset],
upper1[_offset], lower1[_offset], _hist2[_offset], _line2[_offset], tvr[_offset]]
tf = indicatorTF == "Chart" ? timeframe.period : indicatorTF == "1 minute" ? "1" :
indicatorTF == "3 minutes" ? "3" : indicatorTF == "5 minutes" ? "5" : indicatorTF
== "10 minutes" ? "10" : indicatorTF == "15 minutes" ? "15" : indicatorTF == "30
minutes" ? "30" : indicatorTF == "45 minutes" ? "45" : indicatorTF == "1 hour" ?
"60" : indicatorTF == "2 hours" ? "120" : indicatorTF == "3 hours" ? "180" :
indicatorTF == "4 hours" ? "240" : indicatorTF == "12 hours" ? "720" : indicatorTF
== "1 day" ? "1D" : indicatorTF == "1 week" ? "1W" : indicatorTF == "1 month" ?
"1M" : na
[osc, oscRis, oscFal, oscA0, oscB0, oscTop, oscBot, bullR, bearR, bullH, bearH,
sqzOn, sqzOff, _hist1, upper1, lower1, _hist2, _line2, tvr] =
request.security(syminfo.tickerid, tf, cond(indicatorTF != "Chart" and
barstate.isrealtime ? 1 : 0))
//Session A
NYSes = true
NYTxt = 'New York'
NYTime = '1300-2200'
//Session B
LDSes = true
sesb_txt = 'London'
sesb_ses = '0700-1600'
//Session C
show_sesc = true
sesc_txt = 'Tokyo'
sesc_ses = '0000-0900'
//Session D
show_sesd = true
sesd_txt = 'Sydney'
sesd_ses = '2100-0600'
tff = timeframe.period
var tz = exchange ? syminfo.timezone :
str.format('UTC{0}{1}', utc_exchange >= 0 ? '+' : '-', math.abs(utc_exchange))
if is_sesc
SessionText := sesc_txt
if is_sesb
SessionText := sesb_txt
if is_sesa
SessionText := NYTxt
// MTF Trend
dashboard_cell(0, 0 , "MTF")
dashboard_cell(0, 2 , "M5") , dashboard_cell_bg(0, 2 , TF5Bull ?
color.new(bullish, 20) : color.new(bearish,20))
dashboard_cell(0, 3 , "M15") , dashboard_cell_bg(0, 3 , TF15Bull ?
color.new(bullish, 20) : color.new(bearish,20))
dashboard_cell(0, 4 , "M30") , dashboard_cell_bg(0, 4 , TF30Bull ?
color.new(bullish, 20) : color.new(bearish,20))
dashboard_cell(0, 5 , "1H") , dashboard_cell_bg(0, 5 , TF60Bull ?
color.new(bullish, 20): color.new(bearish,20))
dashboard_cell(0, 6 , "4H") , dashboard_cell_bg(0, 6 , TF240Bull ?
color.new(bullish, 20): color.new(bearish,20))
// Middel part
dashboard_cell(1, 0 , " Pieki Algo V.2")
dashboard_cell(1, 2 , "🔎 Optimal Sensitivity ")
dashboard_cell(1, 3 , str.tostring(trendIndication) + " Trend Strength ")
dashboard_cell(1, 4 , "⚠️ Volatility ")
dashboard_cell(1, 5 , "💠 Squeeze ")
dashboard_cell(1, 6 , "🕒 Current Session (UTC) ")
// End part
dashboard_cell(2, 0 , "")
dashboard_cell(2, 2 , str.tostring(final_sensitivity , "#"))
dashboard_cell(2, 3 , str.tostring(adx, format.percent))
dashboard_cell(2, 4 , str.tostring(percentVol, format.percent))
dashboard_cell(2, 5 , str.tostring(squeezePercentage, format.percent))
dashboard_cell(2, 6 , SessionText)
// # ============================[Market Structure]============================ #
// Get comp
boolean =
array.from(false, false , false , false , false , false , false , false, false)
s_BOS = 0
s_CHoCH = 1
i_BOS = 2
i_CHoCH = 3
i_pp_CHoCH = 4
green_candle = 5
red_candle = 6
s_CHoCHP = 7
i_CHoCHP = 8
ob_filter = "None"
invcol = color.new(color.white,100)
type bar
float o = open
float c = close
float h = high
float l = low
float v = volume
int n = bar_index
int t = time
type ms
float[] p
int [] n
float[] l
type msDraw
int n
float p
color css
string txt
bool bull
type ehl
float pt
int t
float pb
int b
// General Setup
bar b = bar.new()
switch
lstyle(style) =>
hy = ta.valuewhen(h != h[1] , h , 1)
hx = ta.valuewhen(h == high , time , 1)
ly = ta.valuewhen(l != l[1] , l , 1)
lx = ta.valuewhen(l == low , time , 1)
if barstate.islast
line.set_xy1(hl , hx , hy)
line.set_xy2(hl , extension , hy)
label.set_xy(hlb, extension , hy)
line.set_xy1(ll , lx , ly)
line.set_xy2(ll , extension , ly)
label.set_xy(lbl, extension , ly)
if lvl_daily
if lvl_weekly
if lvl_monthly
if lvl_yearly
var line id = na
var label lbl = na
id := line.new(
d.n
, d.p
, b.n
, d.p
, color = d.css
, width = 1
, style = style
)
line.delete(msline.shift())
msline.push(id)
lbl := label.new(
int(math.avg(d.n, b.n))
, d.p
, d.txt
, color = invcol
, textcolor = d.css
, style = d.bull ? label.style_label_down : label.style_label_up
, size = size
, text_font_family = font.family_monospace
)
msDraw drw = na
n = bar_index
var ms up = ms.new(
array.new<float>()
, array.new< int >()
, array.new<float>()
)
var ms dn = ms.new(
array.new<float>()
, array.new< int >()
, array.new<float>()
)
switch show_swing_ms
switch show_internal_ms
switch
iH =>
up.p.unshift(b.h[iLen])
up.l.unshift(b.h[iLen])
up.n.unshift(n [iLen])
iL =>
dn.p.unshift(b.l[iLen])
dn.l.unshift(b.l[iLen])
dn.n.unshift(n [iLen])
sL =>
sdn.p.unshift(b.l[sLen])
sdn.l.unshift(b.l[sLen])
sdn.n.unshift(n [sLen])
sH =>
sup.p.unshift(b.h[sLen])
sup.l.unshift(b.h[sLen])
sup.n.unshift(n [sLen])
if ta.crossover(b.c, up.p.first())
bool CHoCH = na
string txt = na
if itrend < 0
CHoCH := true
switch
txt := "BOS"
css := i_ms_up_BOS
isdrw := true
drw := msDraw.new(
up.n.first()
, up.p.first()
, i_ms_up_BOS
, txt
, true
)
CHoCH =>
isdrw := true
drw := msDraw.new(
up.n.first()
, up.p.first()
, i_ms_up_BOS.darkcss(0.25, true)
, txt
, true
)
if mtf == false
switch
itrend := 1
up.n.clear()
up.p.clear()
if ta.crossunder(b.c, dn.p.first())
bool CHoCH = na
string txt = na
if itrend > 0
CHoCH := true
switch
txt := "BOS"
css := i_ms_dn_BOS
isdrw := true
drw := msDraw.new(
dn.n.first()
, dn.p.first()
, i_ms_dn_BOS
, txt
, false
)
CHoCH =>
isdrw := true
drw := msDraw.new(
dn.n.first()
, dn.p.first()
, i_ms_dn_BOS.darkcss(0.25, false)
, txt
, false
)
if mtf == false
switch
itrend := -1
dn.n.clear()
dn.p.clear()
if ta.crossover(b.c, sup.p.first())
bool CHoCH = na
string txt = na
if trend < 0
CHoCH := true
switch
txt := "BOS"
icss := s_ms_up_BOS
isdrwS := true
drw := msDraw.new(
sup.n.first()
, sup.p.first()
, s_ms_up_BOS
, txt
, true
)
CHoCH =>
isdrwS := true
drw := msDraw.new(
sup.n.first()
, sup.p.first()
, s_ms_up_BOS.darkcss(0.25, true)
, txt
, true
)
if mtf == false
switch
trend := 1
sup.n.clear()
sup.p.clear()
if ta.crossunder(b.c, sdn.p.first())
bool CHoCH = na
string txt = na
if trend > 0
CHoCH := true
switch
txt := "BOS"
icss := s_ms_dn_BOS
CHoCH =>
isdrwS := true
drw := msDraw.new(
sdn.n.first()
, sdn.p.first()
, s_ms_dn_BOS.darkcss(0.25, false)
, txt
, false
)
if mtf == false
switch
trend := -1
sdn.n.clear()
sdn.p.clear()
[css, bear_ob, bull_ob, itrend, drw, isdrw, s_bear_ob, s_bull_ob, trend, icss,
isdrwS]
[css, bear_ob, bull_ob, itrend, drw, isdrw, s_bear_ob, s_bull_ob, trend, icss,
isdrwS] = structure(false)
if isdrw
f_line(drw, size.small, line.style_dashed)
if isdrwS
f_line(drw, size.small, line.style_solid)
if show_mtf_str
table.merge_cells(tab, 0, 5, 1, 5)
table.merge_cells(tab, 0, 5, 1, 5)
// EQH/EQL
dEHL() =>
switch
top =>
mx = math.max(top, w.pt)
mn = math.min(top, w.pt)
switch
var aZ = array.new<line>()
var aL = array.new<label>()
if aZ.size() > 50
aZ.pop().delete()
aL.pop().delete()
w.pt := top
w.t := b.n - 1
btm =>
mx = math.max(btm, w.pb)
mn = math.min(btm, w.pb)
switch
var aZ = array.new<line>()
var aL = array.new<label>()
if aZ.size() > 50
aZ.pop().delete()
aL.pop().delete()
w.pb := btm
w.b := b.n - 1
if show_eql
dEHL()
// # ============================[RISK MANAGEMENT]============================ #
decimals = lvlDecimals == 1 ? "#.#" : lvlDecimals == 2 ? "#.##" : lvlDecimals == 3
? "#.###" : lvlDecimals == 4 ? "#.####" : lvlDecimals == 5 ? "#.#####" :
lvlDecimals == 6 ? "#.######" : lvlDecimals == 7 ? "#.#######" : "#.########"
atrLen = 14
rigger2 = bull ? 1 : 0
countBull = ta.barssince(bull)
countBear = ta.barssince(bear)
trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
atrBand = ta.atr(atrLen) * atrRisk
atrStop = trigger == 1 ? low - atrBand : high + atrBand
stop_y = lastTrade(atrStop)
stop = levels ? label.new(time, close, "SL " + str.tostring(stop_y, decimals),
xloc.bar_time, yloc.price, bearish, label.style_label_left, color.white,
size.normal) : na
label.set_x(stop, label.get_x(stop) + math.round(ta.change(time) * 1))
label.set_y(stop, stop_y)
label.delete(stop[1])
plotchar(LoSB ? LL and i_show : false, text= "3-4 am", char = " ", textcolor =
LSBcolor, location=location.top, offset=0)
// 10-11 am Silver Bullet
N1 = time ("1", '1000-1001:1234567')
NN = time ("1", '1030-1031:1234567')
N2 = time ("1", '1100-1101:1234567')
plotchar(NYSB ? NN and i_show : false, text= "10-11 am", char = " ", textcolor =
LSBcolor, location=location.top, offset=0)
// 2-3 pm Silver Bullet
P1 = time ("1", '1400-1401:1234567')
PSB = time ("1", '1430-1431:1234567')
P2 = time ("1", '1500-1501:1234567')
plotchar(NYPM ? PSB and i_show : false, text= "2-3 pm", char = " ", textcolor =
LSBcolor, location=location.top, offset=0)
// Definded
max_bars = 500
option_yes = 'Yes'
option_no = '× No'
option_extend1 = 'Yes'
option_hide = '× Hide'
fmt_price = '{0,number,#.#####}'
fmt_pips = '{0,number,#.#}'
f_message_limit_bars (_v) => '⚠️ This box\'s right position exceeds 500 bars(' +
str.tostring(_v) + '). This box is not displayed correctly.'
if _is_started
start_time := time
if i_label_format_day
array.push(v_label, util.get_day(dayofweek(start_time, i_tz)))
if i_label_format_price
array.push(v_label, str.format(fmt_price, v_chg))
if i_label_format_pips
array.push(v_label, str.format(fmt_pips, util.toPips(v_chg)) + ' pips')
if _show
if _is_started
my_label := label.new(bar_index, v_position_y, array.join(v_label,
icon_separator), textcolor=_color, color=color_none, size=i_label_size,
style=i_label_position)
array.push(_labels, my_label)
util.clear_labels(_labels, i_history_period)
else if _session
label.set_y(my_label, v_position_y)
label.set_text(my_label, array.join(v_label, icon_separator))
// Rendering Limit Massage
f_render_limitmessage (_show, _session, _is_started, _is_ended, _x, _y, _rightbars)
=>
var label my_note = na
if _show
if _is_started
if _rightbars > max_bars
my_note := label.new(_x, _y, f_message_limit_bars(_rightbars),
style=label.style_label_upper_left, color=color.yellow, textalign=text.align_left,
yloc=yloc.price)
else if _session
if _rightbars > max_bars
label.set_y(my_note, _y)
label.set_text(my_note, f_message_limit_bars(_rightbars))
else
label.delete(my_note)
else if _is_ended
label.delete(my_note)
true
// Rendering session
f_render_sessionrange (_show, _session, _is_started, _is_ended, _color, _top,
_bottom, _x1, _x2, _is_extend, _lines) =>
var line above_line = na
var line below_line = na
if _show
if _is_started
above_line := line.new(_x1, _top, _x2, _top, width=i_sess_border_width,
style=i_sess_border_style, color=_color)
below_line := line.new(_x1, _bottom, _x2, _bottom,
width=i_sess_border_width, style=i_sess_border_style, color=_color)
linefill.new(above_line, below_line, color.new(_color,
i_sess_bgopacity))
array.push(_lines, above_line)
array.push(_lines, below_line)
util.clear_lines(_lines, i_history_period * 2)
if _is_extend
line.set_extend(above_line, extend.right)
line.set_extend(below_line, extend.right)
else if _session
line.set_y1(above_line, _top)
line.set_y2(above_line, _top)
line.set_x2(above_line, _x2)
line.set_y1(below_line, _bottom)
line.set_y2(below_line, _bottom)
line.set_x2(below_line, _x2)
true
else if _is_ended
true
true
// Rendering session box
f_render_session (_show, _session, _is_started, _is_ended, _color, _top, _bottom,
_x1, _x2, _is_extend, _boxes) =>
var box my_box = na
if _show
if _is_started
my_box := box.new(_x1, _top, _x2, _bottom, _color, i_sess_border_width,
i_sess_border_style, bgcolor=color.new(_color, i_sess_bgopacity))
array.push(_boxes, my_box)
util.clear_boxes(_boxes, i_history_period)
if _is_extend
box.set_extend(my_box, extend.right)
else if _session
box.set_top(my_box, _top)
box.set_bottom(my_box, _bottom)
f_set_box_right(my_box, _x2)
else if _is_ended
box.set_right(my_box, bar_index)
my_box
// Drawing market
f_render_main (_show, _session, _is_started, _is_ended, _color, _top, _bottom) =>
var box my_box = na
var label my_note = na
var x1 = 0
var x2 = 0
var session_open = 0.0
var session_high = 0.0
var session_low = 0.0
if _show
if _is_started
x1 := bar_index
x2 := bar_index + (math.min(x0_d, limit_bars))
session_open := open
session_high := _top
session_low := _bottom
else if _session
true_x2 = x1 + x0_d
rightbars := true_x2 - bar_index
limit_bars := bar_index + max_bars
x2 := math.min(true_x2, limit_bars)
session_high := _top
session_low := _bottom
else if _is_ended
session_open := na
if i_osc
top := i_osc_max
bottom := i_osc_min
is_started = f_get_started(_session)
is_ended = f_get_ended(_session)
is_extend = _extend != option_no
if i_sess_box_style == 'Box'
f_render_session(_show, _session, is_started, is_ended, _color, top,
bottom, x1, x2, is_extend, _boxes_session)
if i_sess_box_style == 'Sandwich'
f_render_sessionrange(_show, _session, is_started, is_ended, _color, top,
bottom, x1, x2, is_extend, _lines_session)
if i_label_show
f_render_label(_show, _session, is_started, _color, top, bottom, _label,
_labels)