Kve - Indicator 20.06
Kve - Indicator 20.06
// Calculate EMA
emaValue = ta.ema(close, emaLengths)
// Calculate RSI
rsiValue = ta.rsi(close, rsiLengths)
// Define variables
var bool strongLongSignal = false
var bool strongShortSignal = false
highlightState = input(title='Highlight State ?', defval=false)
srcs = input(close, title='Source')
//5-8-13 Signal
len5 = input.int(5, minval=1, title='5EMA')
out5 = ta.ema(srcs, len5)
emaValue5 = ta.ema(close, len5)
if long5813
shortSignal := false
///////////////////////////////////////////
hide = timeframe.isintraday
// EMA calculations
ema = ta.ema(close, emaPeriod)
ema2 = ta.ema(close,emaPeriod2)
ema3 = ta.ema(close, emaPeriod3)
emaColor = close > ema3 ? color.rgb(56, 142, 60, 63) : color.rgb(147, 40, 51, 38)
// Plotting EMA's
plot_ema1 = plot(ShowSmartemsa?(hide ? ema : na):na, style=plot.style_line,
color=color.rgb(255, 255, 255, 100), title="EMA", linewidth=1,editable=false)
plot_ema2 = plot(ShowSmartemsa?(hide ? ema2 : na):na, style=plot.style_line,
color=color.rgb(255, 255, 255, 100), title="EMA", linewidth=1,editable=false)
plot_ema3 = plot(ShowSmartemsa?ema3:na, style=plot.style_line, color=color.rgb(255,
255, 255, 100), title="EMA", linewidth=1,editable=false)
// EMA Cloud
cloudColor = ema2 > ema ? #0f851363 : #a8141450
cloudColor2 = ema2 > ema3 ? color.new(#0f8513, 8) : #ea1818c7
cloudColor := showcloud ? cloudColor : na
fill(plot_ema1, plot_ema2, color=cloudColor, title="EMA Cloud")
fill(plot_ema3, plot_ema2, color=cloudColor, title="EMA Cloud")
//Plot the Price Action Channel (PAC) base on EMA high,low and close
La = plot(ShowSonicR?pacL:na, color=#ff0000, linewidth=1, title='High PAC EMA',
transp=50,editable = false)
Ha = plot(ShowSonicR?pacH:na, color=#0051ff, linewidth=1, title='Low PAC EMA',
transp=50,editable = false)
Ca = plot(ShowSonicR?pacC:na, color=DODGERBLUE, linewidth=2, title='Close PAC EMA',
transp=0,editable = false)
fill(La, Ha, color=color.new(color.green, 80), title='Fill HiLo PAC')
//////////////////////////////////////////
// CHUẨN BỊ CÁC THÔNG SỐ CHO SMARTTRAIL //
//{
trailType = input.string('modified', 'Kve Type', options=['modified',
'unmodified'],group = 'Smart Trail')
ATRPeriod = input(200, 'Kve')
ATRFactor = input(5., 'Kve')
show_fib_entries = input(true, 'Kve_Entry')
Up = norm_c - loss
Dn = norm_c + loss
TrendUp = Up
TrendDown = Dn
Trend = 1
ex = 0.0
ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend ==
1 ? math.max(ex[1], norm_h) : Trend == -1 ? math.min(ex[1], norm_l) : ex[1]
//}
fib1Level = 61.8
fib2Level = 78.6
fib3Level = 88.6
//////////////////SMARTTRAIL 2//////////////////////
Trend1Up1 = Up1
Trend1Down1 = Dn1
Trend1 = 1
ex1 = 0.0
ex1 := ta.crossover(Trend1, 0) ? norm_h1 : ta.crossunder(Trend1, 0) ? norm_l11 :
Trend1 == 1 ? math.max(ex1[1], norm_h1) : Trend1 == -1 ? math.min(ex1[1], norm_l11)
: ex1[1]
//}
Fib11Level11 = 61.8
Fib21Level11 = 78.6
Fib31Level11 = 88.6
//Style
upCss = input.color(color.teal, 'Colors', inline = 'inline1', group = 'Style')
dnCss = input.color(color.red, '', inline = 'inline1', group = 'Style')
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
//Gaussian window
gauss(x, ha) => math.exp(-(math.pow(x, 2)/(ha * ha * 2)))
//-----------------------------------------------------------------------------}
//Append lines
//-----------------------------------------------------------------------------{
k = bar_index
var ln = array.new_line(0)
//-----------------------------------------------------------------------------}
//End point method
//-----------------------------------------------------------------------------{
var coefs = array.new_float(0)
var den = 0.
den := coefs.sum()
out = 0.
if not repaint
for i = 0 to 249
out += src[i] * coefs.get(i)
out /= den
mae = ta.sma(math.abs(src - out), 249) * mult
//-----------------------------------------------------------------------------}
//Compute and display NWE
//-----------------------------------------------------------------------------{
float y2 = na
float y1 = na
nwe = array.new<float>(0)
if ShowSDR?(barstate.islast and repaint):na
sae = 0.
sae1 = 0.
//Compute and set NWE point
for i = 0 to math.min(249,k - 1)
sum = 0.
sumw = 0.
//Compute weighted mean
for j = 0 to math.min(249,k - 1)
w = gauss(i - j, ha)
sum += src[j] * w
sumw += w
y2 := sum / sumw
sae += math.abs(src[i] - y2)
sae1 += math.abs(src[i] - y2)
nwe.push(y2)
y1 := nwe.get(i)
//-----------------------------------------------------------------------------}
//Plot
//-----------------------------------------------------------------------------}
//Ab= plot(repaint ? na : out + mae, 'Upper', upCss,editable =false)
//Bb = plot(repaint ? na : out - mae, 'Lower', dnCss,editable =false)
//Crossing Arrows
//plotshape(ta.crossunder(close, out - mae) ? low : na, "Crossunder",
shape.labelup, location.absolute, color(na), 0 , text = '🔵', textcolor = upCss,
size = size.tiny,editable =false)
//plotshape(ta.crossover(close, out + mae) ? high : na, "Crossover",
shape.labeldown, location.absolute, color(na), 0 , text = '🔴', textcolor = dnCss,
size = size.tiny,editable =false)
/////////////////////////////////////////////////////
//Constants
//-----------------------------------------------------------------------------{
color TRANSP_CSS = #ffffff00
//Tooltips
string MODE_TOOLTIP = 'Allows to display historical Structure or only the
recent ones'
string STYLE_TOOLTIP = 'Indicator color theme'
string COLOR_CANDLES_TOOLTIP = 'Display additional candles with a color reflecting
the current trend detected by structure'
string SHOW_INTERNAL = 'Display internal market structure'
string CONFLUENCE_FILTER = 'Filter non significant internal structure
breakouts'
string SHOW_SWING = 'Display swing market Structure'
string SHOW_SWING_POINTS = 'Display swing point as labels on the chart'
string SHOW_SWHL_POINTS = 'Highlight most recent strong and weak high/low
points on the chart'
string INTERNAL_OB = 'Display internal order blocks on the chart\n\
nNumber of internal order blocks to display on the chart'
string SWING_OB = 'Display swing order blocks on the chart\n\nNumber
of internal swing blocks to display on the chart'
string FILTER_OB = 'Method used to filter out volatile order blocks \n\
nIt is recommended to use the cumulative mean range method when a low amount of
data is available'
string SHOW_EQHL = 'Display equal highs and equal lows on the chart'
string EQHL_BARS = 'Number of bars used to confirm equal highs and
equal lows'
string EQHL_THRESHOLD = 'Sensitivity threshold in a range (0, 1) used for
the detection of equal highs & lows\n\nLower values will return fewer but more
pertinent results'
string SHOW_FVG = 'Display fair values gaps on the chart'
string AUTO_FVG = 'Filter out non significant fair value gaps'
string FVG_TF = 'Fair value gaps timeframe'
string EXTEND_FVG = 'Determine how many bars to extend the Fair Value
Gap boxes on chart'
string PED_ZONES = 'Display premium, discount, and equilibrium zones on
chart'
//-----------------------------------------------------------------------------{
//Settings
//-----------------------------------------------------------------------------{
//General
//----------------------------------------{
mode = input.string('Historical'
, options = ['Historical', 'Present']
, group = 'Smart Money Concepts'
, tooltip = MODE_TOOLTIP)
style = input.string('Colored'
, options = ['Colored', 'Monochrome']
, group = 'Smart Money Concepts'
, tooltip = STYLE_TOOLTIP)
//----------------------------------------}
//Internal Structure
//----------------------------------------{
show_internals = input(false, 'Show Internal Structure'
, group = 'Real Time Internal Structure'
, tooltip = SHOW_INTERNAL)
//Bear Structure
show_ibear = input.string('All', 'Bearish Structure'
, options = ['All', 'BOS', 'CHoCH']
, inline = 'ibear'
, group = 'Real Time Internal Structure')
//----------------------------------------}
//Swing Structure
//----------------------------------------{
show_Structure = input(false, 'Show Swing Structure'
, group = 'Real Time Swing Structure'
, tooltip = SHOW_SWING)
//Bull Structure
show_bull = input.string('All', 'Bullish Structure'
, options = ['All', 'BOS', 'CHoCH']
, inline = 'bull'
, group = 'Real Time Swing Structure')
//Bear Structure
show_bear = input.string('All', 'Bearish Structure'
, options = ['All', 'BOS', 'CHoCH']
, inline = 'bear'
, group = 'Real Time Swing Structure')
//Swings
show_swings = input(false, 'Show Swings Points'
, inline = 'swings'
, group = 'Real Time Swing Structure'
, tooltip = SHOW_SWING_POINTS)
//----------------------------------------}
//Order Blocks
//----------------------------------------{
show_iob = input(false, 'Internal Order Blocks'
, inline = 'iob'
, group = 'Order Blocks'
, tooltip = INTERNAL_OB)
//----------------------------------------}
//EQH/EQL
//----------------------------------------{
show_eq = input(true, 'Equal High/Low'
, group = 'EQH/EQL'
, tooltip = SHOW_EQHL)
//----------------------------------------}
//Fair Value Gaps
//----------------------------------------{
show_fvg = input(true, 'Fair Value Gaps'
, group = 'Fair Value Gaps'
, tooltip = SHOW_FVG)
//----------------------------------------}
//Previous day/week high/low
//----------------------------------------{
//Daily
show_pdhl = input(false, 'Daily'
, inline = 'daily'
, group = 'Highs & Lows MTF')
//Weekly
show_pwhl = input(false, 'Weekly'
, inline = 'weekly'
, group = 'Highs & Lows MTF')
//Monthly
show_pmhl = input(false, 'Monthly'
, inline = 'monthly'
, group = 'Highs & Lows MTF')
//----------------------------------------}
//Premium/Discount zones
//----------------------------------------{
show_sd = input(false, 'Premium/Discount Zones'
, group = 'Premium & Discount Zones'
, tooltip = PED_ZONES)
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index
atrz = ta.atr(200)
cmean_range = ta.cum(high - low) / n
if mode == 'Present'
line.delete(structure_line[1])
label.delete(structure_lbl[1])
//Swings detection/measurements
swings(len)=>
var os = 0
upper = ta.highest(len)
lower = ta.lowest(len)
[top, btm]
//Search for highest/lowest high within the structure interval and get range
if use_max
for i = 1 to (n - loc)-1
if (high[i] - low[i]) < ob_threshold[i] * 2
max := math.max(high[i], max)
min := max == high[i] ? low[i] : min
idx := max == high[i] ? i : idx
else
for i = 1 to (n - loc)-1
if (high[i] - low[i]) < ob_threshold[i] * 2
min := math.min(low[i], min)
max := min == low[i] ? high[i] : max
idx := min == low[i] ? i : idx
array.unshift(target_top, max)
array.unshift(target_btm, min)
array.unshift(target_left, time[idx])
array.unshift(target_type, use_max ? -1 : 1)
color css = na
if swing
if style == 'Monochrome'
css := array.get(target_type, i) == 1 ? color.new(#b2b5be, 80) :
color.new(#5d606b, 80)
border_css = array.get(target_type, i) == 1 ? #b2b5be : #5d606b
box.set_border_color(get_box, border_css)
else
css := array.get(target_type, i) == 1 ? bull_ob_css : bear_ob_css
box.set_border_color(get_box, css)
box.set_bgcolor(get_box, css)
else
if style == 'Monochrome'
css := array.get(target_type, i) == 1 ? color.new(#b2b5be, 80) :
color.new(#5d606b, 80)
else
css := array.get(target_type, i) == 1 ? ibull_ob_css : ibear_ob_css
box.set_border_color(get_box, css)
box.set_bgcolor(get_box, css)
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
ext = time + (time - time[1])*20
//High
line.set_xy1(high_line, hx, hy)
line.set_xy2(high_line, ext, hy)
//Low
line.set_xy1(low_line, lx, ly)
line.set_xy2(low_line, ext, ly)
//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
var trend = 0, var itrend = 0
//Alerts
bull_choch_alert = false
bull_bos_alert = false
bear_choch_alert = false
bear_bos_alert = false
bull_ichoch_alert = false
bull_ibos_alert = false
bear_ichoch_alert = false
bear_ibos_alert = false
bull_iob_break = false
bear_iob_break = false
bull_ob_break = false
bear_ob_break = false
eqh_alert = false
eql_alert = false
//Structure colors
var bull_css = style == 'Monochrome' ? #b2b5be
: swing_bull_css
//Labels size
var internal_structure_lbl_size = internal_structure_size == 'Tiny'
? size.tiny
: internal_structure_size == 'Small'
? size.small
: size.normal
//Swings
[top, btm] = swings(length)
//-----------------------------------------------------------------------------}
//Pivot High
//-----------------------------------------------------------------------------{
var line extend_top = na
if ShowSMC?top:na
top_cross := true
txt_top := top > top_y ? 'HH' : 'LH'
if show_swings
top_lbl = label.new(n-length, top, txt_top
, color = TRANSP_CSS
, textcolor = bear_css
, style = label.style_label_down
, size = swing_structure_lbl_size)
if mode == 'Present'
label.delete(top_lbl[1])
top_y := top
top_x := n - length
trail_up := top
trail_up_x := n - length
if itop
itop_cross := true
itop_y := itop
itop_x := n - 5
//Trailing maximum
trail_up := math.max(high, trail_up)
trail_up_x := trail_up == high ? n : trail_up_x
label.set_x(extend_top_lbl, n + 20)
label.set_y(extend_top_lbl, trail_up)
label.set_text(extend_top_lbl, trend < 0 ? 'Strong High' : 'Weak High')
//-----------------------------------------------------------------------------}
//Pivot Low
//-----------------------------------------------------------------------------{
var line extend_btm = na
if ShowSMC?btm:na
btm_cross := true
txt_btm := btm < btm_y ? 'LL' : 'HL'
if show_swings
btm_lbl = label.new(n - length, btm, txt_btm
, color = TRANSP_CSS
, textcolor = bull_css
, style = label.style_label_up
, size = swing_structure_lbl_size)
if mode == 'Present'
label.delete(btm_lbl[1])
btm_y := btm
btm_x := n-length
trail_dn := btm
trail_dn_x := n-length
if ibtm
ibtm_cross := true
ibtm_y := ibtm
ibtm_x := n - 5
//Trailing minimum
trail_dn := math.min(low, trail_dn)
trail_dn_x := trail_dn == low ? n : trail_dn_x
label.set_x(extend_btm_lbl, n + 20)
label.set_y(extend_btm_lbl, trail_dn)
label.set_text(extend_btm_lbl, trend > 0 ? 'Strong Low' : 'Weak Low')
//-----------------------------------------------------------------------------}
//Order Blocks Arrays
//-----------------------------------------------------------------------------{
var iob_top = array.new_float(0)
var iob_btm = array.new_float(0)
var iob_left = array.new_int(0)
var iob_type = array.new_int(0)
//-----------------------------------------------------------------------------}
//Pivot High BOS/CHoCH
//-----------------------------------------------------------------------------{
//Filtering
var bull_concordant = true
if ifilter_confluence
bull_concordant := high - math.max(close, open) > math.min(close, open - low)
if itrend < 0
choch := true
bull_ichoch_alert := true
else
bull_ibos_alert := true
if show_internals
if show_ibull == 'All' or (show_ibull == 'BOS' and not choch) or
(show_ibull == 'CHoCH' and choch)
display_Structure(itop_x, itop_y, txt, ibull_css, true, true,
internal_structure_lbl_size)
itop_cross := false
itrend := 1
if trend < 0
choch := true
bull_choch_alert := true
else
bull_bos_alert := true
if show_Structure
if show_bull == 'All' or (show_bull == 'BOS' and not choch) or (show_bull
== 'CHoCH' and choch)
display_Structure(top_x, top_y, txt, bull_css, false, true,
swing_structure_lbl_size)
//Order Block
if show_ob
ob_coord(false, top_x, ob_top, ob_btm, ob_left, ob_type)
top_cross := false
trend := 1
//-----------------------------------------------------------------------------}
//Pivot Low BOS/CHoCH
//-----------------------------------------------------------------------------{
var bear_concordant = true
if ifilter_confluence
bear_concordant := high - math.max(close, open) < math.min(close, open - low)
if itrend > 0
choch := true
bear_ichoch_alert := true
else
bear_ibos_alert := true
if show_internals
if show_ibear == 'All' or (show_ibear == 'BOS' and not choch) or
(show_ibear == 'CHoCH' and choch)
display_Structure(ibtm_x, ibtm_y, txt, ibear_css, true, false,
internal_structure_lbl_size)
ibtm_cross := false
itrend := -1
if trend > 0
choch := true
bear_choch_alert := true
else
bear_bos_alert := true
if show_Structure
if show_bear == 'All' or (show_bear == 'BOS' and not choch) or (show_bear
== 'CHoCH' and choch)
display_Structure(btm_x, btm_y, txt, bear_css, false, false,
swing_structure_lbl_size)
//Order Block
if show_ob
ob_coord(true, btm_x, ob_top, ob_btm, ob_left, ob_type)
btm_cross := false
trend := -1
//-----------------------------------------------------------------------------}
//Order Blocks
//-----------------------------------------------------------------------------{
//Set order blocks
var iob_boxes = array.new_box(0)
var ob_boxes = array.new_box(0)
iob_size = array.size(iob_type)
ob_size = array.size(ob_type)
if barstate.isfirst
if show_iob
for i = 0 to iob_showlast-1
array.push(iob_boxes, box.new(na,na,na,na, xloc = xloc.bar_time))
if show_ob
for i = 0 to ob_showlast-1
array.push(ob_boxes, box.new(na,na,na,na, xloc = xloc.bar_time))
if iob_size > 0
if barstate.islast
display_ob(iob_boxes, iob_top, iob_btm, iob_left, iob_type, iob_showlast,
false, iob_size)
if ob_size > 0
if barstate.islast
display_ob(ob_boxes, ob_top, ob_btm, ob_left, ob_type, ob_showlast, true,
ob_size)
//-----------------------------------------------------------------------------}
//Fair Value Gaps
//-----------------------------------------------------------------------------{
var bullish_fvg_max = array.new_box(0)
var bullish_fvg_min = array.new_box(0)
float bullish_fvg_avg = na
float bearish_fvg_avg = na
bullish_fvg_cnd = false
bearish_fvg_cnd = false
change_tf = timeframe.change(fvg_tf)
//FVG conditions
bullish_fvg_cnd := src_l > src_h2
and src_c1 > src_h2
and delta_per > threshold
and change_tf
//FVG Areas
if bullish_fvg_cnd
array.unshift(bullish_fvg_max, box.new(n-1, src_l, n + fvg_extend,
math.avg(src_l, src_h2)
, border_color = bull_fvg_css
, bgcolor = bull_fvg_css))
if bearish_fvg_cnd
array.unshift(bearish_fvg_max, box.new(n-1, src_h, n + fvg_extend,
math.avg(src_h, src_l2)
, border_color = bear_fvg_css
, bgcolor = bear_fvg_css))
for bx in bullish_fvg_min
if low < box.get_bottom(bx)
box.delete(bx)
box.delete(array.get(bullish_fvg_max, array.indexof(bullish_fvg_min,
bx)))
for bx in bearish_fvg_max
if high > box.get_top(bx)
box.delete(bx)
box.delete(array.get(bearish_fvg_min, array.indexof(bearish_fvg_max,
bx)))
//-----------------------------------------------------------------------------}
//Premium/Discount/Equilibrium zones
//-----------------------------------------------------------------------------{
var premium = box.new(na, na, na, na
, bgcolor = color.new(premium_css, 80)
, border_color = na)
label.set_xy(eq_lbl, n, avg)
//-----------------------------------------------------------------------------}
// INDICATOR SETTINGS
swing_length = input.int(7, title = 'Swing High/Low Length', group = 'Settings',
minval = 1, maxval = 50)
history_of_demand_to_keep = input.int(50, title = 'History To Keep', minval = 5,
maxval = 50)
box_width = input.float(10, title = 'Supply/Demand Box Width', group = 'Settings',
minval = 1, maxval = 10, step = 0.5)
//
//END SETTINGS
//
//
//FUNCTIONS
//
else if swing_type == -1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HL'
else
label_text := 'LL'
label.new(bar_index - swing_length, array.get(array,0), text = label_text,
style=label.style_label_up, textcolor = swing_type_color, color =
color.new(swing_type_color, 100), size = size.tiny)
atr_threshold = atr7 * 2
okay_to_draw = true
for i = 0 to array.size(box_array) - 1
top = box.get_top(array.get(box_array, i))
bottom = box.get_bottom(array.get(box_array, i))
poi = (top + bottom) / 2
if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := array.get(value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2
//delete oldest box, and then create a new box and add it to the array
if box_type == 1 and okay_to_draw
box.delete( array.get(box_array, array.size(box_array) - 1) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right =
box_right, bottom = box_bottom, border_color = supply_outline_color,
bgcolor = ShowSR?supply_color:na, extend = extend.right, text = 'SELL
ZONE', text_halign = text.align_center, text_valign = text.align_center, text_color
= ShowSR?poi_label_color:na, text_size = size.small, xloc = xloc.bar_index))
if zone_type == 1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_top(array.get(box_array,i))
// if ta.crossover(close, level_to_break)
if close >= level_to_break
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) +
box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_color)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_center)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))
if zone_type == -1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_bottom(array.get(box_array,i))
// if ta.crossunder(close, level_to_break)
if close <= level_to_break
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) +
box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_color)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_center)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))
for i = 0 to array.size(box_array) - 1
box.set_right(array.get(box_array, i), bar_index + 100)
//
//END FUNCTIONS
//
//
//CALCULATIONS
//
// CALCULATE ATR
atr7 = ta.atr(50)
f_extend_box_endpoint(current_supply_box)
f_extend_box_endpoint(current_demand_box)
//ZIG ZAG
h = ta.highest(high, swing_length * 2 + 1)
l = ta.lowest(low, swing_length * 2 + 1)
f_isMin(len) =>
l == low[len]
f_isMax(len) =>
h == high[len]
f_drawLine() =>
_li_color = show_zigzag ? zigzag_color : color.new(#ffffff,100)
line.new(timeHigh - swing_length, lastHigh, timeLow - swing_length, lastLow,
xloc.bar_index, color=_li_color, width=2)
if dirUp
if f_isMin(swing_length) and low[swing_length] < lastLow
lastLow := low[swing_length]
timeLow := bar_index
line.delete(li)
li := f_drawLine()
li
if not dirUp
if f_isMax(swing_length) and high[swing_length] > lastHigh
lastHigh := high[swing_length]
timeHigh := bar_index
line.delete(li)
li := f_drawLine()
li
if f_isMin(swing_length) and low[swing_length] < lastHigh
lastLow := low[swing_length]
timeLow := bar_index
dirUp := true
li := f_drawLine()
if f_isMax(swing_length) and high[swing_length] > lastLow
lastHigh := high[swing_length]
timeHigh := bar_index
dirUp := false
li := f_drawLine()
li
// if barstate.islast
// label.new(x = bar_index + 10, y = close[1], text =
str.tostring( array.size(current_supply_poi) ))
// label.new(x = bar_index + 20, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 0))))
// label.new(x = bar_index + 30, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 1))))
// label.new(x = bar_index + 40, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 2))))
// label.new(x = bar_index + 50, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 3))))
// label.new(x = bar_index + 60, y = close[1], text =
str.tostring( box.get_bottom( array.get(current_supply_box, 4))))
bullish_engulfing = close[1] < open[1] and close > open and close > open[1]
rsi_below = rsi < rsi_index_param
decrease_over = close < close[candle_delta_length_param]
bearish_engulfing = close[1] > open[1] and close < open and close < open[1]
rsi_above = rsi > 100 - rsi_index_param
increase_over = close > close[candle_delta_length_param]
//last_signal := 'buy'
//if ShowSignal?bear:na and (disable_repeating_signals_param ? (last_signal !=
'sell' ? true : na) : true)
//if label_style == 'text bubble'
//label.new(bear ? bar_index : na, high, 'SELL', color=sell_label_color,
style=label.style_label_down, textcolor=label_text_color, size=label_size)
//else if label_style == 'triangle'
//label.new(bear ? bar_index : na, high, 'SELL', yloc=yloc.abovebar,
color=sell_label_color, style=label.style_triangledown, textcolor=TRANSPARENT,
size=label_size)
//else if label_style == 'arrow'
//label.new(bear ? bar_index : na, high, 'SELL', yloc=yloc.abovebar,
color=sell_label_color, style=label.style_arrowdown, textcolor=TRANSPARENT,
size=label_size)
//last_signal := 'sell'
bullishCandle = close >= open[1] and close[1] < open[1] //and high >= high[1] and
low <= low[1]
bearishCandle = close <= open[1] and close[1] > open[1] //and high > high[1] and
low < low[1]
// RSI integration
//rsiSource = input(title='rsiSource', defval=close)
//rsiLenghth = input(title='rsi length', defval=14)
//rsiOverBought = input(title='rsi overbought level', defval=70)
//rsiOverSold = input(title='rsi over sold level', defval=30)
//rsiOverBoughtThreshold=input(title="rsiOBThreshold level", type=input.integer,
defval=97)
//rsiOverSoldThreshold=input(title="rsiOSThreshold level", type=input.integer,
defval=18)
//get RSI value
//rsiValue = ta.rsi(rsiSource, rsiLenghth)
//isRSIOB = rsiValue >= rsiOverBought and rsiValue
//isRSIOS = rsiValue <= rsiOverSold and rsiValue
///////////SIGNAL//////////////
// Fibonacci Levels
fib_0 = input.float(0.236, "Fib Level 0")
fib_1 = input.float(0.79, "Fib Level 1")
// Plot RSI
//plot(rsi_value, "RSI", color=color.blue, linewidth=2)
//////////////////////////////////////////////////////////////////////////////////
//------------------------------Coding the
BOX---------------------------------------------------------//
//*************Asia Session
InSession(sessionTime, sessionTimeZone=syminfo.timezone) =>
not na(time(timeframe.period, sessionTime, sessionTimeZone))
// STEP 1:
// Define custom session trading times with inputs for *************Asia Session
sessionTime = input.session("0000-0655", title="Session time Tokyo")
sessionZone = input.string("UTC", title="Session time zone")
// STEP 2:
// See if the session is currently active and just started *************Asia
Session
inSession = InSession(sessionTime, sessionZone) and timeframe.isintraday
sessionStart = inSession and not inSession[1]
SessionEnd = inSession[1] and not inSession
// STEP 3:
// When a new session starts, set the session high and low to the data
// of the bar in the session. *************Asia Session
if sessionStart
sessionHighPrice := high
sessionLowPrice := low
sessionOpenPrice := open
// Else, during the session, track the highest high and lowest low
else if inSession
sessionHighPrice := math.max(sessionHighPrice, high)
sessionLowPrice := math.min(sessionLowPrice, low)
// STEP 4:
// When a session begins, make a new box for that session *************Asia Session
if ShowSession?sessionStart:na
sessionBox := box.new(left=bar_index, top=na, right=na, bottom=na,
border_width=boxBorderSize)
// STEP 5:
// During the session, update that session's existing box *************Asia Session
if ShowSession?inSession:na
box.set_top(sessionBox, sessionHighPrice)
box.set_bottom(sessionBox, sessionLowPrice)
box.set_right(sessionBox, bar_index + 1)
// See if bar closed higher than session open. When it did, make
// box green (and use red otherwise).
if close > sessionOpenPrice
box.set_bgcolor(sessionBox, upBoxColor)
box.set_border_color(sessionBox, upBorderColor)
else
box.set_bgcolor(sessionBox, downBoxColor)
box.set_border_color(sessionBox, downBorderColor)
extend = false
maxB = 300
colBl3 = colBl
colBr3 = colBr
nk = bar_index
//-----------------------------------------------------------------------------}
//UDT's
//-----------------------------------------------------------------------------{
type piv
float prc // price
int bix // bar_index
bool brk // broken
bool mit // mitigated
bool tak // taken
bool wic // wick
line lin
type boxBr
box bx
line ln
bool br
int dr
//-----------------------------------------------------------------------------}
//Variables
//-----------------------------------------------------------------------------{
var array< piv >aPivH = array.new< piv >(1, piv.new ())
var array< piv >aPivL = array.new< piv >(1, piv.new ())
var array<boxBr>aBoxBr = array.new<boxBr>(1, boxBr.new())
//-----------------------------------------------------------------------------}
//Methods - functions
//-----------------------------------------------------------------------------{
method n(float piv) => bool out = not na(piv)
method p(piv piv, float val) => float out = (100 / piv.prc * val) - 100
//-----------------------------------------------------------------------------}
//Execution
//-----------------------------------------------------------------------------{
ph = ta.pivothigh(len12345, len12345)
pl = ta.pivotlow (len12345, len12345)
if ph.n()
aPivH.unshift(piv.new(ph, n -len12345, false, false, false, false))
if pl.n()
aPivL.unshift(piv.new(pl, n -len12345, false, false, false, false))
bool bullcandle = false
bool bearcandle = false
for i = aPivH.size() -1 to 0
get = aPivH.get(i)
if not get.mit
if not get.brk
if close > get.prc
if not oW
get.brk := true
else
get.mit := true
if not oO and not get.wic
if high > get.prc and close < get.prc
bearcandle := true
get.wic := true
else
if close < get.prc
get.mit := true
if not oW and low < get.prc and close > get.prc
get.tak := true
get.wic := true
else
if close > get.prc
get.mit := true
if not oW and high > get.prc and close < get.prc
get.tak := true
//-----------------------------------------------------------------------------}
type store
float src
int n
type bar
float o = open
float h = high
float l = low
float c = close
int n = bar_index
float v = volume
type draw
line[] upln
line[] dnln
bar b = bar.new()
atrt = ta.atr(200)
vol() =>
math.min(atrt * 0.1, close * (0.1/100))
if showtrendline?pha:na
bool remove = false
var bool valid = false
upbin.unshift(store.new(b.h[len], b.n[len]))
if upbin.size() > 1
current = upbin.get(0)
before = upbin.get(1)
if current.src < before.src
if broken
valid := true
else
valid := false
if upbin.size() > 3
pastold = upbin.get(3)
pastcur = upbin.get(2)
now = upbin.get(1)
late = upbin.get(0)
if now.src < pastcur.src and now.src < pastold.src and late.src
< pastcur.src and late.src < pastold.src
valid := true
else
valid := false
else
valid := false
if valid
ln = d.upln.get(1)
for i = 0 to (b.n - before.n)
slope = ln.slope()
ln.set_x2(b.n[i])
ln.set_y2(ln.get_y2() - slope)
if low[i] > ln.get_y2()
remove := true
break
if remove
d.upln.get(0).delete()
d.upln.get(1).delete()
d.upln .clear()
upbin .clear()
broken := true
else
d.upln.get(0).delete()
d.upln.get(1).delete()
d.upln .clear ()
if d.upln.size() > 1
btm = d.upln.get(0)
top = d.upln.get(1)
if d.upln.size() > 1
slup = top.slope()
sldn = btm.slope()
top.set_x2(b.n)
top.set_y2(top.get_y2() + slup)
btm.set_x2(b.n)
btm.set_y2(btm.get_y2() + sldn)
if showtrendline?pla:na
bool remove = false
var bool valid = false
dnbin.unshift(store.new(b.l[len], b.n[len]))
if dnbin.size() > 1
current = dnbin.get(0)
before = dnbin.get(1)
if current.src > before.src
if broken
valid := true
else
valid := false
if dnbin.size() > 3
pastold = dnbin.get(3)
pastcur = dnbin.get(2)
now = dnbin.get(1)
late = dnbin.get(0)
else
valid := false
else
valid := false
if valid
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src , y2 = current.src , color = cup))
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 =
before.src + vol() * space, y2 = current.src + vol() * space, color = cup))
ln = d.dnln.get(1)
if remove
d.dnln.get(0).delete()
d.dnln.get(1).delete()
d.dnln .clear ()
dnbin .clear ()
broken := true
else
d.dnln.get(0).delete()
d.dnln.get(1).delete()
d.dnln .clear ()
if d.dnln.size() > 1
btm = d.dnln.get(0)
top = d.dnln.get(1)
if d.dnln.size() > 1
slup = top.slope()
sldn = btm.slope()
top.set_x2(b.n)
top.set_y2(top.get_y2() + slup)
btm.set_x2(b.n)
btm.set_y2(btm.get_y2() + sldn)
///////////////////////////////////////////
bool ontrendline = input.bool(true, "Auto-Trendlines", group = "Price Action
Concepts", inline = "133")
atr10 = ta.atr(200)/2
int autotrendlinesens = input.int(3, "", [1, 2, 3, 4, 5], group = "Price Action
Concepts", inline = "133")
length11111 = 5*autotrendlinesens+5
length111112 = 5*autotrendlinesens+5
astart = 2
aend = 0
bstart = 2
bend = 0
csrcsrcsrc = false
srcsrcsrc = close
//Conditions
upupup = ta.pivothigh(csrcsrcsrc ? srcsrcsrc : high, length11111, length11111)
dndndn = ta.pivotlow(csrcsrcsrc ? srcsrcsrc : low, length111112, length111112)
//Colors
color111 = #a53e48
color222 = #5b8d5e
//Plots
if showtrendline?ontrendline:na
line upupupper1 = line.new(n[n - a1 + length11111], upupup[n - a1]+atr10, n[n -
a2 + length11111], upupup[n - a2]+atr10, extend=extend.right,
color=color.new(color111, 10),width=1)
line lower11 = line.new(n[n - b1 + length111112], dndndn[n - b1], n[n - b2 +
length111112], dndndn[n - b2], extend=extend.right, color=color.new(color222, 10),
width=1)
line upupupper2 = line.new(n[n - a1 + length11111], upupup[n - a1], n[n - a2 +
length11111], upupup[n - a2], extend=extend.right, color=color.new(color111, 10),
width=1)
line lower21 = line.new(n[n - b1 + length111112], dndndn[n - b1]-atr10, n[n -
b2 + length111112], dndndn[n - b2]-atr10, extend=extend.right,
color=color.new(color222, 10), width=1)
linefill t = linefill.new(upupupper1, upupupper2, color.new(color111, 75))
linefill y = linefill.new(lower11, lower21, color.new(color222, 75))
line.delete(upupupper1[1])
line.delete(lower11[1])
line.delete(upupupper2[1])
line.delete(lower21[1])
////////////////////////////////////////// TRENDLINE
END //////////////////////////////
/////////////////////////////// ORDER BLOCK
FINDER /////////////////////////////////////
// Color Scheme
bullcolor = colors == 'DARK' ? color.rgb(249, 13, 13) : #1000ed
bearcolor = colors == 'DARK' ? color.blue : #ff0000
//int downcandles = 0
//for i = 1 to periods by 1
//downcandles += (close[i] < open[i] ? 1 : 0) // Determine color of subsequent
candles (must all be red to identify a valid Bearish OB)
//downcandles
//OB_bear = bearishOB and downcandles == periods and relmove // Identification
logic (green OB candle & subsequent green candles)
//OB_bear_high = OB_bear ? high[ob_period] : na // Determine OB upper limit (High)
//OB_bear_low = OB_bear ? usewicks ? low[ob_period] : open[ob_period] : na //
Determine OB lower limit (Open or Low depending on input)
//OB_bear_avg = (OB_bear_low + OB_bear_high) / 2 // Determine OB middle line
// Plotting
//line.delete(linebull2)
//linebull2 := line.new(x1=bar_index, y1=OB_bull_high, x2=bar_index - 1,
y2=OB_bull_high, extend=extend.left, color=bullcolor, style=line.style_dashed,
width=1)
//line.delete(linebull3)
//linebull3 := line.new(x1=bar_index, y1=OB_bull_low, x2=bar_index - 1,
y2=OB_bull_low, extend=extend.left, color=bullcolor, style=line.style_dashed,
width=1)
//linebull3
//line.delete(linebear2)
//linebear2 := line.new(x1=bar_index, y1=OB_bear_high, x2=bar_index - 1,
y2=OB_bear_high, extend=extend.left, color=bearcolor, style=line.style_dashed,
width=1)
//line.delete(linebear3)
//linebear3 := line.new(x1=bar_index, y1=OB_bear_low, x2=bar_index - 1,
y2=OB_bear_low, extend=extend.left, color=bearcolor, style=line.style_dashed,
width=1)
//linebear3
//////////////////////////////////////////////////////
// 0. Inputs
// 1. Types
// 2. Switches
// 3. Variables and arrays
// 4. Custom Functions
// 5. Execution
// 6. Constructs
///////////////////////////////////////////////////////
//////////////////////// SuperIchi //////////////////
offset = input(2,'Displacement')
//------------------------------------------------------------------------------
avg(src,length,mult)=>
atr = ta.atr(length)*mult
up = hl2 + atr
dn = hl2 - atr
upper = 0.,lower = 0.
upper := src[1] < upper[1] ? math.min(up,upper[1]) : up
lower := src[1] > lower[1] ? math.max(dn,lower[1]) : dn
os = 0,max = 0.,min = 0.
os := src > upper ? 1 : src < lower ? 0 : os[1]
spt = os == 1 ? lower : upper
max := ta.cross(src,spt) ? math.max(src,max[1]) : os == 1 ?
math.max(src,max[1]) : spt
min := ta.cross(src,spt) ? math.min(src,min[1]) : os == 0 ?
math.min(src,min[1]) : spt
math.avg(max,min)
//------------------------------------------------------------------------------
tenkan = avg(close,tenkan_len,tenkan_mult)
kijun = avg(close,kijun_len,kijun_mult)
senkouA = math.avg(kijun,tenkan)
senkouB = avg(close,spanB_len,spanB_mult)
//------------------------------------------------------------------------------
//tenkan_css = #1bd007
//kijun_css = #8d0292
//cloud_a = color.new(color.teal,80)
//cloud_b = color.new(color.red,80)
//chikou_css = #7b1fa2
//plot(SuperIchi?tenkan:na,'Tenkan-Sen',tenkan_css,linewidth =
1,display=display.none)
//plot(SuperIchi?kijun:na,'Kijun-Sen',kijun_css,linewidth = 2,display=display.none)
//plot(SuperIchi?(ta.crossover(tenkan,kijun) ? kijun :
na):na,'Crossover',color.rgb(0, 72, 255),4,plot.style_circles,display=display.none)
//plot(SuperIchi?(ta.crossunder(tenkan,kijun) ? kijun :
na):na,'Crossunder',color.rgb(255, 0, 0),4,plot.style_circles,display=display.none)
//plot(close,'Chikou',chikou_css,offset=-offset+1,display=display.none)
// REV ZONES
//
***********************************************************************************
*************************
////////////////////////////////////////////////
////////////Ichimoku Cloud"//////////////
///////////////////////////////////
////////////////////SUPERTREND////////////////////////
//@version=5
//indicator(title = "SuperTrend ATR + RSI", shorttitle = "SuperTrend ATR + RSI",
overlay = true)
//Mode
Factor=input.int(title="Super Trend", defval=4, minval=1,maxval = 100)
ATR=input.int(title="ATR", defval=7, minval=1,maxval = 100)
RSI = input.int(title="RSI", defval=7, minval=1, maxval = 100)
//RSI
srce = close,
ep = 2 * RSI - 1
auc = ta.ema( math.max( srce - srce[1], 0 ), ep )
adc = ta.ema( math.max( srce[1] - srce, 0 ), ep )
x1 = (RSI - 1) * ( adc * 70 / (100-70) - auc)
ub = x1 >= 0? srce + x1: srce + x1 * (100-70)/70
x2 = (RSI - 1) * ( adc * 30 / (100-30) - auc)
lb = x2 >= 0? srce + x2: srce + x2 * (100-30)/30
//Affichage
//////////////////////////////////
//Timezones
tz_incr = input.int(7, 'UTC (+/-)', group = 'Timezone', group = "EntryTime")
use_exchange = input(false, 'Use Exchange Timezone', group = 'EntryTime')
//Ranges Options
bg_transp = input.float(90, 'Range Area Transparency', group = 'Ranges Settings')
show_outline = input(false, 'Range Outline', group = 'Ranges Settings')
show_txt = input(false, 'Range Label', group = 'Ranges Settings')
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
//n = bar_index
sma
isValidResolution() => timeframe.isdwm == true or timeframe.period == "120" or
timeframe.period == "240" or timeframe.period == "180" or timeframe.period == "360"
? 0 : 1
isBelowHourValidResolution() => timeframe.isdwm == true or timeframe.period ==
"120" or timeframe.period == "240" or timeframe.period == "180" or timeframe.period
== "360" ? 0 : 1
var float y1 = na
var float y2 = na
var float stdev = na
var float r2 = na
y1 := 4 * sma - 3 * wma
y2 := 3 * wma - 2 * sma
//Session Vwap
get_vwap(session) =>
var float num = na
var float den = na
[num, den]
//Set line
set_line(session, y1, y2, session_css)=>
var line tl = na
if show_txt
lbl := label.new(t, max, session_name
, xloc = xloc.bar_time
, textcolor = session_css
, style = label.style_label_down
, color = color.new(color.white, 100)
, size = size.tiny)
box.set_top(bx, max)
box.set_rightbottom(bx, n, min)
if show_txt
label.set_xy(lbl, int(math.avg(t, time)), max)
//-----------------------------------------------------------------------------}
//Sessions
//-----------------------------------------------------------------------------{
tf = timeframe.period
//Ranges
if show_sesc and sesc_range and showSession
[max, min] = get_range(is_sesc, sesc_txt, sesc_css)
max_sesc := max
min_sesc := min
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
// Plot max/min
// Tính toán mức Fibonacci
fibonacci_target3 = max_sesc + (max_sesc - min_sesc) * 3.236
fibonacci_target2 = max_sesc + (max_sesc - min_sesc) * 1.618
fibonacci_target1 = max_sesc + (max_sesc - min_sesc) * 0.618
fibonacci_target3_down = min_sesc - (max_sesc - min_sesc) * 3.236
fibonacci_target2_down = min_sesc - (max_sesc - min_sesc) * 1.618
fibonacci_target1_down = min_sesc - (max_sesc - min_sesc) * 0.618
uptrend = -1
uptrend := close > max_sesc? 2 :close < min_sesc?1:0