cd_sweep&cisd_Cx.txt
Copy
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © cdikici71
// thanks to Rashid
//@version=5
indicator("cd_sweep&cisd_Cx",overlay=true,max_boxes_count = 500,max_lines_count = 100)
htf_opt = input.string(defval ="Auto", title="HTF Selection method:",options=["Auto","Fixed"],group ="HTF",inline="htf0")
htf_ = input.timeframe(defval= "60", title = "If Fixed HTF:",group ="HTF",inline="htf")
showhtf = input.bool(defval = true,title = "Show HTF boxes",group="HTF",inline="htf1")
width_box = input.int(defval=1,title="Border Width :",group="HTF",inline= "htf1")
style_box = input.string(defval=line.style_dotted,title= "Style:",options=[line.style_solid,line.style_dotted,line.style_dashed ],group="HTF",inline= "htf1")
indalert = input.bool(defval = true,title = "Use indicator alerts",group="HTF",inline="al",tooltip = "When using the TradingView alert feature, it should be inactive.")
looksmt = input.bool(defval = true,title = "Show SMT",group="HTF",inline="smt")
show_candle = input.bool(defval = true,title = "Show HTF Candle",group="HTF",inline="htf2")
show_rm = input.bool(defval = true,title = "Show Remaining Time",group="HTF",inline="htf3") // new 2608
dx = input(defval= 0 ,title = " Start from ahead",group="HTF",inline="htf4")
//////////////////////////
htfbias = input.timeframe(defval= "60", title = "HTF for bias",group ="BIAS")
plotbias= input.bool(defval = false,title='Plot Htf Bias',group ="BIAS" )
/////////////////
bull_color = input.color(defval = color.teal, title=" Bull Color " , inline="clr", group= "Colors")
bear_color = input.color(defval = color.red, title=" Bear Color " , inline="clr", group= "Colors")
range_color = input.color(defval=color.navy,title= "Range Color",inline="clr",group="Colors")
swept_color = input.color(defval= #ffeb3b32 ,title= "Sweep Box Color",inline="clr1",group="Colors")
key_txtcolor = input.color(defval= color.new(color.red,0),title= "Key Levels Text Color ",inline="clr1",group="Colors")
can_br_color = input.color(defval= color.black ,title= "Candles Border Color",inline="clr2",group="Colors")
csd_color = input.color(defval= color.navy ,title= "Cisd Line Color",inline="clr2",group="Colors")
show_keylvl = input.bool(defval=true,title="Show Key Levels",group="Time Frames => Key Levels",inline= "key")
ky = input(defval= 20 ,title = " Start from ahead",group="Time Frames => Key Levels",inline="key")
showkeytf1 = input.bool(defval =true , title = "",group ="Time Frames => Key Levels",inline="key1")
showkeytf2 = input.bool(defval =true , title = "",group ="Time Frames => Key Levels",inline="key2")
showkeytf3 = input.bool(defval =true , title = "",group ="Time Frames => Key Levels",inline="key3")
keytf1 = input.timeframe(defval= "1M", title = "Tf1 :",group= "Time Frames => Key Levels",inline="key1")
keytf2 = input.timeframe(defval= "1W", title = "Tf2 :",group= "Time Frames => Key Levels",inline="key2")
keytf3 = input.timeframe(defval= "1D", title = "Tf3 :",group= "Time Frames => Key Levels",inline="key3")
keytf1_clr = input.color(defval = color.gray, title="",group ="Time Frames => Key Levels",inline="key1")
keytf2_clr = input.color(defval = color.gray, title="",group ="Time Frames => Key Levels",inline="key2")
keytf3_clr = input.color(defval = color.gray, title="",group ="Time Frames => Key Levels",inline="key3")
//////////////////
show_cisd=input.bool(defval= true , title= "Show CISD table",group="Table")
//Turn Table On/Off
tableOn = input.bool(true, title="HTF Swept Table ", group="Table")
//Table Location & Size
i_font = input.string("small", "Text size", options = ["tiny", "small", "normal", "large", "huge"], group = "Table")
i_pos = input.string(position.middle_right, "Table Position", inline = "1", options = [position.middle_right, position.top_right,position.bottom_right,position.bottom_center], group = "Table")
i_bgcolor = color.teal
i_textcolor= color.white
/////
sym = syminfo.tickerid
tf = timeframe.period
///////////////////////////////////
f_look_tf(_tf)=>
dtf =
_tf == "1" ? "15" :
_tf == "2" ? "60" :
_tf == "3" ? "30" :
_tf == "5" ? "60" :
_tf == "15" ? "240":
_tf == "30" ? "720":
_tf == "60" ? "1D" :
_tf == "240"? "1W" :
_tf == "D" ? "1M" :
_tf == "W" ? "3M" : tf
dtf
htf = htf_opt == "Auto" ? f_look_tf(tf) : htf_
///////////////////////////////
var o0 = open
var h0 = high
var l0 = low
var h0bar = bar_index
var l0bar = bar_index
var h1bar = bar_index
var l1bar = bar_index
var h0t = time
var l0t = time
var t0 = time
var c0 = close
var h1 = high
var l1 = low
var t1 = time
var c1 = close
var o1 = open
var h2 = high
var l2 = low
var o2 = open
var c2 = close
var h3 = high
var l3 = low
var o3 = open
var c3 = close
var h_swept1 = false
var l_swept1 = false
if timeframe.change(htf)
t0 := time
o0 := open
h0 := high
l0 := low
if high >= h0
h0 := high
h0bar := bar_index
h0t := time
if low <= l0
l0 := low
l0bar := bar_index
l0t := time
c0:= close
if timeframe.change(htf)
o1 := o0[1]
h1 := h0[1]
l1 := l0[1]
t1 := t0[1]
c1 := close[1]
h2 := h1[1]
l2 := l1[1]
o2 := o1[1]
c2 := c1[1]
h3 := h2[1]
l3 := l2[1]
o3 := o2[1]
c3 := c2[1]
l1bar := l0bar[1]
h1bar := h0bar[1]
f_hswept(_sym,_tf)=>
if h0 > h1 and math.max(o0,c0) <= h1
_h_swept = true
f_lswept(_sym,_tf)=>
if l0 < l1 and math.min(o0,c0) >= l1
_l_swept = true
f_text(string _tf)=>
_text = str.tonumber(_tf) < 59 ? _tf + 'm' :
str.tonumber(_tf) > 59 ? 'h'+ str.tostring(math.floor(str.tonumber(_tf)/60)) : _tf
_text := _tf == "1D" ? "D" : _tf == "1W" ? "W" : _tf == "1M" ? "M" : _text
f_tfcon(_tf)=>
timeframe.in_seconds(_tf) / 60 >= timeframe.in_seconds(timeframe.period)/60
Getcolor(_sym,res, data1, i1 , data2,i2) =>
[op,cl] = request.security(_sym, res, [data1[i1],data2[i2]], lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
clr = op > cl ? color.new(bear_color, 0) : color.new(bull_color,0)
clr
add_to_array(arr, value) =>
array.unshift(arr, value)
if array.size(arr) > 100
array.pop(arr)
tf_ok(_htf) =>
_ok = tf == _htf or (timeframe.in_seconds(_htf) >= timeframe.in_seconds(timeframe.period)) or (str.tonumber(_htf) >= str.tonumber(timeframe.period)) or
(_htf == "1D" and str.tonumber(timeframe.period) <= 720 ) or
(_htf == "1W" and str.tonumber(timeframe.period) <= 720 ) or
(_htf == "1W" and timeframe.isdaily ) or
(_htf == "1M" and str.tonumber(timeframe.period) <= 720 ) or
(_htf == "1M" and timeframe.isdaily ) or
(_htf == "1M" and timeframe.isweekly ) or
(_htf == "3M" and timeframe.isweekly ) or
(_htf == "3M" and timeframe.isdaily ) or
(_htf == "3M" and timeframe.ismonthly ) or
(_htf == "3M" and timeframe.period == "240" )
RemainingTime(_TF) =>
//_TF = timeframe.period
if barstate.isrealtime
timeRemaining = (time_close(_TF) - timenow) / 1000
days = math.floor(timeRemaining / 86400)
hours = math.floor((timeRemaining - days * 86400) / 3600)
minutes = math.floor((timeRemaining - days * 86400 - hours * 3600) / 60)
seconds = math.floor(timeRemaining - days * 86400 - hours * 3600 - minutes * 60)
r = str.tostring(seconds, '00')
if minutes == 0
r:= str.tostring(minutes, '00') + ':' + r
r
if minutes > 0 or hours > 0 or days > 0
r := str.tostring(minutes, '00') + ':' + r
r
if hours > 0 or days > 0
r := str.tostring(hours, '00') + ':' + r
r
if days > 0
r := str.tostring(days) + 'D ' + r
r
r
else
'Market closed'
///////////////////////////////////////
/////////////////////////////////////////////////////////
var tablo3 = table.new(position = position.bottom_center,columns = 2,rows = 11,frame_color=color.new(color.teal,50),frame_width=2,border_color=color.new(color.teal,50),border_width=1)
if not str.contains(syminfo.tickerid,"replay")and show_rm
table.cell(tablo3,0,0,text="TF: " + RemainingTime(timeframe.period) ,text_color=color.white,bgcolor= #089981, text_size = i_font)
table.cell(tablo3,0,1,text=f_text(htf)+" : "+ RemainingTime(htf) ,text_color=color.white,bgcolor= #089981, text_size = i_font)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
h_swept = h0 > h1 and math.max(o0,c0) < h1 ? true : false
l_swept = l0 < l1 and math.min(o0,c0) > l1 ? true : false
if timeframe.change(htf)
h_swept1 := h_swept[1]
l_swept1 := l_swept[1]
//////////////////////
var lasthighswept = 0
var lastlowswept = 0
if showhtf
if f_tfcon(htf) and time == t0 and timeframe.period != htf
htf_box_color = c1 > o1 ? bull_color : c1 < o1 ? bear_color : range_color
boxhtf1=box.new(left = t1, top = h1 , right = t0, bottom = l1,xloc = xloc.bar_time,border_width = width_box,border_style = style_box,bgcolor =color.rgb(255, 255, 255, 100) , border_color = htf_box_color ,text = "",text_color= htf_box_color , text_size=size.tiny ,text_halign = text.align_right,text_valign = text.align_center )
if f_tfcon(htf) and timeframe.period != htf // live
htf_box_color = c0 > o0 ? bull_color : c0 < o0 ? bear_color : range_color
boxhtf=box.new(left = t0, top = high > h0 ? high : h0 , right = time+1, bottom =low < l0 ? low : l0,xloc = xloc.bar_time,border_width = width_box,border_style = style_box,bgcolor =color.rgb(255, 255, 255, 100) , border_color = htf_box_color ,text = "",text_color= htf_box_color , text_size=size.tiny ,text_halign = text.align_right,text_valign = text.align_center )
box.delete(boxhtf[1])
xcolor = swept_color
if f_tfcon(htf) and timeframe.period != htf and h0 > h1 and close < h1 and o0 < h1
boxhtf4=box.new(left = t0, top = h0 , right = time, bottom = h1, xloc = xloc.bar_time,border_width = 1,border_style = line.style_dotted,bgcolor =xcolor , border_color =color.new(color.gray,70) )
lasthighswept := t0
if t0 == lasthighswept[1]
box.delete(boxhtf4[1])
if f_tfcon(htf) and timeframe.period != htf and l0 < l1 and close > l1 and o0 > l1
boxhtf5=box.new(left = t0, top = l1, right = time, bottom = l0, xloc = xloc.bar_time,border_width = 1,border_style = line.style_dotted,bgcolor =xcolor , border_color =color.new(color.gray,70) )
lastlowswept := t0
if t0 == lastlowswept[1]
box.delete(boxhtf5[1])
var bull_level = high
var bear_level = low
var bull_index = bar_index
var bear_index = bar_index
var bucisdg=array.new_line()
var becisdg=array.new_line()
var bull_alarm = false
var bear_alarm = false
var xcisd = false
var ycisd =false
////////////////////////////////////////
up = close > open
dw = close < open
eq = close == open
//////////////////////////////////////bull cisd
if low == l0 and low < l1
if (dw[0] or eq[0]) and (up[1] or eq[1]) and not (eq[0] and eq[1])
bull_level := open
bull_index := bar_index
add_to_array(bucisdg, line.new(x1= bull_index,y1= bull_level,x2= bull_index+4,y2= bull_level,color=csd_color,width = 2,style=line.style_dotted))
else
for i = 2 to 10
if low[i] < low
break
if (up[i] or eq[i]) and dw[i-1]
bar = i - 1
bull_level := open[bar]
bull_index := bar_index - bar
for j= bar to 0
if open[j] > bull_level and dw[j]
bull_level := open[j]
bull_index := bar_index-j
if bull_level < open and not (close > open)
bull_level := open
bull_index := bar_index
if bull_level < open and (close > open)
bull_level := high
bull_index := bar_index
add_to_array(bucisdg, line.new(x1= bull_index,y1= bull_level,x2= bull_index+4,y2= bull_level,color=csd_color,width = 2,style=line.style_dotted))
break
///////////////////////////////////////////////////////// bear cisd
if high == h0 and high > h1
if (up[0] or eq[0]) and (dw[1] or eq[1]) and not (eq[0] and eq[1])
bear_level := open
bear_index := bar_index
add_to_array( becisdg,line.new(x1= bear_index,y1= bear_level,x2= bear_index+4,y2= bear_level,color=csd_color,width = 2,style=line.style_dotted))
else
for i = 2 to 10
if high[i] > high
break
if (dw[i] or eq[i]) and up[i-1]
ybar = i - 1
bear_level := open[ybar]
bear_index := bar_index - ybar
for j= ybar to 0
if open[j] < bear_level and up[j]
bear_level := open[j]
bear_index := bar_index-j
if bear_level > open and not (close < open)
bear_level := open
bear_index := bar_index
if bear_level > open and (close < open)
bear_level := low
bear_index := bar_index
add_to_array( becisdg,line.new(x1= bear_index,y1= bear_level,x2= bear_index+4,y2= bear_level,color=csd_color,width = 2,style=line.style_dotted))
break
/////////////////////////////
if high >= h0[1]
ycisd := false
if low <= l0[1]
xcisd := false
/////////////////////////////cisd kesişim
xbull = close[1] > bull_level and (l_swept[1] or (l1 <= l0 and l_swept1)) and xcisd == false and bar_index-1 >= bull_index
if xbull
bucisd =box.new(left= bull_index, top= bull_level,right= bar_index-1, bottom= bull_level,border_color = csd_color,border_width = 1,text="cisd+",text_color = csd_color,text_size=size.tiny,text_halign = text.align_center,text_valign = text.align_bottom)
bull_alarm := true
if bull_alarm
if not indalert
alert(sym + ',' + timeframe.period + ',🟢 Long Alarm"}', alert.freq_once_per_bar )
bull_level := 1000000.0
xcisd := true
if array.size(bucisdg) > 0
dbox = array.get(bucisdg, 0)
line.delete(dbox)
array.remove(bucisdg,0)
if close[1] > bull_level and not (l_swept[1] or (l1 <= l0 and l_swept1)) and xcisd == false and bar_index-1 >= bull_index //added 0209
bucisd =box.new(left= bull_index, top= bull_level,right= bar_index-1, bottom= bull_level,border_color = color.new(csd_color,50),border_width = 1,text="cisd+",text_color = color.new(csd_color,50),text_size=size.tiny,text_halign = text.align_center,text_valign = text.align_bottom)
bull_level := 1000000.0
if array.size(bucisdg) > 1
for i = array.size(bucisdg) - 1 to 1
dbox = array.get(bucisdg, i)
line.delete(dbox)
array.remove(bucisdg,i)
///////////
xbear = close[1] < bear_level and (h_swept[1] or (h1>=h0 and h_swept1)) and ycisd == false and bar_index-1 >= bear_index
if xbear
becisd =box.new(left= bear_index, top= bear_level,right= bar_index-1, bottom= bear_level,border_color =csd_color,border_width = 1,text="cisd-",text_color=csd_color,text_size=size.tiny,text_halign = text.align_center,text_valign = text.align_top)
bear_alarm := true
if bear_alarm
if not indalert
alert(sym +',' + timeframe.period + ',🔴 Short Alarm', alert.freq_once_per_bar)
bear_level := 0.0
ycisd := true
if array.size(becisdg) > 0
dbox = array.get(becisdg, 0)
line.delete(dbox)
array.remove(becisdg,0)
if close[1] < bear_level and not (h_swept[1] or (h1 >=h0 and h_swept1)) and ycisd == false and bar_index-1 >= bear_index //added 0209
becisd =box.new(left= bear_index, top= bear_level,right= bar_index-1, bottom= bear_level,border_color = color.new(csd_color,50),border_width = 1,text="cisd-",text_color=color.new(csd_color,50),text_size=size.tiny,text_halign = text.align_center,text_valign = text.align_top)
bear_level := 0.0
if array.size(becisdg)>1
for i = array.size(becisdg) - 1 to 1
dbox = array.get(becisdg, i)
line.delete(dbox)
array.remove(becisdg,i)
/////////////
plotshape( bull_alarm, title = "Bullish Cisd",style=shape.arrowup,location=location.belowbar,color=bull_color,size=size.tiny,text="",textcolor = color.green,offset = -1)
plotshape( bear_alarm, title = "Bearish Cisd",style=shape.arrowdown,location=location.abovebar,color=bear_color,size=size.tiny,text="",textcolor = color.red,offset = -1)
/////////////////////////////////////////////
sw1=line.new(na,na,na,na)
sw2=line.new(na,na,na,na)
xxo = o0 , xxc = c0 , xxh = h0 , xxl = l0
xxo1 = o1 , xxc1 = c1 , xxh1 = h1 , xxl1 = l1
xxo2 = o2 , xxc2 = c2 , xxh2 = h2 , xxl2 = l2
xxo3 = o3 , xxc3 = c3 , xxh3 = h3 , xxl3 = l3
if show_candle
if barstate.islast
line.delete(sw1[1])
line.delete(sw2[1])
bl0=box.new(left=bar_index+dx+18 ,top= xxc , right= bar_index+dx +20 , bottom = xxo, bgcolor = Getcolor(sym,htf,open,0,close,0), border_color = can_br_color , text = f_text(htf) , text_size = size.tiny ,text_valign = text.align_center , text_halign = text.align_center,text_color = color.white )
wup=box.new(left=bar_index+dx+19 ,top= xxh , right= bar_index+dx +19 , bottom = math.max(xxo,xxc) , border_color = can_br_color,border_width =1)
wdw=box.new(left=bar_index+dx+19 ,top= xxl , right= bar_index+dx +19 , bottom = math.min(xxo,xxc) , border_color = can_br_color,border_width =1)
bl01=box.new(left=bar_index+dx+15 ,top= xxc1 , right= bar_index+dx +17 , bottom = xxo1, bgcolor = Getcolor(sym,htf,open,1,close,1), border_color = can_br_color , text = f_text(htf), text_size = size.tiny ,text_valign = text.align_center , text_halign = text.align_center,text_color = color.white )
wup1=box.new(left=bar_index+dx+16 ,top= xxh1 , right= bar_index+dx +16 , bottom = math.max(xxo1,xxc1) , border_color = can_br_color,border_width =1)
wdw1=box.new(left=bar_index+dx+16 ,top= xxl1 , right= bar_index+dx +16 , bottom = math.min(xxo1,xxc1) , border_color = can_br_color,border_width =1)
bl02=box.new(left=bar_index+dx+12 ,top= xxc2 , right= bar_index+dx +14 , bottom = xxo2, bgcolor = Getcolor(sym,htf,open,2,close,2), border_color = can_br_color , text = f_text(htf) , text_size = size.tiny ,text_valign = text.align_center , text_halign = text.align_center,text_color = color.white )
wup2=box.new(left=bar_index+dx+13 ,top= xxh2 , right= bar_index+dx +13 , bottom = math.max(xxo2,xxc2) , border_color = can_br_color,border_width =1)
wdw2=box.new(left=bar_index+dx+13 ,top= xxl2 , right= bar_index+dx +13 , bottom = math.min(xxo2,xxc2) , border_color = can_br_color,border_width =1)
bl03=box.new(left=bar_index+dx+9 ,top= xxc3 , right= bar_index+dx +11 , bottom = xxo3, bgcolor = Getcolor(sym,htf,open,3,close,3), border_color = can_br_color , text = f_text(htf) , text_size = size.tiny ,text_valign = text.align_center , text_halign = text.align_center,text_color = color.white )
wup3=box.new(left=bar_index+dx+10 ,top= xxh3 , right= bar_index+dx +10 , bottom = math.max(xxo3,xxc3) , border_color = can_br_color,border_width =1)
wdw3=box.new(left=bar_index+dx+10 ,top= xxl3 , right= bar_index+dx +10 , bottom = math.min(xxo3,xxc3) , border_color = can_br_color,border_width =1)
box.delete(bl0[1])
box.delete(bl01[1])
box.delete(bl02[1])
box.delete(bl03[1])
box.delete(wup[1])
box.delete(wdw[1])
box.delete(wup1[1])
box.delete(wdw1[1])
box.delete(wup2[1])
box.delete(wdw2[1])
box.delete(wup3[1])
box.delete(wdw3[1])
if xxh > xxh1 and xxh1 > math.max(xxo,xxc) and h_swept
sw1 := line.new(x1 = bar_index+dx+16, y1 = xxh1 , x2= bar_index+dx +19,y2 =xxh1, color = bear_color , style = line.style_solid,width = 2)
line.delete(sw1[1])
if xxl < xxl1 and xxl1 < math.min(xxo,xxc) and l_swept
sw2 := line.new(x1 = bar_index+dx+16, y1 = xxl1 , x2= bar_index+dx +19,y2 =xxl1, color = bull_color, style = line.style_solid,width = 2)
line.delete(sw2[1])
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Assets
ok1 = input.bool(defval=true,title="",group = "Assets",inline="s1")
ok2 = input.bool(defval=true,title="",group = "Assets",inline="s2")
ok3 = input.bool(defval=true,title="",group = "Assets",inline="s3")
ok4 = input.bool(defval=true,title="",group = "Assets",inline="s4")
ok5 = input.bool(defval=true,title="",group = "Assets",inline="s5")
ok6 = input.bool(defval=true,title="",group = "Assets",inline="s6")
s1=input.symbol(defval = "PEPPERSTONE:EURUSD", title = "1 : " , group = "Assets",inline="s1")
s2=input.symbol(defval = "PEPPERSTONE:GBPUSD", title = "2 : " , group = "Assets",inline="s2")
s3=input.symbol(defval = "PEPPERSTONE:NAS100", title = "3 : " , group = "Assets",inline="s3")
s4=input.symbol(defval = "PEPPERSTONE:US500", title = "4 : " , group = "Assets",inline="s4")
s5=input.symbol(defval = "PEPPERSTONE:XAUUSD", title = "5 : " , group = "Assets",inline="s5")
s6=input.symbol(defval = "PEPPERSTONE:XAGUSD", title = "6 : " , group = "Assets",inline="s6")
/// corele Assets
ss1=input.symbol(defval = "PEPPERSTONE:GBPUSD", title = "Cor: " , group = "Assets",inline="s1")
ss2=input.symbol(defval = "PEPPERSTONE:EURUSD", title = "Cor: " , group = "Assets",inline="s2")
ss3=input.symbol(defval = "PEPPERSTONE:US500", title = "Cor: " , group = "Assets",inline="s3")
ss4=input.symbol(defval = "PEPPERSTONE:NAS100", title = "Cor: " , group = "Assets",inline="s4")
ss5=input.symbol(defval = "PEPPERSTONE:XAGUSD", title = "Cor: " , group = "Assets",inline="s5")
ss6=input.symbol(defval = "PEPPERSTONE:XAUUSD", title = "Cor: " , group = "Assets",inline="s6")
s1_bull = request.security(s1,tf,xbull, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s1_bear = request.security(s1,tf,xbear, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s2_bull = request.security(s2,tf,xbull, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s2_bear = request.security(s2,tf,xbear, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s3_bull = request.security(s3,tf,xbull, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s3_bear = request.security(s3,tf,xbear, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s4_bull = request.security(s4,tf,xbull, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s4_bear = request.security(s4,tf,xbear, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s5_bull = request.security(s5,tf,xbull, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s5_bear = request.security(s5,tf,xbear, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s6_bull = request.security(s6,tf,xbull, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s6_bear = request.security(s6,tf,xbear, lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
//////
if s1_bull and indalert and ok1
alert( s1 + ',' + timeframe.period + ',🟢 Long Alarm"}', alert.freq_once_per_bar)
if s2_bull and indalert and ok2
alert( s2 + ',' + timeframe.period + ',🟢 Long Alarm"}', alert.freq_once_per_bar)
if s3_bull and indalert and ok3
alert( s3 + ',' + timeframe.period + ',🟢 Long Alarm"}', alert.freq_once_per_bar)
if s4_bull and indalert and ok4
alert( s4 + ',' + timeframe.period + ',🟢 Long Alarm"}', alert.freq_once_per_bar)
if s5_bull and indalert and ok5
alert( s5 + ',' + timeframe.period + ',🟢 Long Alarm"}', alert.freq_once_per_bar)
if s6_bull and indalert and ok6
alert( s6 + ',' + timeframe.period + ',🟢 Long Alarm"}', alert.freq_once_per_bar)
if s1_bear and indalert and ok1
alert(s1 + ',' + timeframe.period + ',🔴 Short Alarm"}', alert.freq_once_per_bar)
if s2_bear and indalert and ok2
alert(s2 + ',' + timeframe.period + ',🔴 Short Alarm"}', alert.freq_once_per_bar)
if s3_bear and indalert and ok3
alert(s3 + ',' + timeframe.period + ',🔴 Short Alarm"}', alert.freq_once_per_bar)
if s4_bear and indalert and ok4
alert(s4 + ',' + timeframe.period + ',🔴 Short Alarm"}', alert.freq_once_per_bar)
if s5_bear and indalert and ok5
alert(s5 + ',' + timeframe.period + ',🔴 Short Alarm"}', alert.freq_once_per_bar)
if s6_bear and indalert and ok6
alert(s6 + ',' + timeframe.period + ',🔴 Short Alarm"}', alert.freq_once_per_bar)
s1_h_swept = ok1 ? request.security(s1,tf,f_hswept(s1,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true) : na
s2_h_swept = request.security(s2,tf,f_hswept(s2,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s3_h_swept = request.security(s3,tf,f_hswept(s3,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s4_h_swept = request.security(s4,tf,f_hswept(s4,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s5_h_swept = request.security(s5,tf,f_hswept(s5,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s6_h_swept = request.security(s6,tf,f_hswept(s5,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s1_l_swept = request.security(s1,tf,f_lswept(s1,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s2_l_swept = request.security(s2,tf,f_lswept(s2,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s3_l_swept = request.security(s3,tf,f_lswept(s3,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s4_l_swept = request.security(s4,tf,f_lswept(s4,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s5_l_swept = request.security(s5,tf,f_lswept(s5,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
s6_l_swept = request.security(s6,tf,f_lswept(s6,htf), lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true)
// Compose a screener message
swept_label = ' ' + f_text(htf) + ' Swept \n ------------------------\n'
swept_label := s1_h_swept and ok1 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s1)) +" "+ f_text(htf) +" 🔴 " + '\n' : swept_label
swept_label := s2_h_swept and ok2 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s2)) +" "+ f_text(htf) +" 🔴 " + '\n' : swept_label
swept_label := s3_h_swept and ok3 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s3)) +" "+ f_text(htf) +" 🔴 " + '\n' : swept_label
swept_label := s4_h_swept and ok4 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s4)) +" "+ f_text(htf) +" 🔴 " + '\n' : swept_label
swept_label := s5_h_swept and ok5 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s5)) +" "+ f_text(htf) +" 🔴 " + '\n' : swept_label
swept_label := s6_h_swept and ok6 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s6)) +" "+ f_text(htf) +" 🔴 " + '\n' : swept_label
swept_label := s1_l_swept and ok1 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s1)) +" "+ f_text(htf) +" 🟢 " + '\n' : swept_label
swept_label := s2_l_swept and ok2 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s2)) +" "+ f_text(htf) +" 🟢 " + '\n' : swept_label
swept_label := s3_l_swept and ok3 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s3)) +" "+ f_text(htf) +" 🟢 " + '\n' : swept_label
swept_label := s4_l_swept and ok4 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s4)) +" "+ f_text(htf) +" 🟢 " + '\n' : swept_label
swept_label := s5_l_swept and ok5 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s5)) +" "+ f_text(htf) +" 🟢 " + '\n' : swept_label
swept_label := s6_l_swept and ok6 ? swept_label + "⚠️ "+str.tostring(syminfo.ticker(s6)) +" "+ f_text(htf) +" 🟢 " + '\n' : swept_label
//Plot Label
dataTable = table.new(position = i_pos, columns=1, rows=3, bgcolor=#00000000)
if tableOn and barstate.islast
table.cell(table_id=dataTable, column=0, row=0, text=swept_label, height=0, text_color=i_textcolor, text_halign=text.align_left, text_valign= text.align_center, text_size=i_font, bgcolor=i_bgcolor)
///////////////////////////////////////////////////
f_tb2_text(bool _alarm) =>
_textt = _alarm ? "🔥" : "🕒"
var tablo2 = table.new(position = position.bottom_right,columns = 3,rows = 11,frame_color=i_textcolor,frame_width=2,border_color=i_textcolor,border_width=1)
if show_cisd
table.cell(tablo2,0,0,text="CISD" ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,1,0,text="Bullish" ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,2,0,text="Bearish" ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
if ok1
table.cell(tablo2,0,1,text= syminfo.ticker(s1) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,1,1,text= f_tb2_text(s1_bull) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,2,1,text= f_tb2_text(s1_bear) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
if ok2
table.cell(tablo2,0,2,text= syminfo.ticker(s2) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,1,2,text= f_tb2_text(s2_bull) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,2,2,text= f_tb2_text(s2_bear) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
if ok3
table.cell(tablo2,0,3,text= syminfo.ticker(s3) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,1,3,text= f_tb2_text(s3_bull) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,2,3,text= f_tb2_text(s3_bear) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
if ok4
table.cell(tablo2,0,4,text= syminfo.ticker(s4) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,1,4,text= f_tb2_text(s4_bull) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,2,4,text= f_tb2_text(s4_bear) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
if ok5
table.cell(tablo2,0,5,text= syminfo.ticker(s5) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,1,5,text= f_tb2_text(s5_bull) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,2,5,text= f_tb2_text(s5_bear) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
if ok6
table.cell(tablo2,0,6,text= syminfo.ticker(s6) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,1,6,text= f_tb2_text(s6_bull) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
table.cell(tablo2,2,6,text= f_tb2_text(s6_bear) ,text_color=i_textcolor,bgcolor= i_bgcolor, text_size = i_font)
bull_alarm := false
bear_alarm := false
//////////////////////////////////bias
var bo0 = open
var bh0 = high
var bl0 = low
var bt0 = time
var bc0 = close
var bh1 = high
var bl1 = low
var bt1 = time
var bc1 = close
var bo1 = open
var bh2 = high
var bl2 = low
var bo2 = open
var bc2 = close
var bias = 0
if timeframe.change(htfbias)
bt0 := time
bo0 := open
bh0 := high
bl0 := low
if high >= bh0
bh0 := high
if low <= bl0
bl0 := low
bc0:= close
if timeframe.change(htfbias)
bo1 := bo0[1]
bh1 := bh0[1]
bl1 := bl0[1]
bt1 := bt0[1]
bc1 := close[1]
bh2 := bh1[1]
bl2 := bl1[1]
bo2 := bo1[1]
bc2 := bc1[1]
if timeframe.change(htfbias)
bias:= 0
if bc1 > bh2
bias := 1
if bc1 < bl2
bias := -1
if bc1 < bh2 and bc1 > bl2 and bh1 > bh2 and bl1 > bl2
bias := -1
if bc1 > bl2 and bc1 < bh2 and bh1 < bh2 and bl1 < bl2
bias := 1
if bh1 <= bh2 and bl1 >= bl2
if bc2 > bo2
bias := 1
else
bias := -1
plotshape(plotbias, 'htf Bias', style = shape.square, size = size.tiny, location = location.bottom, color = bias == 1 ? bull_color :bias == -1 ? bear_color :bias == 0 ? color.gray : na)
///////////SMT
var lb1=label.new(na,na)
var lb2=label.new(na,na)
csym = str.contains(sym,s1) and ok1 ? ss1 : str.contains(sym,s2)and ok2 ? ss2 : str.contains(sym,s3) and ok3 ? ss3 : str.contains(sym,s4) and ok4 ? ss4 : str.contains(sym,s5) and ok5 ? ss5 : str.contains(sym,s6)and ok6 ? ss6 : sym
par_ok = csym != sym
c_l = request.security(csym,htf,low < low[1] , lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true) ? true : false
c_h = request.security(csym,htf,high > high[1], lookahead=barmerge.lookahead_on ,ignore_invalid_symbol = true) ? true : false
da = ta.atr(20)*1.25
tf_ok = timeframe.in_seconds(tf) < timeframe.in_seconds(htf)
if looksmt and tf_ok and par_ok
if ( (l0 < l1 and c_l == false) or ( l0 >= l1 and c_l) )
lb1 := label.new(x= l0t , y= l0 - da ,xloc=xloc.bar_time,text= "SMT",color=color.teal,style = label.style_label_up,textcolor=color.white,size =i_font )
label.delete(lb1[1])
else
label.delete(lb1[1])
if looksmt and tf_ok and par_ok
if ( (h0 > h1 and c_h == false) or ( h0 <= h1 and c_h) )
lb2 :=label.new(x= h0t , y= h0 + da,xloc=xloc.bar_time,text= "SMT",color=color.teal,style = label.style_label_down,textcolor=color.white,size =i_font)
label.delete(lb2[1])
else
label.delete(lb2[1])
////////////////////////////////////////////////////////////////////////////////
f_live_mini(_htf)=>
var _o0 = open
var _h0 = high
var _l0 = low
var _t0 = time
var _c0 = close
var _h1 = high
var _l1 = low
var _t1 = time
var _c1 = close
var _o1 = open
if timeframe.change(_htf)
_t0 := time
_o0 := open
_h0 := high
_l0 := low
if high >= _h0
_h0 := high
if low <= _l0
_l0 := low
if timeframe.change(_htf)
_o1 := _o0[1]
_h1 := _h0[1]
_l1 := _l0[1]
_t1 := _t0[1]
_c1 := close[1]
_c0:= close
[_h1,_l1,_c1,_o1,_t1,_h0,_l0,_c0,_o0,_t0]
///////////////////////////////////////////////////////key levels
[tf1h1,tf1l1,tf1c1,tf1o1,tf1t1,wh0,wl0,wc0,wo0,wt0] = f_live_mini(keytf1)
[tf2h1,tf2l1,tf2c1,tf2o1,tf2t1,dh0,dl0,dc0,do0,dt0] = f_live_mini(keytf2)
[tf3h1,tf3l1,tf3c1,tf3o1,tf3t1,h40,l40,c40,o40,t40] = f_live_mini(keytf3)
nx=ky
dt = timeframe.in_seconds(tf)*1000
if show_keylvl and barstate.islast
if tf_ok(keytf1) and showkeytf1
add1h = wh0 >= tf1h1 ? "(-)" : ""
add1l = wl0 <= tf1l1 ? "(-)" : ""
wbox1 = box.new(left = t0, top = tf1h1 , right = time + nx * dt,bottom = tf1h1,xloc= xloc.bar_time, border_color = keytf1_clr,bgcolor = color.new(color.gray,100),text = "p "+f_text(keytf1)+" h "+ add1h, text_color = key_txtcolor,text_valign = text.align_bottom,text_halign = text.align_right,text_size = size.tiny,border_style = line.style_dotted)
wbox2 = box.new(left = t0, top = tf1l1 , right = time + nx * dt,bottom = tf1l1,xloc= xloc.bar_time, border_color = keytf1_clr,bgcolor = color.new(color.gray,100),text = "p "+f_text(keytf1)+" l "+ add1l, text_color = key_txtcolor,text_valign = text.align_top,text_halign = text.align_right,text_size = size.tiny,border_style = line.style_dotted)
wbox3 = box.new(left = t0, top = wo0 , right = time + nx * dt,bottom = wo0 ,xloc= xloc.bar_time, border_color = keytf1_clr,bgcolor = color.new(color.gray,100),text = f_text(keytf1)+" open ", text_color = key_txtcolor,text_valign = text.align_bottom,text_halign = text.align_right,text_size = size.tiny,border_style = line.style_dotted)
box.delete(wbox1[1])
box.delete(wbox2[1])
box.delete(wbox3[1])
if tf_ok(keytf2) and showkeytf2
add2h = dh0 >= tf2h1 ? "(-)" : ""
add2l = dl0 <= tf2l1 ? "(-)" : ""
dbox1 = box.new(left = t0, top = tf2h1 , right = time + nx * dt,bottom = tf2h1,xloc= xloc.bar_time, border_color = keytf2_clr,bgcolor = color.new(color.gray,100),text = "p "+f_text(keytf2)+" h "+ add2h, text_color = key_txtcolor,text_valign = text.align_top,text_halign = text.align_right,text_size = size.tiny,border_style = line.style_dotted)
dbox2 = box.new(left = t0, top = tf2l1 , right = time + nx * dt,bottom = tf2l1,xloc= xloc.bar_time, border_color = keytf2_clr,bgcolor = color.new(color.gray,100),text = "p "+f_text(keytf2)+" l "+ add2l, text_color = key_txtcolor,text_valign = text.align_bottom,text_halign = text.align_right,text_size = size.tiny,border_style = line.style_dotted)
dbox3 = box.new(left = t0, top = do0 , right = time + nx * dt,bottom = do0 ,xloc= xloc.bar_time, border_color = keytf2_clr,bgcolor = color.new(color.gray,100),text = f_text(keytf2)+" open ", text_color = key_txtcolor,text_valign = text.align_top,text_halign = text.align_right,text_size = size.tiny,border_style = line.style_dotted)
box.delete(dbox1[1])
box.delete(dbox2[1])
box.delete(dbox3[1])
if tf_ok(keytf3) and showkeytf3
add3h = h40 >= tf3h1 ? "(-)" : ""
add3l = l40 <= tf3l1 ? "(-)" : ""
h4box1 = box.new(left = t0, top = tf3h1 , right = time + nx * dt,bottom = tf3h1,xloc= xloc.bar_time, border_color = keytf3_clr,bgcolor = color.new(color.gray,100),text = "p "+f_text(keytf3)+" h "+ add3h, text_color = key_txtcolor,text_valign = text.align_bottom,text_halign = text.align_right,text_size = size.tiny,border_style = line.style_dotted)
h4box2 = box.new(left = t0, top = tf3l1 , right = time + nx * dt,bottom = tf3l1,xloc= xloc.bar_time, border_color = keytf3_clr,bgcolor = color.new(color.gray,100),text = "p "+f_text(keytf3)+" l "+ add3l, text_color = key_txtcolor,text_valign = text.align_top,text_halign = text.align_right,text_size = size.tiny,border_style = line.style_dotted)
h4box3 = box.new(left = t0, top = o40 , right = time + nx * dt,bottom = o40 ,xloc= xloc.bar_time, border_color = keytf3_clr,bgcolor = color.new(color.gray,100),text = f_text(keytf3)+" open ", text_color = key_txtcolor,text_valign = text.align_bottom,text_halign = text.align_right,text_size = size.tiny,border_style = line.style_dotted)
box.delete(h4box1[1])
box.delete(h4box2[1])
box.delete(h4box3[1])
Show all 714 lines