Binocular Trend Emoji
Binocular Trend Emoji
0 at
https://mozilla.org/MPL/2.0/
// © Jib1979
//@version=5
indicator("Binocular", overlay=true, max_bars_back = 5000)
//Binocular
//Settlement
// === INPUTS
useDaily = input(true, title='Use Daily Data to Calculate HV (default), otherwise
chart TF')
LookBack = input.int(21, minval=1)
annual = input.int(252, minval=1)
DaystoExpire_ = input.int(defval=0, minval=0, title='Calender Days to Expiry
(0=Auto, default)')
src_111 = input(close, title='Settlement Source (close=default)')
sLength_ = input.int(1, minval=1, title='Settlement Volume Weighted Average Length
(1=Use end of day)')
//
showset = input(title="Settlement", defval=true, group='Settlement')
stddev1 = input(true, title='Display 1x Standard Deviation Levels',
group='Settlement')
stddev2 = input(false, title='Display 2x Standard Deviation
Levels',group='Settlement')
stddev3 = input(false, title='Display 3x Standard Deviation
Levels',group='Settlement')
pivotNow = input(false, title='Display Only Todays Deviation
Levels',group='Settlement')
showstd1 = input(title="Dev1 Labels", defval=true, group='Settlement')
showstd2 = input(title="Dev2 Labels", defval=false,group='Settlement')
showstd3 = input(title="Dev3 Labels", defval=false, group='Settlement')
//
// === /INPUTs
dodgerblue = #1E90FF
//
// Test for new Daily Session or start of new month for Daily.
sLength = timeframe.isintraday ? sLength_ : 1
nstart = request.security(syminfo.tickerid, 'D', bar_index, barmerge.gaps_off,
barmerge.lookahead_on)
start1 = request.security(syminfo.tickerid, 'D', time, barmerge.gaps_off,
barmerge.lookahead_on)
first = request.security(syminfo.tickerid, 'D', ta.valuewhen(barstate.islast, time,
0), barmerge.gaps_off, barmerge.lookahead_on)
change_1 = ta.change(start1)
newDay = nohist ? false : timeframe.isintraday ? change_1 : dayofmonth(time) <
dayofmonth(time[1])
SettleM = plot(not nohist and showset and (not pivotNow or firstDay) and not newDay
? settlement : na, color=color.new(#ec186d, 0), title='Settlement', linewidth=2,
style=plot.style_linebr)
stdhv05u = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not
newDay ? settlement + stdhv05 : na, color=color.new(color.orange, 20), title='+0.5
SD', linewidth=1, style=plot.style_linebr)
stdhv05d = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not
newDay ? settlement - stdhv05 : na, color=color.new(color.orange, 20), title='-0.5
SD', linewidth=1, style=plot.style_linebr)
stdhv07u = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not
newDay ? settlement + stdhv07 : na, color=color.new(color.red, 20), title='+0.7
SD', linewidth=1, style=plot.style_linebr)
stdhv07d = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not
newDay ? settlement - stdhv07 : na, color=color.new(color.red, 20), title='-0.7
SD', linewidth=1, style=plot.style_linebr)
stdhv1u = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not newDay
? settlement + stdhv1 : na, color=color.new(color.lime, 20), title='+1 SD',
linewidth=3, style=plot.style_linebr)
stdhv1d = plot(not nohist and stddev1 and (not pivotNow or firstDay) and not newDay
? settlement - stdhv1 : na, color=color.new(color.lime, 20), title='-1 SD',
linewidth=3, style=plot.style_linebr)
//Show Settlement
if showset
settlement = label.new(start1, settlement, text='Settlement',
xloc=xloc.bar_time, textcolor=color.new(#ec186d,0), style=label.style_none)
label.delete(settlement[1])
if stddev1
if Stdhv05u
Stdhv05u = label.new(start1, Stdhv05u, text='+0.5', xloc=xloc.bar_time,
textcolor=color.new(color.orange,0), style=label.style_none)
label.delete(Stdhv05u[1])
if Stdhv05d
Stdhv05d = label.new(start1, Stdhv05d, text='-0.5', xloc=xloc.bar_time,
textcolor=color.new(color.orange,0), style=label.style_none)
label.delete(Stdhv05d[1])
if Stdhv07u
Stdhv07u = label.new(start1, Stdhv07u, text='+0.7', xloc=xloc.bar_time,
textcolor=color.new(color.red,0), style=label.style_none)
label.delete(Stdhv07u[1])
if Stdhv07d
Stdhv07d = label.new(start1, Stdhv07d, text='-0.7', xloc=xloc.bar_time,
textcolor=color.new(color.red,0), style=label.style_none)
label.delete(Stdhv07d[1])
if Stdhv1u
Stdhv1u = label.new(start1, Stdhv1u, text='+1.0', xloc=xloc.bar_time,
textcolor=color.new(color.lime,10), style=label.style_none)
label.delete(Stdhv1u[1])
if Stdhv1d
Stdhv1d = label.new(start1, Stdhv1d, text='-1.0', xloc=xloc.bar_time,
textcolor=color.new(color.lime,10), style=label.style_none)
label.delete(Stdhv1d[1])
//
//
//Buy Sell
// ======================================================================
// INPUTS
// ======================================================================
// =============================== MA ===================================
gr2 = "???????????????? MA ????????????????"
mab1 = input.bool(false,"",inline="1",group=gr2)
mat1 = input.string(title = "", defval = "SMA", options=["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"],inline="1", group=gr2)
mas1 = input.source(hlc3,title="",inline="1",group=gr2)
mal1 = input.int(21,title="",inline="1",group=gr2)
c1 = color.new(color.lime,0)
mab2 = input.bool(false,"",inline="2",group=gr2)
mat2 = input.string(title = "", defval = "SMA", options=["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"],inline="2", group=gr2)
mas2 = input.source(hlc3,title="",inline="2",group=gr2)
mal2 = input.int(44,title="",inline="2",group=gr2)
c2 = color.new(color.red,0)
mab3 = input.bool(false,"",inline="3",group=gr2)
mat3 = input.string(title = "", defval = "SMA", options=["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"],inline="3", group=gr2)
mas3 = input.source(hlc3,title="",inline="3",group=gr2)
mal3 = input.int(100,title="",inline="3",group=gr2)
c3 = color.new(color.blue,0)
tbgc = color.new(color.black,0)
brc = color.new(color.white,0)
tw = input.int(2,"",inline="1",group=tab)
label.delete(_offsetLabel[1])
line.delete(li[1])
if bs == -1
txt = "SELL BELLOW : " + str.tostring(int(math.round(Price,2)))
li := line.new(index, Price, bar_index+5, Price,
extend=extend.right,color=color.new(color.red,0),style=line.style_dashed)
le := label.new(bar_index + 10, Price, text= txt,
style=label.style_none,textcolor=color.new(color.red,0),textalign=text.align_left)
label.delete(le[1])
line.delete(li[1])
pl = 0.0
pl := pos == 1 ? math.max((high - Price),nz(pl[1])) : pos == -1 ?
math.max((Price - low),nz(pl[1])) : 0
plp = math.round(math.abs(pl*100/Price),2)
htc = color.new(color.white,0)
btc = color.new(color.white,0)
bg = bs == 1 ? color.new(#025d06,0) : color.new(#b60000,0)
if barstate.islast and plt
table.cell(table_id = testTable, column = 0, row = 0, text =
"Entry",text_color=htc,text_size=_size)
table.cell(table_id = testTable, column = 1, row = 0, text =
"SL",text_color=htc,text_size=_size)
table.cell(table_id = testTable, column = 0, row = 1, text =
str.tostring(int(math.round(Price,2))), bgcolor =
bg,text_color=btc,text_size=_size)
table.cell(table_id = testTable, column = 1, row = 1, text =
str.tostring(int(math.round(sl,2))), bgcolor = bg,text_color=btc,text_size=_size)
//
//
//EMA
showema = input(title='Show EMA', defval=true)
len1 = input.int(30, minval=1, title='MA1')
len2 = input.int(35, minval=1, title='MA2')
len3 = input.int(40, minval=1, title='MA3')
len4 = input.int(45, minval=1, title='MA4')
len5 = input.int(50, minval=1, title='MA5')
len6 = input.int(60, minval=1, title='MA6')
longCond = bool(na)
shortCond = bool(na)
longCond := ma1 > ma6 and ma2 > ma6 and ma3 > ma6 and ma4 > ma6 and ma5 > ma6
shortCond := ma1 < ma6 and ma2 < ma6 and ma3 < ma6 and ma4 < ma6 and ma5 < ma6
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1
//
//Price Volume Trend
signalType = input.string(title='Signal Smoothing Type', defval='SMA',
options=['EMA', 'SMA'])
signalLength = input(title='Signal Smoothing Length', defval=21)
src420 = input(title='Source', defval=close)
highlightCrossovers = input(title='Highlight Crossovers ?', defval=false)
applyFilling = input(title='Apply Ribbon Filling ?', defval=true)
//
calculation(float bfr) =>
time_limit = timestamp(2222, 1, 31, 23, 00)
display = timenow < time_limit
rsi1 = ta.rsi(close,25)
rsi2 = ta.rsi(close,55)
length = 10
mult = 2.2
useClose = true
BUY = dir == 1 and ta.pvt > signal_1 and rsi1 > rsi2
SELL = dir == -1 and ta.pvt < signal_1 and rsi1 < rsi2
label.new(bar_index,close,text='',size=size.normal,color=color.new(color.green,100)
,yloc=yloc.belowbar,style=label.style_label_up,textcolor=color.new(color.white,100)
)
pos := 0
index := bar_index
buy:=true
sell:=false
sell1:=false
en := high*(1+bfr/100)
HighVal:=high*(1+bfr/100)
Stoploss:=math.min(low[1],low)
diff = (high-low[1])*2
Target1:=high+diff
Target2:=Target1+diff
Target3:=Target2+diff
Target4:=Target3+diff
label.new(bar_index,close,text='',size=size.normal,color=color.new(color.red,100),y
loc=yloc.abovebar,style=label.style_label_down,textcolor=color.new(color.white,100)
)
pos := 0
index := bar_index
sell:=true
buy:=false
buy1:=false
en := low*(1-bfr/100)
LowVal:=low*(1-bfr/100)
Stoploss:=math.max(high[1],high)
diff = (high[1]-low)*2
Target1:=low-diff
Target2:=Target1-diff
Target3:=Target2-diff
Target4:=Target3-diff
label.new(bar_index,close,text='',size=size.tiny,color=color.new(color.green,100),y
loc=yloc.belowbar,style=label.style_triangleup,textcolor=color.new(color.white,0))
pos := 1
buy1:=true
sell1:=false
label.new(bar_index,close,text='',size=size.tiny,color=color.new(color.red,100),ylo
c=yloc.abovebar,style=label.style_triangledown,textcolor=color.new(color.white,0))
pos := -1
buy1:=false
sell1:=true
[bs,pos,index,en,Stoploss,Target1,Target2,Target3]
[v1,v2,v3]
[bs,pos,index,e,sl,t1,t2,t3] = calculation(bfr)
DefineLabel(eb,pos,index,e,color.new(#019a66,0),'🤞EN')
DefineLabel(slb,pos,index,sl,color.new(color.red,0),'🥵SL')
DefineLabel(tb1,pos,index,t1,color.new(color.green,0),'😁TG1')
DefineLabel(tb2,pos,index,t2,color.new(color.green,0),'😂TG2')
DefineLabel(tb3,pos,index,t3,color.new(color.green,0),'🤣TG3')
[_TablePos,_size] = tablelocation(TablePos,size)
var testTable = table.new(_TablePos, 3, 2, bgcolor = tbgc, frame_color = brc,
frame_width = tw, border_color = brc, border_width = tw)
entry(plt,testTable,_size,bs,pos,index,e,sl)
//
===================================================================================
=====================================
[v1,v2,v3] = vwapc(src,"D","W","M")
signal() =>
rsi1 = ta.rsi(close,25)
rsi2 = ta.rsi(close,55)
length = 10
mult = 2.2
useClose = true
[_mtf_p,_mtf_s] = tablelocation(mtf_p,mtf_s)
var mtf_Table = table.new(_mtf_p, 2, 20, border_color = color.new(color.white,0),
border_width = 1)
//Supertrend
showst = input(title='Supertrend', defval=false)
//
//EMA200
Ema_Len = input(50)
Ema_Len2 = input(200)
EMA50 = request.security(syminfo.tickerid, "D", ta.ema(close[1],Ema_Len),
barmerge.gaps_off, barmerge.lookahead_on)
EMA200 = request.security(syminfo.tickerid, "D", ta.ema(close[1],Ema_Len2),
barmerge.gaps_off, barmerge.lookahead_on)
EMA200_15 = request.security(syminfo.tickerid, "15", ta.ema(close[1],Ema_Len2),
barmerge.gaps_off, barmerge.lookahead_on)
if showemalb
var EMA50Label = label.new(x = bar_index, y = EMA50, style =
label.style_label_left, color = color.new(color.blue,0), textcolor = color.white,
text = "Daily 50")
label.set_xy(EMA50Label, x = bar_index, y = EMA50)
var EMA200_15Label = label.new(x = bar_index, y = EMA200_15, style =
label.style_label_left, color = color.new(color.blue,0), textcolor = color.white,
text = "15Min 200")
label.set_xy(EMA200_15Label, x = bar_index, y = EMA200_15)
var EMA200Label = label.new(x = bar_index, y = EMA200, style =
label.style_label_left, color = color.new(color.blue,0), textcolor = color.white,
text = "Daily 200")
label.set_xy(EMA200Label, x = bar_index, y = EMA200)
//
//BarColor
ap = hlc3
esa = ta.ema(ap, n1)
d1 = ta.ema(math.abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d1)
tci = ta.ema(ci, n2)
wt1 = tci
wt2 = ta.sma(wt1, 4)
//RSI INPUTS
len = input.int(14, minval=1, title="Length ? ?", inline="001", group="rsi inputs")
src_101 = input.source(close, "Source ? ?", inline="002", group="rsi inputs")
tfTxt(x)=>
//adds abbreviation next to timeframe value
out = x
if not str.contains(x, "S") and not str.contains(x, "M") and
not str.contains(x, "W") and not str.contains(x, "D")
if str.tonumber(x)%60 == 0
out := str.tostring(str.tonumber(x)/60)+"H"
else
out := x + "m"
out
if barstate.islast
f_fillCellText(RSITable, 1, 1, RSITF1, "")
f_fillCellText(RSITable, 2, 1, RSITF5, "")
f_fillCellText(RSITable, 3, 1, RSITF15, "")
f_fillCellText(RSITable, 4, 1, RSITF60, "")
f_fillCellText(RSITable, 5, 1, RSITF4H, "")
f_fillCellText(RSITable, 6, 1, RSITF1D, "")
//
//Demand and Supply
//SETTINGS
//
// INDICATOR SETTINGS
swing_length = input.int(10, title = 'Swing High/Low Length', group = 'Settings',
minval = 1, maxval = 50)
history_of_demand_to_keep = input.int(20, title = 'History To Keep', minval = 5,
maxval = 50)
box_width = input.float(2.5, 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 = atr * 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 = supply_color, extend = extend.right, text = 'SUPPLY',
text_halign = text.align_center, text_valign = text.align_center, text_color =
poi_label_color, 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
atr = 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))))
//
//Trend Bar
ShowTrendIndi = input(true, title='Show Trend Indicator')
PACLen = input.int(50, minval=2, title='EMA ')
src_YGS = input(close, title='Source for Wave centre EMA')
////