Binocular Final v1
Binocular Final v1
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 stddev1 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 showset 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 showset 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 showset 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 showset 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 showset 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 showset 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
if stddev1
if settlement
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 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
vwap = ta.vwap(close)
rsi1 = ta.rsi(close,25)
rsi2 = ta.rsi(close,55)
length = 22
mult = 3.0
useClose = true
BUY = dir == 1 and rsi1 > rsi2 and ta.pvt > signal_1 and close > settlement
SELL = dir == -1 and rsi2 > rsi1 and ta.pvt < signal_1 and close < settlement
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,Target4]
[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() =>
vwap = ta.vwap(close)
rsi1 = ta.rsi(close,25)
rsi2 = ta.rsi(close,55)
length = 22
mult = 3.0
useClose = true
BUY = dir == 1 and rsi1 > rsi2 and ta.pvt > signal_1 and close > settlement
SELL = dir == -1 and rsi2 > rsi1 and ta.pvt < signal_1 and close < settlement
[BUY,SELL]
[_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)
//
//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)
plot(0, color=color.new(color.gray, 0))