PROTECTED SOURCE SCRIPT
CandelaCharts - Liquidity Key Zones (LKZ)

// This source code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0/
// © CandelaCharts
//version=6
indicator("CandelaCharts - Liquidity Key Zones (LKZ)", shorttitle = "CandelaCharts - Liquidity Key Zones (LKZ)", overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count = 500, max_bars_back = 500, max_polylines_count = 100)
// # ========================================================================= #
// # | Colors |
// # ========================================================================= #
//#region
// # Core -------------------------------------------------------------------- #
colors_orange = color.orange
colors_blue = color.blue
colors_aqua = color.aqua
colors_red = color.red
colors_green = color.green
colors_maroon = color.maroon
colors_purple = color.purple
colors_gray = color.gray
colors_transparent = color.new(color.white,100)
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Inputs |
// # ========================================================================= #
//#region
// # General ----------------------------------------------------------------- #
general_font = input.string("Monospace", "Text ", options = ["Default", "Monospace"], inline = "5", group = "General")
general_text = input.string("Tiny", "", options = ["Tiny", "Small", "Normal", "Large", "Huge", "Auto"], inline = "5", group = "General", tooltip = "Customize global text size and style")
general_brand_show = input.bool(false, "Hide Brand", group = "General")
// # LKZ --------------------------------------------------------------------- #
hl_daily = input.bool(true, "Day ", inline = "1", group = "HTF Levels")
hl_weekly = input.bool(false, "Week ", inline = "2", group = "HTF Levels")
hl_monthly = input.bool(false, "Month ", inline = "3", group = "HTF Levels")
hl_quartely = input.bool(false, "Quarter ", inline = "4", group = "HTF Levels")
hl_yearly = input.bool(false, "Year ", inline = "5", group = "HTF Levels")
hl_css_daily = input.color(colors_blue, "", inline = "1", group = "HTF Levels")
hl_css_weekly = input.color(colors_green, "", inline = "2", group = "HTF Levels")
hl_css_monthly = input.color(colors_purple, "", inline = "3", group = "HTF Levels")
hl_css_quaterly = input.color(colors_maroon, "", inline = "4", group = "HTF Levels")
hl_css_yearly = input.color(colors_gray, "", inline = "5", group = "HTF Levels")
hl_line_daily = input.string('⎯⎯⎯', '', inline = '1', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_weekly = input.string('⎯⎯⎯', '', inline = '2', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_monthly = input.string('⎯⎯⎯', '', inline = '3', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_quaterly = input.string('⎯⎯⎯', '', inline = '4', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_yearly = input.string('⎯⎯⎯', '', inline = '5', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_width_daily = input.int(1, '', inline = '1', group = "HTF Levels", minval = 1, maxval = 5)
hl_line_width_weekly = input.int(1, '', inline = '2', group = "HTF Levels", minval = 1, maxval = 5)
hl_line_width_monthly = input.int(1, '', inline = '3', group = "HTF Levels", minval = 1, maxval = 5)
hl_line_width_quaterly = input.int(1, '', inline = '4', group = "HTF Levels", minval = 1, maxval = 5)
hl_line_width_yearly = input.int(1, '', inline = '5', group = "HTF Levels", minval = 1, maxval = 5)
hl_midline = input.bool(true, "Show Average ", inline = "6" , group = "HTF Levels")
hl_midline_css = input.color(colors_aqua, "", inline = "6", group = "HTF Levels")
hl_midline_type = input.string("----", "", inline = "6", group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'], tooltip = "Show highs & lows mid-line")
hl_midline_width = input.int(1, "", inline = "6", group = "HTF Levels", tooltip = "Change mid-line highs & lows width")
hl_openline = input.bool(true, "Show Open ", inline = "7" , group = "HTF Levels")
hl_openline_css = input.color(colors_orange, "", inline = "7", group = "HTF Levels")
hl_openline_type = input.string("····", "", inline = "7", group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'], tooltip = "Show highs & lows mid-line")
hl_openline_width = input.int(1, "", inline = "7", group = "HTF Levels", tooltip = "Change mid-line highs & lows width")
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | UDTs |
// # ========================================================================= #
//#region
type UDT_Store
line [] hl_ln
label [] hl_lbl
type UDT_MTF
int x1 = na
int x2 = na
float y1 = na
float y2 = na
type UDT_HTF_Candle
string tf
// real coordinates of HTF candle
float o
float c
float h
float l
int ot
int ct
int ht
int lt
bool bull
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Functions |
// # ========================================================================= #
//#region
method text_size(string size) =>
out = switch size
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
"Huge" => size.huge
"Auto" => size.auto
out
method line_style(string line) =>
out = switch line
'⎯⎯⎯' => line.style_solid
'----' => line.style_dashed
'····' => line.style_dotted
method font_style(string font) =>
out = switch font
'Default' => font.family_default
'Monospace' => font.family_monospace
shift_to_right(int current, int length, string tf) =>
current + timeframe.in_seconds(tf) * 1000 * (length + 1)
shift_to_left(int current, int prev, int length) =>
current - (current - prev) * length + 1
shift_bars_to_right(int bars) =>
bars + 20
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Store |
// # ========================================================================= #
//#region
var UDT_Store bin = UDT_Store.new(hl_ln = array.new<line>(), hl_lbl = array.new<label>())
method clean_hl(UDT_Store store) =>
for obj in store.hl_ln
obj.delete()
for obj in store.hl_lbl
obj.delete()
store.hl_ln.clear()
store.hl_lbl.clear()
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Highs & Lows MTF |
// # ========================================================================= #
//#region
method draw_pivots_ol_line(UDT_MTF mtf) =>
ol = line.new(
x1 = mtf.x1
, y1 = mtf.y1
, x2 = mtf.x2
, y2 = mtf.y2
, xloc = xloc.bar_time
, color = hl_openline_css
, style = line_style(hl_openline_type)
, width = hl_openline_width
)
bin.hl_ln.push(ol)
mtf
method draw_pivots_hl_line(UDT_MTF mtf, color css, string pdhl_style, int line_width) =>
hl = line.new(
x1 = mtf.x1
, y1 = mtf.y1
, x2 = mtf.x2
, y2 = mtf.y2
, xloc = xloc.bar_time
, color = css
, style = line_style(pdhl_style)
, width = line_width
)
bin.hl_ln.push(hl)
mtf
method draw_pivots_mid_line(UDT_MTF mtf) =>
ml = line.new(
x1 = mtf.x1
, y1 = mtf.y1
, x2 = mtf.x2
, y2 = mtf.y2
, xloc = xloc.bar_time
, color = hl_midline_css
, style = line_style(hl_midline_type)
, width = hl_midline_width
)
bin.hl_ln.push(ml)
mtf
method draw_pivots_ll_line(UDT_MTF mtf, color css, string pdhl_style, int line_width) =>
ll = line.new(
x1 = mtf.x1
, y1 = mtf.y1
, x2 = mtf.x2
, y2 = mtf.y2
, xloc = xloc.bar_time
, color = css
, style = line_style(pdhl_style)
, width = line_width
)
bin.hl_ln.push(ll)
mtf
method draw_pivots_label(UDT_MTF mtf, string fmt, string tf, color css) =>
lbl = label.new(
x = mtf.x2
, y = mtf.y2
, xloc = xloc.bar_time
, text = str.format(fmt, tf)
, color = colors_transparent
, textcolor = css
, size = text_size(general_text)
, style = label.style_label_left
, text_font_family = font_style(general_font)
)
bin.hl_lbl.push(lbl)
mtf
method mtf_pivots(UDT_HTF_Candle candle, tf, css, pdhl_style, line_width) =>
h_mtf = UDT_MTF.new(x1 = candle.ht, x2 = candle.ct, y1 = candle.h, y2 = candle.h)
l_mtf = UDT_MTF.new(x1 = candle.lt, x2 = candle.ct, y1 = candle.l, y2 = candle.l)
// validate high/low detections, if no candle is detected on the levels, set x1 to open
if na(h_mtf.x1)
h_mtf.x1 := candle.ot
if na(l_mtf.x1)
l_mtf.x1 := candle.ot
// position
extension = shift_to_right(time, 10, timeframe.period)
h_mtf.x2 := extension
l_mtf.x2 := extension
// Draw high line
h_mtf.draw_pivots_hl_line(css, pdhl_style, line_width)
.draw_pivots_label('P{0}H', tf, css)
// Draw low line
l_mtf.draw_pivots_ll_line(css, pdhl_style, line_width)
.draw_pivots_label('P{0}L', tf, css)
if hl_openline
o_mtf = UDT_MTF.new(x1 = candle.ot, x2 = candle.ct, y1 = candle.o, y2 = candle.o)
o_mtf.x2 := extension
// Draw open line
o_mtf.draw_pivots_ol_line()
.draw_pivots_label('P{0}O', tf, hl_openline_css)
if hl_midline
m_mtf = UDT_MTF.new()
midline_y = (h_mtf.y1 + l_mtf.y1) / 2
m_mtf.x1 := candle.ot
m_mtf.x2 := extension
m_mtf.y1 := midline_y
m_mtf.y2 := midline_y
// Draw midline
m_mtf.draw_pivots_mid_line()
.draw_pivots_label('P{0}A', tf, hl_midline_css)
candle
method session_begins(string tf, string ses, string tz) =>
ta.change(time(tf, ses, na(tz) ? "" : tz))!= 0
session_begins_2(string tf, string ses, string tz) =>
t = time(tf, ses, na(tz) ? "" : tz)
ct = time_close(tf, ses, na(tz) ? "" : tz)
not na(t) and not na(ct) and (na(t[1]) or t > t[1])
method in_session(string tf, string ses, string tz) =>
t = time(tf, ses, na(tz) ? "" : tz)
ct = time_close(tf, ses, na(tz) ? "" : tz)
not na(t) and not na(ct)
is_bullish_candle(float c, float o, float h, float l) =>
// Doji candle
if c == o
math.abs(o - h) < math.abs(o - l)
else
c > o
method detect_htf_candle(array<UDT_HTF_Candle> candles, string tf, int buffer) =>
if session_begins(tf, "", na)or candles.size()==0
// log.info("session begins " + " open=" + str.format_time(time, "yyyy-MM-dd HH:mm"))
candle = UDT_HTF_Candle.new(tf = 'D')
candle.o := open
candle.c := close
candle.h := high
candle.l := low
candle.ot := time
candle.ct := time
candle.ht := time
candle.lt := time
candle.bull := is_bullish_candle(candle.c, candle.o, candle.h, candle.l)
if candles.size() >= buffer
candles.pop()
candles.unshift(candle)
else if in_session(tf, "", na) and candles.size()>0
candle = candles.first()
candle.c := close
candle.ct := time
if high > candle.h
candle.h := high
candle.ht := time
// log.info("h=" + str.tostring(high) + " l=" + str.tostring(low) + " o=" + str.tostring(open) + " c=" + str.tostring(close))
if low < candle.l
candle.l := low
candle.lt := time
// log.info("h=" + str.tostring(high) + " l=" + str.tostring(low) + " o=" + str.tostring(open) + " c=" + str.tostring(close))
candle.bull := is_bullish_candle(candle.c, candle.o, candle.h, candle.l)
// log.info("in session " + " time=" + str.format_time(time, "yyyy-MM-dd HH:mm") + " o=" + str.tostring(candle.o) + " c=" + str.tostring(candle.c))
candles
bin.clean_hl()
const int buffer = 2
if hl_daily
var htf_daily_candles = array.new<UDT_HTF_Candle>()
htf_daily_candles.detect_htf_candle('D', buffer)
if htf_daily_candles.size() == buffer
prev_day = htf_daily_candles.get(1)
prev_day.mtf_pivots('D', hl_css_daily, hl_line_daily, hl_line_width_daily)
if hl_weekly
var htf_weekly_candles = array.new<UDT_HTF_Candle>()
htf_weekly_candles.detect_htf_candle('W', buffer)
if htf_weekly_candles.size() == buffer and barstate.islast
prev_week = htf_weekly_candles.get(1)
prev_week.mtf_pivots('W', hl_css_weekly, hl_line_weekly, hl_line_width_weekly)
if hl_monthly
var htf_monthly_candles = array.new<UDT_HTF_Candle>()
htf_monthly_candles.detect_htf_candle('M', buffer)
if htf_monthly_candles.size() == buffer and barstate.islast
prev_month = htf_monthly_candles.get(1)
prev_month.mtf_pivots('M', hl_css_monthly, hl_line_monthly, hl_line_width_monthly)
if hl_quartely
var htf_quartely_candles = array.new<UDT_HTF_Candle>()
htf_quartely_candles.detect_htf_candle('3M', buffer)
if htf_quartely_candles.size() == buffer and barstate.islast
prev_quarter = htf_quartely_candles.get(1)
prev_quarter.mtf_pivots('3M', hl_css_quaterly, hl_line_quaterly, hl_line_width_quaterly)
if hl_yearly
var htf_yearly_candles = array.new<UDT_HTF_Candle>()
htf_yearly_candles.detect_htf_candle('12M', buffer)
if htf_yearly_candles.size() == buffer and barstate.islast
prev_year = htf_yearly_candles.get(1)
prev_year.mtf_pivots('12M', hl_css_yearly, hl_line_yearly, hl_line_width_yearly)
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Brand |
// # ========================================================================= #
//#region
if barstate.isfirst and general_brand_show == false
var table brand = table.new(position.bottom_right, 1, 1, bgcolor = chart.bg_color)
table.cell(brand, 0, 0, "© CandelaCharts", text_color = colors_gray, text_halign = text.align_center, text_size = text_size(general_text), text_font_family = font_style(general_font))
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// Constants
color CLEAR = color.rgb(0,0,0,100)
eq_threshold = input.float(0.3, '', minval = 0, maxval = 0.5, step = 0.1, group = 'Market Structure',inline = 'equilibrium_zone')
showSwing = input.bool(false, 'Swing Points', group="Market Structure",inline="3")
swingSize_swing = input.int(10, "Swing Point Period",inline="4", group="Market Structure")
label_sizes_s =input.string("Medium", options=["Small", "Medium","Large"], title="Label Size",inline="4", group="Market Structure")
label_size_buysell_s = label_sizes_s == "Small" ? size.tiny : label_sizes_s == "Medium" ? size.small : label_sizes_s == "Large" ? size.normal : label_sizes_s == "Medium2" ? size.normal : label_sizes_s == "Large2" ? size.large : size.huge
label_size_buysell = label_sizes_s == "Small" ? size.tiny : label_sizes_s == "Medium" ? size.small : label_sizes_s == "Large" ? size.normal : label_sizes_s == "Medium2" ? size.normal : label_sizes_s == "Large2" ? size.large : size.huge
swingColor = input.color(#787b86 , '', group="Market Structure",inline="3")
swingSize = 3
length_eqh = 3
//----------------------------------------}
//Key Levels
//----------------------------------------{
var Show_4H_Levels = input.bool(defval=false, title='4H', group='Key Levels', inline='4H')
Color_4H_Levels = input.color(title='', defval=color.orange, group='Key Levels', inline='4H')
Style_4H_Levels = input.string('Dotted', ' Style', ['Solid', 'Dashed', 'Dotted'], group="Key Levels",inline="4H")
Text_4H_Levels = input.bool(defval=false, title='Shorten', group='Key Levels', inline='4H')
labelsize = input.string(defval='Medium', title='Text Size', options=['Small', 'Medium', 'Large'],group = "Key Levels", inline='H')
displayStyle = 'Standard'
distanceright = 25
radistance = 250
linesize = 'Small'
linestyle = 'Solid'
var untested_monday = false
bosConfType = 'Candle High'//input.string('Candle Close', 'BOS Confirmation', ['Candle Close', 'Wicks'], tooltip='Choose whether candle close/wick above previous swing point counts as a BOS.')
MSS = true//input.bool(false, 'Show MSS', tooltip='Renames the first counter t_MS BOS to MSS' )
// showSwing = false//input.bool(true, 'Show Swing Points', tooltip='Show or hide HH, LH, HL, LL')
// Functions
lineStyle(x) =>
switch x
'Solid' => line.style_solid
'Dashed' => line.style_dashed
'Dotted' => line.style_dotted
pivot_high_found = ta.pivothigh(high, swingSize_swing, swingSize_swing)
pivot_low_found = ta.pivotlow(low, swingSize_swing, swingSize_swing)
var float prevHigh_s = na,var float prevLow_s = na,var int prevHighIndex_s = na,var int prevLowIndex_s = na
bool higher_highs = false, bool lower_highs = false, bool higher_lows = false, bool lower_lows = false
var int prevSwing_s = 0
if not na(pivot_high_found)
if pivot_high_found >= prevHigh_s
higher_highs := true
prevSwing_s := 2
else
lower_highs := true
prevSwing_s := 1
prevHigh_s := pivot_high_found
prevHighIndex_s := bar_index - swingSize_swing
if not na(pivot_low_found)
if pivot_low_found >= prevLow_s
higher_lows := true
prevSwing_s := -1
else
lower_lows := true
prevSwing_s := -2
prevLow_s := pivot_low_found
prevLowIndex_s := bar_index - swingSize_swing
// ———————————————————— Global data {
//Using current bar data for HTF highs and lows instead of security to prevent future leaking
var htfH = open
var htfL = open
if close > htfH
htfH:= close
if close < htfL
htfL := close
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Key Levels
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var monday_time = time
var monday_high = high
var monday_low = low
[weekly_time, weekly_open] = request.security(syminfo.tickerid, 'W', [time, open], lookahead=barmerge.lookahead_on)
[weeklyh_time, weeklyh_open] = request.security(syminfo.tickerid, 'W', [time[1], high[1]], lookahead=barmerge.lookahead_on)
[weeklyl_time, weeklyl_open] = request.security(syminfo.tickerid, 'W', [time[1], low[1]], lookahead=barmerge.lookahead_on)
[monthly_time, monthly_open] = request.security(syminfo.tickerid, 'M', [time, open], lookahead=barmerge.lookahead_on)
[monthlyh_time, monthlyh_open] = request.security(syminfo.tickerid, 'M', [time[1], high[1]], lookahead=barmerge.lookahead_on)
[monthlyl_time, monthlyl_open] = request.security(syminfo.tickerid, 'M', [time[1], low[1]], lookahead=barmerge.lookahead_on)
[intrah_time, intrah_open] = request.security(syminfo.tickerid, '240', [time[1], high[1]], lookahead=barmerge.lookahead_on)
[intral_time, intral_open] = request.security(syminfo.tickerid, '240', [time[1], low[1]], lookahead=barmerge.lookahead_on)
[quarterly_time, quarterly_open] = request.security(syminfo.tickerid, '3M', [time, open], lookahead=barmerge.lookahead_on)
[quarterlyh_time, quarterlyh_open] = request.security(syminfo.tickerid, '3M', [time[1], high[1]], lookahead=barmerge.lookahead_on)
[quarterlyl_time, quarterlyl_open] = request.security(syminfo.tickerid, '3M', [time[1], low[1]], lookahead=barmerge.lookahead_on)
[yearlyh_time, yearlyh_open] = request.security(syminfo.tickerid, '12M', [time, high], lookahead=barmerge.lookahead_on)
[yearlyl_time, yearlyl_open] = request.security(syminfo.tickerid, '12M', [time, low], lookahead=barmerge.lookahead_on)
if weekly_time != weekly_time[1]
untested_monday := false
untested_monday
untested_monday := true
monday_low
linewidthint = 1
if linesize == 'Small'
linewidthint := 1
linewidthint
if linesize == 'Medium'
linewidthint := 2
linewidthint
if linesize == 'Large'
linewidthint := 3
linewidthint
var linewidth_def = linewidthint
fontsize = size.small
if labelsize == 'Small'
fontsize := size.small
fontsize
if labelsize == 'Medium'
fontsize := size.normal
fontsize
if labelsize == 'Large'
fontsize := size.large
fontsize
linestyles = line.style_solid
if linestyle == 'Dashed'
linestyles := line.style_dashed
linestyles
if linestyle == 'Dotted'
linestyles := line.style_dotted
linestyles
var DEFAULT_LABEL_SIZE = fontsize
var DEFAULT_LABEL_STYLE = label.style_none
var Rigth_Def = distanceright
var arr_price = array.new_float(0)
var arr_label = array.new_label(0)
Combine_Levels(arr_price, arr_label, currentprice, currentlabel, currentcolor) =>
if array.includes(arr_price, currentprice)
whichindex = array.indexof(arr_price, currentprice)
labelhold = array.get(arr_label, whichindex)
whichtext = label.get_text(labelhold)
label.set_text(labelhold, label.get_text(currentlabel) + ' / ' + whichtext)
label.set_text(currentlabel, '')
label.set_textcolor(labelhold, currentcolor)
else
array.push(arr_price, currentprice)
array.push(arr_label, currentlabel)
extend_to_current(bars) =>
timenow + (time - time[1]) * bars
if barstate.islast
arr_price := array.new_float(0)
arr_label := array.new_label(0)
if Show_4H_Levels
limit_4H_right = extend_to_current(Rigth_Def)
intrah_limit_right = extend_to_current(Rigth_Def)
intral_limit_right = extend_to_current(Rigth_Def)
var intrah_line = line.new(x1=intrah_time, x2=intrah_limit_right, y1=intrah_open, y2=intrah_open, color=Color_4H_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_4H_Levels))
var intral_line = line.new(x1=intral_time, x2=intral_limit_right, y1=intral_open, y2=intral_open, color=Color_4H_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_4H_Levels))
line.set_xy1(intrah_line,intrah_time,intrah_open)
line.set_xy2(intrah_line,intrah_limit_right,intrah_open)
line.set_x1(intral_line, intral_time)
line.set_x2(intral_line, intral_limit_right)
line.set_y1(intral_line, intral_open)
line.set_y2(intral_line, intral_open)
daily_limit_right = extend_to_current(Rigth_Def)
dailyh_limit_right = extend_to_current(Rigth_Def)
dailyl_limit_right = extend_to_current(Rigth_Def)
type Candle
float o
float c
float h
float l
int o_idx
int c_idx
int h_idx
int l_idx
box body
line wick_up
line wick_down
type Imbalance
box b
int idx
type CandleSettings
bool show
string htf
int max_display
type Settings
int max_sets
color bull_body
color bull_border
color bull_wick
color bear_body
color bear_border
color bear_wick
int offset
int buffer
int htf_buffer
int width
bool trace_show
color trace_o_color
string trace_o_style
int trace_o_size
color trace_c_color
string trace_c_style
int trace_c_size
color trace_h_color
string trace_h_style
int trace_h_size
color trace_l_color
string trace_l_style
int trace_l_size
string trace_anchor
bool label_show
color label_color
string label_size
bool htf_label_show
color htf_label_color
string htf_label_size
bool htf_timer_show
color htf_timer_color
string htf_timer_size
type CandleSet
Candle[] candles
Imbalance[] imbalances
CandleSettings settings
label tfName
label tfTimer
type Helper
string name = "Helper"
Settings settings = Settings.new()
var CandleSettings SettingsHTF1 = CandleSettings.new()
var CandleSettings SettingsHTF2 = CandleSettings.new()
var CandleSettings SettingsHTF3 = CandleSettings.new()
var Candle[] candles_1 = array.new<Candle>(0)
var Candle[] candles_2 = array.new<Candle>(0)
var Candle[] candles_3 = array.new<Candle>(0)
var CandleSet htf1 = CandleSet.new()
htf1.settings := SettingsHTF1
htf1.candles := candles_1
var CandleSet htf2 = CandleSet.new()
htf2.settings := SettingsHTF2
htf2.candles := candles_2
var CandleSet htf3 = CandleSet.new()
htf3.settings := SettingsHTF3
htf3.candles := candles_3
//+------------------------------------------------------------------------------------------------------------+//
//+--- Settings ---+//
//+------------------------------------------------------------------------------------------------------------+//
htf1.settings.show := input.bool(true, "HTF 1 ", inline="htf1")
htf_1 = input.timeframe("15", "", inline="htf1")
htf1.settings.htf := htf_1
htf1.settings.max_display := input.int(4, "", inline="htf1")
htf2.settings.show := input.bool(true, "HTF 2 ", inline="htf2")
htf_2 = input.timeframe("60", "", inline="htf2")
htf2.settings.htf := htf_2
htf2.settings.max_display := input.int(4, "", inline="htf2")
htf3.settings.show := input.bool(true, "HTF 3 ", inline="htf3")
htf_3 = input.timeframe("1D", "", inline="htf3")
htf3.settings.htf := htf_3
htf3.settings.max_display := input.int(4, "", inline="htf3")
settings.max_sets := input.int(6, "Limit to next HTFs only", minval=1, maxval=6)
settings.bull_body := input.color(color.new(#39d23e, 3), "Body ", inline="body")
settings.bear_body := input.color(color.new(#ec0d0d, 4), "", inline="body")
settings.bull_border := input.color(color.rgb(206, 216, 216), "Borders", inline="borders")
settings.bear_border := input.color(color.new(#e5e9ea, 0), "", inline="borders")
settings.bull_wick := input.color(color.new(#e9eeee, 10), "Wick ", inline="wick")
settings.bear_wick := input.color(#f7f9f9, "", inline="wick")
settings.offset := input.int(25, "padding from current candles", minval = 1)
settings.buffer := input.int(1, "space between candles", minval = 1, maxval = 4)
settings.htf_buffer := input.int(10, "space between Higher Timeframes", minval = 1, maxval = 10)
settings.width := input.int(1, "Candle Width", minval = 1, maxval = 4)*2
settings.htf_label_show := input.bool(true, "HTF Label ", inline="HTFlabel")
settings.htf_label_color := input.color(color.new(#e6eef0, 10), "", inline='HTFlabel')
settings.htf_label_size := input.string(size.large, "", [size.tiny, size.small, size.normal, size.large, size.huge], inline="HTFlabel")
// ---------------- إعدادات ----------------
atrPeriod = input.int(10, "ATR Period", minval=1)
factor = input.float(3.0, "Supertrend Multiplier", minval=0.1, step=0.1)
rsiLength = input.int(14, "RSI Length", minval=2)
macdFast = input.int(12, "MACD Fast Length", minval=1)
macdSlow = input.int(26, "MACD Slow Length", minval=1)
macdSig = input.int(9, "MACD Signal Length", minval=1)
emaLen1 = input.int(20, "EMA 20 Length")
emaLen2 = input.int(50, "EMA 50 Length")
tablePos = input.string("top_right", "Table Position",
options=["top_left","top_right","bottom_left","bottom_right"])
// ---------------- Supertrend ----------------
atr = ta.atr(atrPeriod)
upperBand = hl2 - factor * atr
lowerBand = hl2 + factor * atr
var float trend = na
if (close > nz(trend[1], hl2))
trend := math.max(upperBand, nz(trend[1], upperBand))
else
trend := math.min(lowerBand, nz(trend[1], lowerBand))
bull = close > trend
bear = close < trend
buySignal = ta.crossover(close, trend)
sellSignal = ta.crossunder(close, trend)
// ---------------- EMA ----------------
ema20 = ta.ema(close, emaLen1)
ema50 = ta.ema(close, emaLen2)
emaBull = ema20 > ema50
emaBear = ema20 < ema50
// ---------------- RSI ----------------
rsi = ta.rsi(close, rsiLength)
rsiBull = rsi > 50
// ---------------- MACD ----------------
macd = ta.ema(close, macdFast) - ta.ema(close, macdSlow)
signal = ta.ema(macd, macdSig)
macdBull = macd > signal
// ---------------- VWAP ----------------
vwapValue = ta.vwap(close)
vwapBull = close > vwapValue
vwapBear = close < vwapValue
// ---------------- Dashboard ----------------
// نحتاج 8 صفوف: (العنوان + Supertrend + EMA + RSI + MACD + VWAP + FINAL + السعر الحالي)
var table dash = table.new(position=tablePos, columns=2, rows=8, border_width=1)
if barstate.islast
// العناوين
table.cell(dash, 0, 0, "Indicator", text_color=color.white, bgcolor=color.blue)
table.cell(dash, 1, 0, "Signal", text_color=color.white, bgcolor=color.blue)
// Supertrend
table.cell(dash, 0, 1, "Supertrend", text_color=color.white, bgcolor=color.rgb(79, 97, 148))
table.cell(dash, 1, 1, buySignal ? "كول ✅" : sellSignal ? "انعكاس المسار ❌" : bull ? "كول" : "بوت",
text_color=color.white,
bgcolor= buySignal ? color.green : sellSignal ? color.red : bull ? color.green : color.red)
// EMA
table.cell(dash, 0, 2, "EMA 20/50", text_color=color.white, bgcolor=color.rgb(71, 91, 144))
table.cell(dash, 1, 2, emaBull ? "كول" : "بوت",
text_color=color.white, bgcolor=emaBull ? color.green : color.red)
// RSI
table.cell(dash, 0, 3, "RSI", text_color=color.white, bgcolor=color.rgb(66, 85, 139))
table.cell(dash, 1, 3, rsiBull ? "كول" : "بوت",
text_color=color.white, bgcolor=rsiBull ? color.green : color.red)
// MACD
table.cell(dash, 0, 4, "MACD", text_color=color.white, bgcolor=color.rgb(94, 111, 159))
table.cell(dash, 1, 4, macdBull ? "كول" : "بوت",
text_color=color.white, bgcolor=macdBull ? color.green : color.red)
// VWAP
table.cell(dash, 0, 5, "VWAP", text_color=color.white, bgcolor=color.rgb(89, 106, 153))
table.cell(dash, 1, 5, vwapBull ? "كول" : "بوت",
text_color=color.white, bgcolor=vwapBull ? color.green : color.red)
// السعر الحالي
table.cell(dash, 0, 7, "السعر", text_color=color.white, bgcolor=color.rgb(78, 89, 121))
table.cell(dash, 1, 7, str.tostring(close, format.mintick),
text_color=color.white, bgcolor=color.gray)
// © CandelaCharts
//version=6
indicator("CandelaCharts - Liquidity Key Zones (LKZ)", shorttitle = "CandelaCharts - Liquidity Key Zones (LKZ)", overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count = 500, max_bars_back = 500, max_polylines_count = 100)
// # ========================================================================= #
// # | Colors |
// # ========================================================================= #
//#region
// # Core -------------------------------------------------------------------- #
colors_orange = color.orange
colors_blue = color.blue
colors_aqua = color.aqua
colors_red = color.red
colors_green = color.green
colors_maroon = color.maroon
colors_purple = color.purple
colors_gray = color.gray
colors_transparent = color.new(color.white,100)
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Inputs |
// # ========================================================================= #
//#region
// # General ----------------------------------------------------------------- #
general_font = input.string("Monospace", "Text ", options = ["Default", "Monospace"], inline = "5", group = "General")
general_text = input.string("Tiny", "", options = ["Tiny", "Small", "Normal", "Large", "Huge", "Auto"], inline = "5", group = "General", tooltip = "Customize global text size and style")
general_brand_show = input.bool(false, "Hide Brand", group = "General")
// # LKZ --------------------------------------------------------------------- #
hl_daily = input.bool(true, "Day ", inline = "1", group = "HTF Levels")
hl_weekly = input.bool(false, "Week ", inline = "2", group = "HTF Levels")
hl_monthly = input.bool(false, "Month ", inline = "3", group = "HTF Levels")
hl_quartely = input.bool(false, "Quarter ", inline = "4", group = "HTF Levels")
hl_yearly = input.bool(false, "Year ", inline = "5", group = "HTF Levels")
hl_css_daily = input.color(colors_blue, "", inline = "1", group = "HTF Levels")
hl_css_weekly = input.color(colors_green, "", inline = "2", group = "HTF Levels")
hl_css_monthly = input.color(colors_purple, "", inline = "3", group = "HTF Levels")
hl_css_quaterly = input.color(colors_maroon, "", inline = "4", group = "HTF Levels")
hl_css_yearly = input.color(colors_gray, "", inline = "5", group = "HTF Levels")
hl_line_daily = input.string('⎯⎯⎯', '', inline = '1', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_weekly = input.string('⎯⎯⎯', '', inline = '2', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_monthly = input.string('⎯⎯⎯', '', inline = '3', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_quaterly = input.string('⎯⎯⎯', '', inline = '4', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_yearly = input.string('⎯⎯⎯', '', inline = '5', group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'])
hl_line_width_daily = input.int(1, '', inline = '1', group = "HTF Levels", minval = 1, maxval = 5)
hl_line_width_weekly = input.int(1, '', inline = '2', group = "HTF Levels", minval = 1, maxval = 5)
hl_line_width_monthly = input.int(1, '', inline = '3', group = "HTF Levels", minval = 1, maxval = 5)
hl_line_width_quaterly = input.int(1, '', inline = '4', group = "HTF Levels", minval = 1, maxval = 5)
hl_line_width_yearly = input.int(1, '', inline = '5', group = "HTF Levels", minval = 1, maxval = 5)
hl_midline = input.bool(true, "Show Average ", inline = "6" , group = "HTF Levels")
hl_midline_css = input.color(colors_aqua, "", inline = "6", group = "HTF Levels")
hl_midline_type = input.string("----", "", inline = "6", group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'], tooltip = "Show highs & lows mid-line")
hl_midline_width = input.int(1, "", inline = "6", group = "HTF Levels", tooltip = "Change mid-line highs & lows width")
hl_openline = input.bool(true, "Show Open ", inline = "7" , group = "HTF Levels")
hl_openline_css = input.color(colors_orange, "", inline = "7", group = "HTF Levels")
hl_openline_type = input.string("····", "", inline = "7", group = "HTF Levels", options = ['⎯⎯⎯', '----', '····'], tooltip = "Show highs & lows mid-line")
hl_openline_width = input.int(1, "", inline = "7", group = "HTF Levels", tooltip = "Change mid-line highs & lows width")
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | UDTs |
// # ========================================================================= #
//#region
type UDT_Store
line [] hl_ln
label [] hl_lbl
type UDT_MTF
int x1 = na
int x2 = na
float y1 = na
float y2 = na
type UDT_HTF_Candle
string tf
// real coordinates of HTF candle
float o
float c
float h
float l
int ot
int ct
int ht
int lt
bool bull
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Functions |
// # ========================================================================= #
//#region
method text_size(string size) =>
out = switch size
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
"Huge" => size.huge
"Auto" => size.auto
out
method line_style(string line) =>
out = switch line
'⎯⎯⎯' => line.style_solid
'----' => line.style_dashed
'····' => line.style_dotted
method font_style(string font) =>
out = switch font
'Default' => font.family_default
'Monospace' => font.family_monospace
shift_to_right(int current, int length, string tf) =>
current + timeframe.in_seconds(tf) * 1000 * (length + 1)
shift_to_left(int current, int prev, int length) =>
current - (current - prev) * length + 1
shift_bars_to_right(int bars) =>
bars + 20
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Store |
// # ========================================================================= #
//#region
var UDT_Store bin = UDT_Store.new(hl_ln = array.new<line>(), hl_lbl = array.new<label>())
method clean_hl(UDT_Store store) =>
for obj in store.hl_ln
obj.delete()
for obj in store.hl_lbl
obj.delete()
store.hl_ln.clear()
store.hl_lbl.clear()
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Highs & Lows MTF |
// # ========================================================================= #
//#region
method draw_pivots_ol_line(UDT_MTF mtf) =>
ol = line.new(
x1 = mtf.x1
, y1 = mtf.y1
, x2 = mtf.x2
, y2 = mtf.y2
, xloc = xloc.bar_time
, color = hl_openline_css
, style = line_style(hl_openline_type)
, width = hl_openline_width
)
bin.hl_ln.push(ol)
mtf
method draw_pivots_hl_line(UDT_MTF mtf, color css, string pdhl_style, int line_width) =>
hl = line.new(
x1 = mtf.x1
, y1 = mtf.y1
, x2 = mtf.x2
, y2 = mtf.y2
, xloc = xloc.bar_time
, color = css
, style = line_style(pdhl_style)
, width = line_width
)
bin.hl_ln.push(hl)
mtf
method draw_pivots_mid_line(UDT_MTF mtf) =>
ml = line.new(
x1 = mtf.x1
, y1 = mtf.y1
, x2 = mtf.x2
, y2 = mtf.y2
, xloc = xloc.bar_time
, color = hl_midline_css
, style = line_style(hl_midline_type)
, width = hl_midline_width
)
bin.hl_ln.push(ml)
mtf
method draw_pivots_ll_line(UDT_MTF mtf, color css, string pdhl_style, int line_width) =>
ll = line.new(
x1 = mtf.x1
, y1 = mtf.y1
, x2 = mtf.x2
, y2 = mtf.y2
, xloc = xloc.bar_time
, color = css
, style = line_style(pdhl_style)
, width = line_width
)
bin.hl_ln.push(ll)
mtf
method draw_pivots_label(UDT_MTF mtf, string fmt, string tf, color css) =>
lbl = label.new(
x = mtf.x2
, y = mtf.y2
, xloc = xloc.bar_time
, text = str.format(fmt, tf)
, color = colors_transparent
, textcolor = css
, size = text_size(general_text)
, style = label.style_label_left
, text_font_family = font_style(general_font)
)
bin.hl_lbl.push(lbl)
mtf
method mtf_pivots(UDT_HTF_Candle candle, tf, css, pdhl_style, line_width) =>
h_mtf = UDT_MTF.new(x1 = candle.ht, x2 = candle.ct, y1 = candle.h, y2 = candle.h)
l_mtf = UDT_MTF.new(x1 = candle.lt, x2 = candle.ct, y1 = candle.l, y2 = candle.l)
// validate high/low detections, if no candle is detected on the levels, set x1 to open
if na(h_mtf.x1)
h_mtf.x1 := candle.ot
if na(l_mtf.x1)
l_mtf.x1 := candle.ot
// position
extension = shift_to_right(time, 10, timeframe.period)
h_mtf.x2 := extension
l_mtf.x2 := extension
// Draw high line
h_mtf.draw_pivots_hl_line(css, pdhl_style, line_width)
.draw_pivots_label('P{0}H', tf, css)
// Draw low line
l_mtf.draw_pivots_ll_line(css, pdhl_style, line_width)
.draw_pivots_label('P{0}L', tf, css)
if hl_openline
o_mtf = UDT_MTF.new(x1 = candle.ot, x2 = candle.ct, y1 = candle.o, y2 = candle.o)
o_mtf.x2 := extension
// Draw open line
o_mtf.draw_pivots_ol_line()
.draw_pivots_label('P{0}O', tf, hl_openline_css)
if hl_midline
m_mtf = UDT_MTF.new()
midline_y = (h_mtf.y1 + l_mtf.y1) / 2
m_mtf.x1 := candle.ot
m_mtf.x2 := extension
m_mtf.y1 := midline_y
m_mtf.y2 := midline_y
// Draw midline
m_mtf.draw_pivots_mid_line()
.draw_pivots_label('P{0}A', tf, hl_midline_css)
candle
method session_begins(string tf, string ses, string tz) =>
ta.change(time(tf, ses, na(tz) ? "" : tz))!= 0
session_begins_2(string tf, string ses, string tz) =>
t = time(tf, ses, na(tz) ? "" : tz)
ct = time_close(tf, ses, na(tz) ? "" : tz)
not na(t) and not na(ct) and (na(t[1]) or t > t[1])
method in_session(string tf, string ses, string tz) =>
t = time(tf, ses, na(tz) ? "" : tz)
ct = time_close(tf, ses, na(tz) ? "" : tz)
not na(t) and not na(ct)
is_bullish_candle(float c, float o, float h, float l) =>
// Doji candle
if c == o
math.abs(o - h) < math.abs(o - l)
else
c > o
method detect_htf_candle(array<UDT_HTF_Candle> candles, string tf, int buffer) =>
if session_begins(tf, "", na)or candles.size()==0
// log.info("session begins " + " open=" + str.format_time(time, "yyyy-MM-dd HH:mm"))
candle = UDT_HTF_Candle.new(tf = 'D')
candle.o := open
candle.c := close
candle.h := high
candle.l := low
candle.ot := time
candle.ct := time
candle.ht := time
candle.lt := time
candle.bull := is_bullish_candle(candle.c, candle.o, candle.h, candle.l)
if candles.size() >= buffer
candles.pop()
candles.unshift(candle)
else if in_session(tf, "", na) and candles.size()>0
candle = candles.first()
candle.c := close
candle.ct := time
if high > candle.h
candle.h := high
candle.ht := time
// log.info("h=" + str.tostring(high) + " l=" + str.tostring(low) + " o=" + str.tostring(open) + " c=" + str.tostring(close))
if low < candle.l
candle.l := low
candle.lt := time
// log.info("h=" + str.tostring(high) + " l=" + str.tostring(low) + " o=" + str.tostring(open) + " c=" + str.tostring(close))
candle.bull := is_bullish_candle(candle.c, candle.o, candle.h, candle.l)
// log.info("in session " + " time=" + str.format_time(time, "yyyy-MM-dd HH:mm") + " o=" + str.tostring(candle.o) + " c=" + str.tostring(candle.c))
candles
bin.clean_hl()
const int buffer = 2
if hl_daily
var htf_daily_candles = array.new<UDT_HTF_Candle>()
htf_daily_candles.detect_htf_candle('D', buffer)
if htf_daily_candles.size() == buffer
prev_day = htf_daily_candles.get(1)
prev_day.mtf_pivots('D', hl_css_daily, hl_line_daily, hl_line_width_daily)
if hl_weekly
var htf_weekly_candles = array.new<UDT_HTF_Candle>()
htf_weekly_candles.detect_htf_candle('W', buffer)
if htf_weekly_candles.size() == buffer and barstate.islast
prev_week = htf_weekly_candles.get(1)
prev_week.mtf_pivots('W', hl_css_weekly, hl_line_weekly, hl_line_width_weekly)
if hl_monthly
var htf_monthly_candles = array.new<UDT_HTF_Candle>()
htf_monthly_candles.detect_htf_candle('M', buffer)
if htf_monthly_candles.size() == buffer and barstate.islast
prev_month = htf_monthly_candles.get(1)
prev_month.mtf_pivots('M', hl_css_monthly, hl_line_monthly, hl_line_width_monthly)
if hl_quartely
var htf_quartely_candles = array.new<UDT_HTF_Candle>()
htf_quartely_candles.detect_htf_candle('3M', buffer)
if htf_quartely_candles.size() == buffer and barstate.islast
prev_quarter = htf_quartely_candles.get(1)
prev_quarter.mtf_pivots('3M', hl_css_quaterly, hl_line_quaterly, hl_line_width_quaterly)
if hl_yearly
var htf_yearly_candles = array.new<UDT_HTF_Candle>()
htf_yearly_candles.detect_htf_candle('12M', buffer)
if htf_yearly_candles.size() == buffer and barstate.islast
prev_year = htf_yearly_candles.get(1)
prev_year.mtf_pivots('12M', hl_css_yearly, hl_line_yearly, hl_line_width_yearly)
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// # ========================================================================= #
// # | Brand |
// # ========================================================================= #
//#region
if barstate.isfirst and general_brand_show == false
var table brand = table.new(position.bottom_right, 1, 1, bgcolor = chart.bg_color)
table.cell(brand, 0, 0, "© CandelaCharts", text_color = colors_gray, text_halign = text.align_center, text_size = text_size(general_text), text_font_family = font_style(general_font))
//#endregion
// # ========================================================================= #
// # | End |
// # ========================================================================= #
// Constants
color CLEAR = color.rgb(0,0,0,100)
eq_threshold = input.float(0.3, '', minval = 0, maxval = 0.5, step = 0.1, group = 'Market Structure',inline = 'equilibrium_zone')
showSwing = input.bool(false, 'Swing Points', group="Market Structure",inline="3")
swingSize_swing = input.int(10, "Swing Point Period",inline="4", group="Market Structure")
label_sizes_s =input.string("Medium", options=["Small", "Medium","Large"], title="Label Size",inline="4", group="Market Structure")
label_size_buysell_s = label_sizes_s == "Small" ? size.tiny : label_sizes_s == "Medium" ? size.small : label_sizes_s == "Large" ? size.normal : label_sizes_s == "Medium2" ? size.normal : label_sizes_s == "Large2" ? size.large : size.huge
label_size_buysell = label_sizes_s == "Small" ? size.tiny : label_sizes_s == "Medium" ? size.small : label_sizes_s == "Large" ? size.normal : label_sizes_s == "Medium2" ? size.normal : label_sizes_s == "Large2" ? size.large : size.huge
swingColor = input.color(#787b86 , '', group="Market Structure",inline="3")
swingSize = 3
length_eqh = 3
//----------------------------------------}
//Key Levels
//----------------------------------------{
var Show_4H_Levels = input.bool(defval=false, title='4H', group='Key Levels', inline='4H')
Color_4H_Levels = input.color(title='', defval=color.orange, group='Key Levels', inline='4H')
Style_4H_Levels = input.string('Dotted', ' Style', ['Solid', 'Dashed', 'Dotted'], group="Key Levels",inline="4H")
Text_4H_Levels = input.bool(defval=false, title='Shorten', group='Key Levels', inline='4H')
labelsize = input.string(defval='Medium', title='Text Size', options=['Small', 'Medium', 'Large'],group = "Key Levels", inline='H')
displayStyle = 'Standard'
distanceright = 25
radistance = 250
linesize = 'Small'
linestyle = 'Solid'
var untested_monday = false
bosConfType = 'Candle High'//input.string('Candle Close', 'BOS Confirmation', ['Candle Close', 'Wicks'], tooltip='Choose whether candle close/wick above previous swing point counts as a BOS.')
MSS = true//input.bool(false, 'Show MSS', tooltip='Renames the first counter t_MS BOS to MSS' )
// showSwing = false//input.bool(true, 'Show Swing Points', tooltip='Show or hide HH, LH, HL, LL')
// Functions
lineStyle(x) =>
switch x
'Solid' => line.style_solid
'Dashed' => line.style_dashed
'Dotted' => line.style_dotted
pivot_high_found = ta.pivothigh(high, swingSize_swing, swingSize_swing)
pivot_low_found = ta.pivotlow(low, swingSize_swing, swingSize_swing)
var float prevHigh_s = na,var float prevLow_s = na,var int prevHighIndex_s = na,var int prevLowIndex_s = na
bool higher_highs = false, bool lower_highs = false, bool higher_lows = false, bool lower_lows = false
var int prevSwing_s = 0
if not na(pivot_high_found)
if pivot_high_found >= prevHigh_s
higher_highs := true
prevSwing_s := 2
else
lower_highs := true
prevSwing_s := 1
prevHigh_s := pivot_high_found
prevHighIndex_s := bar_index - swingSize_swing
if not na(pivot_low_found)
if pivot_low_found >= prevLow_s
higher_lows := true
prevSwing_s := -1
else
lower_lows := true
prevSwing_s := -2
prevLow_s := pivot_low_found
prevLowIndex_s := bar_index - swingSize_swing
// ———————————————————— Global data {
//Using current bar data for HTF highs and lows instead of security to prevent future leaking
var htfH = open
var htfL = open
if close > htfH
htfH:= close
if close < htfL
htfL := close
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------- Key Levels
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var monday_time = time
var monday_high = high
var monday_low = low
[weekly_time, weekly_open] = request.security(syminfo.tickerid, 'W', [time, open], lookahead=barmerge.lookahead_on)
[weeklyh_time, weeklyh_open] = request.security(syminfo.tickerid, 'W', [time[1], high[1]], lookahead=barmerge.lookahead_on)
[weeklyl_time, weeklyl_open] = request.security(syminfo.tickerid, 'W', [time[1], low[1]], lookahead=barmerge.lookahead_on)
[monthly_time, monthly_open] = request.security(syminfo.tickerid, 'M', [time, open], lookahead=barmerge.lookahead_on)
[monthlyh_time, monthlyh_open] = request.security(syminfo.tickerid, 'M', [time[1], high[1]], lookahead=barmerge.lookahead_on)
[monthlyl_time, monthlyl_open] = request.security(syminfo.tickerid, 'M', [time[1], low[1]], lookahead=barmerge.lookahead_on)
[intrah_time, intrah_open] = request.security(syminfo.tickerid, '240', [time[1], high[1]], lookahead=barmerge.lookahead_on)
[intral_time, intral_open] = request.security(syminfo.tickerid, '240', [time[1], low[1]], lookahead=barmerge.lookahead_on)
[quarterly_time, quarterly_open] = request.security(syminfo.tickerid, '3M', [time, open], lookahead=barmerge.lookahead_on)
[quarterlyh_time, quarterlyh_open] = request.security(syminfo.tickerid, '3M', [time[1], high[1]], lookahead=barmerge.lookahead_on)
[quarterlyl_time, quarterlyl_open] = request.security(syminfo.tickerid, '3M', [time[1], low[1]], lookahead=barmerge.lookahead_on)
[yearlyh_time, yearlyh_open] = request.security(syminfo.tickerid, '12M', [time, high], lookahead=barmerge.lookahead_on)
[yearlyl_time, yearlyl_open] = request.security(syminfo.tickerid, '12M', [time, low], lookahead=barmerge.lookahead_on)
if weekly_time != weekly_time[1]
untested_monday := false
untested_monday
untested_monday := true
monday_low
linewidthint = 1
if linesize == 'Small'
linewidthint := 1
linewidthint
if linesize == 'Medium'
linewidthint := 2
linewidthint
if linesize == 'Large'
linewidthint := 3
linewidthint
var linewidth_def = linewidthint
fontsize = size.small
if labelsize == 'Small'
fontsize := size.small
fontsize
if labelsize == 'Medium'
fontsize := size.normal
fontsize
if labelsize == 'Large'
fontsize := size.large
fontsize
linestyles = line.style_solid
if linestyle == 'Dashed'
linestyles := line.style_dashed
linestyles
if linestyle == 'Dotted'
linestyles := line.style_dotted
linestyles
var DEFAULT_LABEL_SIZE = fontsize
var DEFAULT_LABEL_STYLE = label.style_none
var Rigth_Def = distanceright
var arr_price = array.new_float(0)
var arr_label = array.new_label(0)
Combine_Levels(arr_price, arr_label, currentprice, currentlabel, currentcolor) =>
if array.includes(arr_price, currentprice)
whichindex = array.indexof(arr_price, currentprice)
labelhold = array.get(arr_label, whichindex)
whichtext = label.get_text(labelhold)
label.set_text(labelhold, label.get_text(currentlabel) + ' / ' + whichtext)
label.set_text(currentlabel, '')
label.set_textcolor(labelhold, currentcolor)
else
array.push(arr_price, currentprice)
array.push(arr_label, currentlabel)
extend_to_current(bars) =>
timenow + (time - time[1]) * bars
if barstate.islast
arr_price := array.new_float(0)
arr_label := array.new_label(0)
if Show_4H_Levels
limit_4H_right = extend_to_current(Rigth_Def)
intrah_limit_right = extend_to_current(Rigth_Def)
intral_limit_right = extend_to_current(Rigth_Def)
var intrah_line = line.new(x1=intrah_time, x2=intrah_limit_right, y1=intrah_open, y2=intrah_open, color=Color_4H_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_4H_Levels))
var intral_line = line.new(x1=intral_time, x2=intral_limit_right, y1=intral_open, y2=intral_open, color=Color_4H_Levels, width=linewidth_def, xloc=xloc.bar_time, style=lineStyle(Style_4H_Levels))
line.set_xy1(intrah_line,intrah_time,intrah_open)
line.set_xy2(intrah_line,intrah_limit_right,intrah_open)
line.set_x1(intral_line, intral_time)
line.set_x2(intral_line, intral_limit_right)
line.set_y1(intral_line, intral_open)
line.set_y2(intral_line, intral_open)
daily_limit_right = extend_to_current(Rigth_Def)
dailyh_limit_right = extend_to_current(Rigth_Def)
dailyl_limit_right = extend_to_current(Rigth_Def)
type Candle
float o
float c
float h
float l
int o_idx
int c_idx
int h_idx
int l_idx
box body
line wick_up
line wick_down
type Imbalance
box b
int idx
type CandleSettings
bool show
string htf
int max_display
type Settings
int max_sets
color bull_body
color bull_border
color bull_wick
color bear_body
color bear_border
color bear_wick
int offset
int buffer
int htf_buffer
int width
bool trace_show
color trace_o_color
string trace_o_style
int trace_o_size
color trace_c_color
string trace_c_style
int trace_c_size
color trace_h_color
string trace_h_style
int trace_h_size
color trace_l_color
string trace_l_style
int trace_l_size
string trace_anchor
bool label_show
color label_color
string label_size
bool htf_label_show
color htf_label_color
string htf_label_size
bool htf_timer_show
color htf_timer_color
string htf_timer_size
type CandleSet
Candle[] candles
Imbalance[] imbalances
CandleSettings settings
label tfName
label tfTimer
type Helper
string name = "Helper"
Settings settings = Settings.new()
var CandleSettings SettingsHTF1 = CandleSettings.new()
var CandleSettings SettingsHTF2 = CandleSettings.new()
var CandleSettings SettingsHTF3 = CandleSettings.new()
var Candle[] candles_1 = array.new<Candle>(0)
var Candle[] candles_2 = array.new<Candle>(0)
var Candle[] candles_3 = array.new<Candle>(0)
var CandleSet htf1 = CandleSet.new()
htf1.settings := SettingsHTF1
htf1.candles := candles_1
var CandleSet htf2 = CandleSet.new()
htf2.settings := SettingsHTF2
htf2.candles := candles_2
var CandleSet htf3 = CandleSet.new()
htf3.settings := SettingsHTF3
htf3.candles := candles_3
//+------------------------------------------------------------------------------------------------------------+//
//+--- Settings ---+//
//+------------------------------------------------------------------------------------------------------------+//
htf1.settings.show := input.bool(true, "HTF 1 ", inline="htf1")
htf_1 = input.timeframe("15", "", inline="htf1")
htf1.settings.htf := htf_1
htf1.settings.max_display := input.int(4, "", inline="htf1")
htf2.settings.show := input.bool(true, "HTF 2 ", inline="htf2")
htf_2 = input.timeframe("60", "", inline="htf2")
htf2.settings.htf := htf_2
htf2.settings.max_display := input.int(4, "", inline="htf2")
htf3.settings.show := input.bool(true, "HTF 3 ", inline="htf3")
htf_3 = input.timeframe("1D", "", inline="htf3")
htf3.settings.htf := htf_3
htf3.settings.max_display := input.int(4, "", inline="htf3")
settings.max_sets := input.int(6, "Limit to next HTFs only", minval=1, maxval=6)
settings.bull_body := input.color(color.new(#39d23e, 3), "Body ", inline="body")
settings.bear_body := input.color(color.new(#ec0d0d, 4), "", inline="body")
settings.bull_border := input.color(color.rgb(206, 216, 216), "Borders", inline="borders")
settings.bear_border := input.color(color.new(#e5e9ea, 0), "", inline="borders")
settings.bull_wick := input.color(color.new(#e9eeee, 10), "Wick ", inline="wick")
settings.bear_wick := input.color(#f7f9f9, "", inline="wick")
settings.offset := input.int(25, "padding from current candles", minval = 1)
settings.buffer := input.int(1, "space between candles", minval = 1, maxval = 4)
settings.htf_buffer := input.int(10, "space between Higher Timeframes", minval = 1, maxval = 10)
settings.width := input.int(1, "Candle Width", minval = 1, maxval = 4)*2
settings.htf_label_show := input.bool(true, "HTF Label ", inline="HTFlabel")
settings.htf_label_color := input.color(color.new(#e6eef0, 10), "", inline='HTFlabel')
settings.htf_label_size := input.string(size.large, "", [size.tiny, size.small, size.normal, size.large, size.huge], inline="HTFlabel")
// ---------------- إعدادات ----------------
atrPeriod = input.int(10, "ATR Period", minval=1)
factor = input.float(3.0, "Supertrend Multiplier", minval=0.1, step=0.1)
rsiLength = input.int(14, "RSI Length", minval=2)
macdFast = input.int(12, "MACD Fast Length", minval=1)
macdSlow = input.int(26, "MACD Slow Length", minval=1)
macdSig = input.int(9, "MACD Signal Length", minval=1)
emaLen1 = input.int(20, "EMA 20 Length")
emaLen2 = input.int(50, "EMA 50 Length")
tablePos = input.string("top_right", "Table Position",
options=["top_left","top_right","bottom_left","bottom_right"])
// ---------------- Supertrend ----------------
atr = ta.atr(atrPeriod)
upperBand = hl2 - factor * atr
lowerBand = hl2 + factor * atr
var float trend = na
if (close > nz(trend[1], hl2))
trend := math.max(upperBand, nz(trend[1], upperBand))
else
trend := math.min(lowerBand, nz(trend[1], lowerBand))
bull = close > trend
bear = close < trend
buySignal = ta.crossover(close, trend)
sellSignal = ta.crossunder(close, trend)
// ---------------- EMA ----------------
ema20 = ta.ema(close, emaLen1)
ema50 = ta.ema(close, emaLen2)
emaBull = ema20 > ema50
emaBear = ema20 < ema50
// ---------------- RSI ----------------
rsi = ta.rsi(close, rsiLength)
rsiBull = rsi > 50
// ---------------- MACD ----------------
macd = ta.ema(close, macdFast) - ta.ema(close, macdSlow)
signal = ta.ema(macd, macdSig)
macdBull = macd > signal
// ---------------- VWAP ----------------
vwapValue = ta.vwap(close)
vwapBull = close > vwapValue
vwapBear = close < vwapValue
// ---------------- Dashboard ----------------
// نحتاج 8 صفوف: (العنوان + Supertrend + EMA + RSI + MACD + VWAP + FINAL + السعر الحالي)
var table dash = table.new(position=tablePos, columns=2, rows=8, border_width=1)
if barstate.islast
// العناوين
table.cell(dash, 0, 0, "Indicator", text_color=color.white, bgcolor=color.blue)
table.cell(dash, 1, 0, "Signal", text_color=color.white, bgcolor=color.blue)
// Supertrend
table.cell(dash, 0, 1, "Supertrend", text_color=color.white, bgcolor=color.rgb(79, 97, 148))
table.cell(dash, 1, 1, buySignal ? "كول ✅" : sellSignal ? "انعكاس المسار ❌" : bull ? "كول" : "بوت",
text_color=color.white,
bgcolor= buySignal ? color.green : sellSignal ? color.red : bull ? color.green : color.red)
// EMA
table.cell(dash, 0, 2, "EMA 20/50", text_color=color.white, bgcolor=color.rgb(71, 91, 144))
table.cell(dash, 1, 2, emaBull ? "كول" : "بوت",
text_color=color.white, bgcolor=emaBull ? color.green : color.red)
// RSI
table.cell(dash, 0, 3, "RSI", text_color=color.white, bgcolor=color.rgb(66, 85, 139))
table.cell(dash, 1, 3, rsiBull ? "كول" : "بوت",
text_color=color.white, bgcolor=rsiBull ? color.green : color.red)
// MACD
table.cell(dash, 0, 4, "MACD", text_color=color.white, bgcolor=color.rgb(94, 111, 159))
table.cell(dash, 1, 4, macdBull ? "كول" : "بوت",
text_color=color.white, bgcolor=macdBull ? color.green : color.red)
// VWAP
table.cell(dash, 0, 5, "VWAP", text_color=color.white, bgcolor=color.rgb(89, 106, 153))
table.cell(dash, 1, 5, vwapBull ? "كول" : "بوت",
text_color=color.white, bgcolor=vwapBull ? color.green : color.red)
// السعر الحالي
table.cell(dash, 0, 7, "السعر", text_color=color.white, bgcolor=color.rgb(78, 89, 121))
table.cell(dash, 1, 7, str.tostring(close, format.mintick),
text_color=color.white, bgcolor=color.gray)
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. However, you can use it freely and without any limitations – learn more here.
Penafian
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. However, you can use it freely and without any limitations – learn more here.
Penafian
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.