Pieki Algo v1.1
Pieki Algo v1.1
Pieki Algo v1.1
// # ========================================================================= #
indicator(title = "Pieki Algo | Signals & Overlays [v.1.1]", shorttitle = "Pieki
Algo", overlay = true, max_lines_count = 500, max_labels_count = 500,
max_boxes_count = 500, max_bars_back = 500, max_polylines_count = 100)
// # ========================================================================= #
bullish = #089981
bearish = #f23645
start_style = #36a7f2
stop_style = #944f77
// # ========================================================================= #
// Signals
gr_signals = "SIGNALS SETTINGS"
showsignal = input(true, "Show Signals", group = gr_signals, inline = "00")
sigsensiviti = input.float(3, "Sensivity", step = 0.1, group = gr_signals, inline =
"01")
// Indicator Overlays
gr_overlays = "INDICATOR OVERLAYS"
showcandle = input(true, "Coloring Candle", group = gr_overlays, inline = "11")
candleoption = input.string("Trend", "", options = ["Trend","RSI Gradient"],group =
gr_overlays, inline = "11")
shoowtrendwave = input(true, "Wave Trend", group = gr_overlays, inline ="12")
// Market Structure
gr_ms = "MARKET STRUCTURE"
show_swing_ms = input.string("All", "Swing", inline = "1", group = gr_ms, options =
["All", "CHoCH", "CHoCH+", "BOS", "None"])
show_internal_ms = input.string("All", "Internal", inline = "2", group = gr_ms,
options = ["All", "CHoCH", "CHoCH+", "BOS", "None"])
internal_r_lookback = input.int(5, "", inline = "2", group = gr_ms, minval = 2)
swing_r_lookback = input.int(50, "", inline = "1", group = gr_ms, minval = 2)
ms_mode = input.string("Manual", "Market Structure Mode", inline = "a", group =
gr_ms,options = ["Manual", "Dynamic"])
show_mtf_str = input.bool(false, "MTF Scanner", inline = "9", group = gr_ms)
show_eql = input.bool(false, "Show EQH/EQL", inline = "6", group = gr_ms)
// VOLUMETRIC ORDER BLOCKS
gr_ob = "VOLUMETRIC ORDER BLOCKS"
ob_show = input.bool(false, "Show Last", inline = "1", group = gr_ob)
ob_num = input.int(5, "", inline = "1", group = gr_ob,minval = 1, maxval = 10)
ob_metrics_show= input.bool(false, "Internal Buy/Sell Activity",group = gr_ob)
css_metric_up = input.color(color.new(#089981, 50), "", inline = "2", group =
gr_ob)
css_metric_dn = input.color(color.new(#f23645 , 50), "", inline = "2", group =
gr_ob)
ob_swings = input.bool(false, "Swing Order Blocks", inline = "a", group = gr_ob)
css_swing_up = input.color(color.new(color.gray , 90), "", inline = "a", group =
gr_ob)
css_swing_dn = input.color(color.new(color.silver, 90), "", inline = "a", group =
gr_ob)
ob_filter = input.string("None", "Filtering", inline = "d", group = gr_ob, options
= ["None", "BOS", "CHoCH", "CHoCH+"])
ob_mitigation = input.string("Absolute", "Mitigation", inline = "4", group = gr_ob,
options = ["Absolute", "Middle"])
ob_pos = input.string("Precise", "Positioning", inline = "k", group = gr_ob,options
= ["Full", "Middle", "Accurate", "Precise"])
use_grayscale = input.bool(false, "Grayscale", inline = "6", group = gr_ob)
use_show_metric = input.bool(false, "Show Metrics", inline = "7", group = gr_ob)
use_middle_line = input.bool(false, "Show Middle-Line", inline = "8", group =
gr_ob)
use_overlap = input.bool(false, "Hide Overlap", inline = "9", group = gr_ob
, tooltip = "Hide overlapping order blocks")
use_overlap_method = input.string("Previous", "Overlap Method", inline = "Z", group
= gr_ob, options = ["Recent", "Previous"])
ob_bull_css = input.color(color.new(#089981 , 90), "", inline = "1", group =
gr_ob)
ob_bear_css = input.color(color.new(#f23645 , 90), "", inline = "1", group =
gr_ob)
// Support & Resistance
gr_sr = "SUPPORT & RESISTANCE"
showsr = input(false, title="Show Support & Resistance", group = gr_sr)
swing_length = input.int(defval=8, title="Sensitivity", group = gr_sr)
box_width = input.float(defval=4, title="Zone Width", group = gr_sr)
box_extend_option = input.string("Right", title="Extend Box", options=["Right",
"Both"], group = gr_sr)
res = input.timeframe(title='Time Frame', defval='', group= gr_sr)
s1 = request.security(syminfo.tickerid, res, showsr, gaps=barmerge.gaps_on)
demand_color = input.color(#089981, title = 'Support & Resistance Color', group =
gr_sr ,inline = "1")
supply_color = input.color(#f23645, title = '', group = gr_sr, inline = "1")
sidewaysThreshold = input.int(title='ADX Sideways Threshold (10-30)', minval=2,
defval=15)
// Dashboard
gr_dashboard = "DASHBOARD SETTINGS"
showDash = input(true, "Dashboard", group = gr_dashboard)
dashLoc = input.string('Bottom Right', 'Location', options = ['Top Right', 'Bottom
Right', 'Bottom Left'], group = gr_dashboard)
textSize = input.string('Normal', 'Size', options = ['Tiny', 'Small', 'Normal'],
group = gr_dashboard)
// Risk Management
gr_risk = "RISK Management"
levels = input.bool(false, "Show TP/SL Levels" , group = gr_risk , inline =
"MMDB2")
lvlLines = input.bool(false, "Show Lines ", inline="levels", group = gr_risk)
linesStyle = input.string("SOLID", "", ["SOLID", "DASHED", "DOTTED"],
inline="levels", group = gr_risk)
lvlDistance = input.int(1, "Distance", 1, inline="levels2", group = gr_risk)
lvlDecimals = input.int(2, " Decimals", 1, 8, inline="levels2", group =
gr_risk)
atrRisk = input.int(1, "Risk % ", 1, group = gr_risk , inline="levels3")
atrLen = input.int(14, " ATR Length", 1, group = gr_risk ,
inline="levels3")
decimals = lvlDecimals == 1 ? "#.#" : lvlDecimals == 2 ? "#.##" : lvlDecimals == 3
? "#.###" : lvlDecimals == 4 ? "#.####" : lvlDecimals == 5 ? "#.#####" :
lvlDecimals == 6 ? "#.######" : lvlDecimals == 7 ? "#.#######" : "#.########"
// # ========================================================================= #
// SIGNALS
// # ========================================================================= #
// Signal Generation
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]
// SMA
ocAvg = math.avg(open, close)
sma4 = ta.sma(close, 8)
sma5 = ta.sma(close, 9)
sma9 = ta.sma(close, 13)
psar = ta.sar(0.02, 0.02, 0.2)
buy = bull and showsignal ? label.new(bar_index, y1, sma4 >= sma5 ? "▲ +" : "▲",
xloc.bar_index, yloc.price, bullish, label.style_label_up, color.white,
size.normal) : na
sell = bear and showsignal ? label.new(bar_index, y2, sma4 <= sma5 ? "▼ +" : "▼",
xloc.bar_index, yloc.price, bearish, label.style_label_down, color.white,
size.normal) : na
// # ========================================================================= #
// INDICATOR OVERLAYS
// # ========================================================================= #
// # =============================[CANDLE COLORS]============================= #
// Data reference
[macd, signal, hist] = ta.macd(close, 12, 26, 9)
// Candle Colors
greenHigh = #05df09
greenMidHigh = #05df09
greenMidLow = #388E3C
greenLow = #5f3a97
yellowLow = #5f3a97
redHigh = #ea0402
redMidHigh = #ea0402
redMidLow = #cc0402
redLow = #5f3a97
candleBody = yellowLow
// Ranging trend
if hist > 0
if hist > hist[1] and hist[1] > 0
candleBody := greenLow
if hist < 0
if hist < hist[1] and hist[1] < 0
candleBody := redLow
// Bullish trend
if macd > 0 and hist > 0
candleBody := greenMidLow
// Bearish trend
if macd < 0 and hist < 0
candleBody := redMidLow
// # =============================[WAVE TREND]============================= #
// Get Compponents
wtlength = 20
wma = ta.wma(close, wtlength)
wma1 = ta.wma(close, wtlength)
a = 3 * wma - 2 * wma1
a1 = ta.sma(close, wtlength)
// Functions
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)
// Plot
color1 = color.from_gradient(g, -2, 2, bearish, bullish)
tw1 = plot(shoowtrendwave ? a : na, 'HEMA', color1, 2, editable = false)
tw2 = plot(shoowtrendwave ? a1 : na, 'SMA', color1, 2, editable = false)
fill(tw1, tw2, color = color1)
// # ========================================================================= #
// Support & Resistance
// # ========================================================================= #
history_of_demand_to_keep = 20
show_zigzag = false
show_price_action_labels = false
// Other initializations
avg_volume = ta.sma(volume, 20)
very_weak_multiplier = 0.5
weak_multiplier = 1
strong_multiplier = 1.5
// Rejection handling
var int[] demandRejections = array.new_int(history_of_demand_to_keep, 0)
var int[] supplyRejections = array.new_int(history_of_demand_to_keep, 0)
var int[] demandCreationBars = array.new_int(history_of_demand_to_keep, na)
var int[] supplyCreationBars = array.new_int(history_of_demand_to_keep, na)
f_check_demand_rejections() =>
for i = 0 to history_of_demand_to_keep - 1
if not na(array.get(demandCreationBars, i))
if bar_index - array.get(demandCreationBars, i) > 15 and bar_index -
array.get(demandCreationBars, i) % 15 == 0
label.new(bar_index, high, "Checking demand rejection",
color=color.red)
dBox = array.get(current_demand_box, i)
if (na(dBox))
continue
withinBox = (high >= box.get_bottom(dBox) and high <=
box.get_top(dBox)) or (close >= box.get_bottom(dBox) and close <=
box.get_top(dBox))
bearishCandlesCount = math.sum(close < open ? 1 : 0, 15)
if withinBox and bearishCandlesCount >= 7
label.new(bar_index, low, "Bearish count > 7",
color=color.blue)
array.set(demandRejections, i, array.get(demandRejections, i) +
1)
f_check_supply_rejections() =>
for i = 0 to history_of_demand_to_keep - 1
if not na(array.get(supplyCreationBars, i))
if bar_index - array.get(supplyCreationBars, i) > 15 and bar_index -
array.get(supplyCreationBars, i) % 15 == 0
label.new(bar_index, low, "Checking supply rejection",
color=color.red)
sBox = array.get(current_supply_box, i)
if (na(sBox))
continue
withinBox = (low <= box.get_top(sBox) and low >=
box.get_bottom(sBox)) or (close <= box.get_top(sBox) and close >=
box.get_bottom(sBox))
bullishCandlesCount = math.sum(close > open ? 1 : 0, 15)
if withinBox and bullishCandlesCount >= 7
label.new(bar_index, high, "Bullish count > 7",
color=color.blue)
array.set(supplyRejections, i, array.get(supplyRejections, i) +
1)
f_extend_box_endpoint(box_array) =>
for i = 0 to array.size(box_array) - 1
box.set_right(array.get(box_array, i), bar_index + 30) // Extend only 20
bars
atr567 = ta.atr(50)
swing_high = ta.pivothigh(high, swing_length, swing_length)
swing_low = ta.pivotlow(low, swing_length, swing_length)
var swing_high_values = array.new_float(5,0.00)
var swing_low_values = array.new_float(5,0.00)
var swing_high_bns = array.new_int(5,0)
var swing_low_bns = array.new_int(5,0)
var current_supply_poi = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi = array.new_box(history_of_demand_to_keep, na)
var supply_bos = array.new_box(5, na)
var demand_bos = array.new_box(5, na)
if not na(swing_high)
f_array_add_pop(swing_high_values, swing_high)
f_array_add_pop(swing_high_bns, bar_index[swing_length])
if show_price_action_labels
f_sh_sl_labels(swing_high_values, 1)
f_supply_demand(swing_high_values, swing_high_bns, current_supply_box,
current_supply_poi, 1, atr567)
else if not na(swing_low)
f_array_add_pop(swing_low_values, swing_low)
f_array_add_pop(swing_low_bns, bar_index[swing_length])
if show_price_action_labels
f_sh_sl_labels(swing_low_values, -1)
f_supply_demand(swing_low_values, swing_low_bns, current_demand_box,
current_demand_poi, -1, atr567)
f_sd_to_bos(current_supply_box, supply_bos, current_supply_poi, 1)
f_sd_to_bos(current_demand_box, demand_bos, current_demand_poi, -1)
f_extend_box_endpoint(current_supply_box)
f_extend_box_endpoint(current_demand_box)
// Inside the main execution, after the box is drawn, check for rejections
if not na(swing_low)
f_array_add_pop(swing_low_values, swing_low)
f_array_add_pop(swing_low_bns, bar_index[swing_length])
if show_price_action_labels
f_sh_sl_labels(swing_low_values, -1)
f_supply_demand(swing_low_values, swing_low_bns, current_demand_box,
current_demand_poi, -1, atr567)
f_check_demand_rejections()
if not na(swing_high)
f_array_add_pop(swing_high_values, swing_high)
f_array_add_pop(swing_high_bns, bar_index[swing_length])
if show_price_action_labels
f_sh_sl_labels(swing_high_values, 1)
f_supply_demand(swing_high_values, swing_high_bns, current_supply_box,
current_supply_poi, 1, atr567)
f_check_supply_rejections()
// # ========================================================================= #
// SMC
// # ========================================================================= #
lvl_daily = false, css_d = color.blue, s_d = '⎯⎯⎯'
lvl_weekly = false, css_w = color.blue, s_w = '⎯⎯⎯'
lvl_monthly = false, css_m = color.blue, s_m = '⎯⎯⎯'
lvl_yearly = false, css_y = color.blue, s_y = '⎯⎯⎯'
t = color.t(ob_bull_css)
invcol = color.new(color.white, 100)
// # =============================[BOOLEAN SETUP]============================= #
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
boolean =
array.from(
false
, false
, false
, false
, false
, false
, false
, false
, false
)
/// # =============================[UDT]============================= #
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 Zphl
line top
line bottom
label top_label
label bottom_label
bool stopcross
bool sbottomcross
bool itopcross
bool ibottomcross
string txtup
string txtdn
float topy
float bottomy
float topx
float bottomx
float tup
float tdn
int tupx
int tdnx
float itopy
float itopx
float ibottomy
float ibottomx
float uV
float dV
type FVG
box [] box
line[] ln
bool bull
float top
float btm
int left
int right
type ms
float[] p
int [] n
float[] l
type msDraw
int n
float p
color css
string txt
bool bull
type obC
float[] top
float[] btm
int [] left
float[] avg
float[] dV
float[] cV
int [] wM
int [] blVP
int [] brVP
int [] dir
float[] h
float[] l
int [] n
type obD
box [] ob
box [] eOB
box [] blB
box [] brB
line[] mL
type zone
chart.point points
float p
int c
int t
type hqlzone
box pbx
box ebx
box lbx
label plb
label elb
label lbl
type ehl
float pt
int t
float pb
int b
type pattern
string found = "None"
bool isfound = false
int period = 0
bool bull = false
type alerts
bool chochswing = false
bool chochplusswing = false
bool swingbos = false
bool chochplus = false
bool choch = false
bool bos = false
bool equal = false
bool ob = false
bool swingob = false
bool zone = false
bool fvg = false
bool obtouch = false
// # =============================[GENERAL SETUP]============================= #
bar b = bar.new()
var pattern p = pattern.new()
if p.isfound
p.period += 1
if p.period == 50
p.period := 0
p.found := "None"
p.isfound := false
p.bull := na
switch
if ms_mode == "Dynamic"
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
)
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
"All" => boolean.set(i_BOS, true ), boolean.set(i_CHoCH, true ),
boolean.set(i_CHoCHP, true )
"CHoCH" => boolean.set(i_BOS, false), boolean.set(i_CHoCH, true ),
boolean.set(i_CHoCHP, false)
"CHoCH+" => boolean.set(i_BOS, false), boolean.set(i_CHoCH, false ),
boolean.set(i_CHoCHP, true )
"BOS" => boolean.set(i_BOS, true ), boolean.set(i_CHoCH, false ),
boolean.set(i_CHoCHP, false)
"None" => boolean.set(i_BOS, false), boolean.set(i_CHoCH, false ),
boolean.set(i_CHoCHP, false)
=> na
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 := bullish
blalert.bos := true
if boolean.get(i_BOS) and mtf == false and na(drw)
isdrw := true
drw := msDraw.new(
up.n.first()
, up.p.first()
, bullish
, txt
, true
)
CHoCH =>
isdrw := true
drw := msDraw.new(
up.n.first()
, up.p.first()
, bullish.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
bralert.bos := true
txt := "BOS"
css := bearish
isdrw := true
drw := msDraw.new(
dn.n.first()
, dn.p.first()
, bearish
, txt
, false
)
CHoCH =>
isdrw := true
drw := msDraw.new(
dn.n.first()
, dn.p.first()
, bearish.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
blalert.swingbos := true
txt := "BOS"
icss := bullish
isdrwS := true
drw := msDraw.new(
sup.n.first()
, sup.p.first()
, bullish
, txt
, true
)
CHoCH =>
isdrwS := true
drw := msDraw.new(
sup.n.first()
, sup.p.first()
, bullish.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
bralert.swingbos := true
txt := "BOS"
icss := bearish
isdrwS := true
drw := msDraw.new(
sdn.n.first()
, sdn.p.first()
, bearish
, txt
, false
)
CHoCH =>
isdrwS := true
drw := msDraw.new(
sdn.n.first()
, sdn.p.first()
, bearish.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, 6, 1, 6)
// # =============================[ORDER BLOCKS]============================= #
method eB(box[] b, bool ext, color css, bool swing) =>
b.unshift(
box.new(
na
, na
, na
, na
, xloc = xloc.bar_time
, text_font_family = font.family_monospace
, extend = ext ? extend.right : extend.none
, border_color = swing ? color.new(css, 0) :
color.new(color.white,100)
, bgcolor = css
, border_width = 1
)
)
method drawVOB(bool cdn, bool bull, color css, int loc, bool swing) =>
, [
close
, open
, high
, low
, volume
, lookahead = barmerge.lookahead_off
)
var obC obj = obC.new(
array.new<float>()
, array.new<float>()
, array.new< int >()
, array.new<float>()
, array.new<float>()
, array.new<float>()
, array.new< int >()
, array.new< int >()
, array.new< int >()
, array.new< int >()
, array.new<float>()
, array.new<float>()
, array.new< int >()
)
if barstate.isfirst
for i = 0 to ob_num - 1
draw.mL .eL(false, false, use_grayscale ? color.new(color.gray, 0) :
color.new(css,0))
draw.ob .eB(false, use_grayscale ? color.new(color.gray, 90) : css,
swing)
draw.blB.eB(false, css_metric_up ,
swing)
draw.brB.eB(false, css_metric_dn ,
swing)
draw.eOB.eB(true , use_grayscale ? color.new(color.gray, 90) : css,
swing)
if cdn
obj.h.clear()
obj.l.clear()
obj.n.clear()
obj.h.push(hH[i])
obj.l.push(lL[i])
obj.n.push(b.t[i])
// obj.h.reverse()
// obj.l.reverse()
int iU = obj.l.indexof(obj.l.min()) + 1
int iD = obj.h.indexof(obj.h.max()) + 1
obj.dir.unshift(
bull
? (b.c[iU] > b.o[iU] ? 1 : -1)
: (b.c[iD] > b.o[iD] ? 1 : -1)
)
obj.top.unshift(
bull
? pos[iU]
: obj.h.max()
)
obj.btm.unshift(
bull
? obj.l.min()
: pos[iD]
)
obj.left.unshift(
bull
? obj.n.get(obj.l.indexof(obj.l.min()))
: obj.n.get(obj.h.indexof(obj.h.max()))
)
obj.avg.unshift(
math.avg(obj.top.first(), obj.btm.first())
)
obj.cV.unshift(
bull
? b.v[iU]
: b.v[iD]
)
if ob_pos == "Precise"
switch bull
true =>
if obj.avg.get(0) < (b.c[iU] < b.o[iU] ? b.c[iU] : b.o[iU]) and
obj.top.get(0) > hlcc4[iU]
obj.top.set(0, obj.avg.get(0))
obj.avg.set(0, math.avg(obj.top.first(), obj.btm.first()))
false =>
if obj.avg.get(0) > (b.c[iU] < b.o[iU] ? b.o[iD] : b.c[iD]) and
obj.btm.get(0) < hlcc4[iD]
obj.btm.set(0, obj.avg.get(0))
obj.avg.set(0, math.avg(obj.top.first(), obj.btm.first()))
obj.blVP.unshift ( 0 )
obj.brVP.unshift ( 0 )
obj.wM .unshift ( 1 )
if use_overlap
if obj.avg.size() > 1
if bull
if barstate.isconfirmed
for x = 0 to ob_num - 1
tg = switch ob_mitigation
"Middle" => obj.avg
"Absolute" => bull ? obj.btm : obj.top
for [idx, pt] in tg
if barstate.islast
if obj.avg.size() > 0
// Alert
if bull
? ta.crossunder(low , obj.top.get(0))
: ta.crossover (high, obj.btm.get(0))
switch bull
true => blalert.obtouch := true
false => bralert.obtouch := true
float tV = 0
obj.dV.clear()
seq = math.min(ob_num - 1, obj.avg.size() - 1)
for j = 0 to seq
tV += obj.cV.get(j)
if j == seq
for y = 0 to seq
obj.dV.unshift(
math.floor(
(obj.cV.get(y) / tV) * 100)
)
obj.dV.reverse()
dmL.set_xy1(obj.left.get(i), obj.avg.get(i))
dmL.set_xy2(b.t , obj.avg.get(i))
if ob_metrics_show
rpBL = dblB.get_right()
rpBR = dbrB.get_right()
dbrB.set_right(rpBR + (b.t - b.t[1]) * obj.brVP.get(i))
dblB.set_right(rpBL + (b.t - b.t[1]) * obj.blVP.get(i))
if use_show_metric
txt = switch
deOB.set_text(
str.tostring(
txt + " (" + str.tostring(obj.dV.get(i)) + "%)")
)
deOB.set_text_size (size.auto)
deOB.set_text_halign(text.align_left)
deOB.set_text_color (use_grayscale ? color.silver :
color.new(css, 0))
if obj.wM.size() > 0
for i = 0 to obj.avg.size() - 1
switch obj.dir.get(i)
1 =>
switch obj.wM.get(i)
if iH
hN.pop()
hN.unshift(int(b.n[iLen]))
if iL
lN.pop()
lN.unshift(int(b.n[iLen]))
if sH
hS.pop()
hS.unshift(int(b.n[sLen]))
if sL
lS.pop()
lS.unshift(int(b.n[sLen]))
if ob_show
if ob_swings
if bull_ob
blalert.ob := true
if bear_ob
bralert.ob := true
if s_bull_ob
blalert.swingob := true
if s_bear_ob
blalert.swingob := true
// # ========================================================================= #
// DASHBOARD
// # ========================================================================= #
// Optimal Sensivity
// Volume Function
vollength = 20
buyThreshold = 0.7
sellThreshold = -0.7
// Volatility Function
volatilength = 20
lowVolatilityThreshold = 0.5
highVolatilityThreshold = 1.5
// Drawing Dashboard
var table_position = dashLoc == 'Bottom Left' ? position.bottom_left
: dashLoc == 'Top Right' ? position.top_right
: position.bottom_right
if showDash
if barstate.isfirst
tb.cell(0, 0, "Pieki Dashboard", text_color = color.white, text_size =
table_size)
tb.merge_cells(0,0,1,0)
if barstate.islast
tb.cell(0, 3, str.tostring(trendIndication) + "Trend Strenght", text_color
= color.white, text_size = table_size, text_halign = text.align_left)
tb.cell(0, 4, "💠 Volume", text_color = color.white, text_size = table_size,
text_halign = text.align_left)
tb.cell(0, 5, str.tostring(volatilityIndication) + " Volatility",
text_color = color.white, text_size = table_size, text_halign = text.align_left)
tb.cell(0, 6, str.tostring(trendemote) + " Trend", text_color =
color.white, text_size = table_size, text_halign = text.align_left)
tb.cell(1, 3, str.tostring(trendStrengthPercentage, format.percent),
text_color=textColorstrength, text_size=table_size)
tb.cell(1, 4, str.tostring(volumeSentiment, format.percent), text_color =
textcolorvolu, text_size = table_size)
tb.cell(1, 5, str.tostring(volatilityPercentage, format.percent),
text_color=volatilitycolor, text_size=table_size)
tb.cell(1, 6, str.tostring(trendtext), text_color = textColorstrength,
text_size = table_size)
// # ========================================================================= #
// Risk Managment
// # ========================================================================= #
trigger2 = 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, stop_style, label.style_label_left, color.white,
size.normal) : na
label.set_x(stop, label.get_x(stop) + math.round(ta.change(time) * lvlDistance))
label.set_y(stop, stop_y)
label.delete(stop[1])