// This source code is subject to the terms of the Mozilla Public License 2.
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)
nohist = nstart <= math.max(sLength, LookBack) + 1
change_1 = ta.change(start1)
newDay = nohist ? false : timeframe.isintraday ? change_1 : dayofmonth(time) <
dayofmonth(time[1])
// Calculate Annualised Volatility
hv = 0.0
stdev_1 = ta.stdev(math.log(src_111 / src_111[1]), LookBack)
security_1 = request.security(syminfo.tickerid, 'D', stdev_1 * math.sqrt(annual),
barmerge.gaps_off, barmerge.lookahead_on)
stdev_2 = ta.stdev(math.log(src_111 / src_111[1]), LookBack)
hv_ = useDaily ? security_1 : stdev_2 * math.sqrt(annual)
hv := newDay ? hv_ : nz(hv[1], hv_)
hinow = high
hinow := newDay ? high : high > hinow[1] ? high : hinow[1]
lonow = low
lonow := newDay ? low : low < lonow[1] ? low : lonow[1]
prevhi = ta.valuewhen(newDay, hinow[1], 0)
prevlo = ta.valuewhen(newDay, lonow[1], 0)
// get the Daily Settlement
valuewhen_1 = ta.valuewhen(start1[1] <= time, src_111, 0)
vwma_1 = ta.vwma(src_111[1], sLength)
settlement = sLength == 1 ? valuewhen_1 : vwma_1
settlement := newDay ? settlement : nz(settlement[1], open[1])
firstDay = dayofmonth(start1) == dayofmonth(first) and month(start1) ==
month(first) and year(start1) == year(first)
stdhv = 0.0
DaystoExpire = DaystoExpire_ == 0 ? timeframe.isintraday ? useDaily ? 1 :
math.min(annual, 1440 / timeframe.multiplier) : LookBack : DaystoExpire_
stdhv := newDay ? settlement * hv * math.sqrt(DaystoExpire / annual) : nz(stdhv[1])
// calculate StdDev lines ratios.
stdhv05 = stdhv * 0.5
stdhv07 = stdhv * 0.7
stdhv1 = stdhv
Stdhv05u = settlement + stdhv05
Stdhv05d = settlement - stdhv05
Stdhv07u = settlement + stdhv07
Stdhv07d = settlement - stdhv07
Stdhv1u = settlement + stdhv1
Stdhv1d = settlement - stdhv1
// Plot the StdDev Levels for all Days.
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
// ======================================================================
tgrp = "🚀🚀🚀🔴🔷🔶🔵⌛⏰ TRADE SETUP ⏰⌛🔵🔶🔷🔴🚀🚀🚀"
bfr = input.float(0.02,title = "Entry Buffer",inline = "1",group = tgrp)
tm = input.session("Last Trade", title = "", options = ["Last Trade","All
Trade"],inline = "1",group = tgrp)
eb = input.bool(true,title = "Entry",inline = "2",group = tgrp)
tb1 = input.bool(true,title = "Target 1",inline = "2",group = tgrp)
tb2 = input.bool(true,title = "Target 2",inline = "2",group = tgrp)
tb3 = input.bool(true,title = "Target 3",inline = "2",group = tgrp)
slb = input.bool(true,title = "Stop Loss",inline = "2",group = tgrp)
// ============================== VWAP ==================================
gr1 =   "🚀🚀🚀🔴🔷🔶🔵⌛⏰ VWAP ⏰⌛🔵🔶🔷🔴🚀🚀🚀"
vwapd   = input.bool(true,"",inline="1",group=gr1)
vwapw   = input.bool(false,"",inline="1",group=gr1)
vwapm   = input.bool(false,"",inline="1",group=gr1)
src =   input.source(hlc3,title="Source",inline="1",group=gr1)
dvc =   ta.vwap(close) > close ? color.new(color.fuchsia,0) : color.new(#32CD32,0)
wvc =   color.new(#44f513,0)
mvc =   color.new(color.yellow,0)
// =============================== 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)
// ============================= TABLE ==================================
tab = "🚀🚀🚀🔴🔷🔶🔵⌛⏰ TABLE ⏰⌛🔵🔶🔷🔴🚀🚀🚀"
plt = input.bool(true,title="P/L Table",inline="1",group=tab)
TablePos = input.string(title="Table Location", defval="Bottom Right",
options=["Top Right", "Middle Right", "Bottom Right",
              "Top Center", "Middle Center", "Bottom Center", "Top Left",     "Middle
Left",   "Bottom Left"], inline="1", group=tab)
size = input.string(title="Table Size", defval="Auto", options=["Auto",    "Huge",
"Large", "Normal", "Small", "Tiny"], inline="1", group=tab)
tbgc = color.new(color.black,0)
brc = color.new(color.white,0)
tw = input.int(2,"",inline="1",group=tab)
// =============== EXPORT FUNCTION
===================================================================================
======
tablelocation(string TablePos,string size) =>
    _TablePos= TablePos== "Top Right"     ? position.top_right:
           TablePos== "Middle Right" ? position.middle_right:
           TablePos== "Bottom Right" ? position.bottom_right:
           TablePos== "Top Center"    ? position.top_center:
           TablePos== "Middle Center"? position.middle_center:
           TablePos== "Bottom Center"? position.bottom_center:
           TablePos== "Top Left"     ? position.top_left:
           TablePos== "Middle Left" ? position.middle_left:position.bottom_left
    _size= size == "Auto" ? size.auto: size == "Huge" ? size.huge:
       size == "Large"? size.large: size == "Normal"? size.normal:
       size == "Small"? size.small: size.tiny
    [_TablePos,_size]
DefineLabel(bool but,int pos,int index,float Price,color color_,string text_)=>
    var label _offsetLabel=na
    line li = na
    label msg = na
    if barstate.islast and index > 0 and pos != 0 and but
        li := line.new(index, Price, bar_index+5, Price,
extend=extend.right,color=color_)
        _offsetLabel := label.new(bar_index + 10, Price,text = text_+" : "+
str.tostring(int(math.round(Price,2))),color=color_,textcolor=color_,style=label.st
yle_none)
    label.delete(_offsetLabel[1])
    line.delete(li[1])
entry(bool plt,table testTable,string _size,int bs,int pos,int index,float
Price,float sl) =>
    label le = na
    line li = na
    if barstate.islast and pos == 0
        if bs == 1
            txt = "BUY ABOVE : " + str.tostring(int(math.round(Price,2)))
            li := line.new(index, Price, bar_index+5, Price,
extend=extend.right,color=color.new(color.lime,0),style=line.style_dashed)
            le := label.new(bar_index + 10, Price, text= txt,
style=label.style_none,textcolor=color.new(color.lime,0),textalign=text.align_left)
        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')
ma1   =   ta.ema(close,   len1)
ma2   =   ta.ema(close,   len2)
ma3   =   ta.ema(close,   len3)
ma4   =   ta.ema(close,   len4)
ma5   =   ta.ema(close,   len5)
ma6   =   ta.ema(close,   len6)
plot(showema ? ma1 : na, title='MA1', color=close > ma1 ?   color.new(color.green, 0)
: color.new(color.red,0))
plot(showema ? ma2 : na, title='MA2', color=close > ma2 ?
color.new(color.green,0) : color.new(color.red, 0))
plot(showema ? ma3 : na, title='MA3', color=close > ma3 ?
color.new(color.green,0) : color.new(color.red, 0))
plot(showema ? ma4 : na, title='MA4', color=close > ma4 ?   color.new(color.green, 0)
: color.new(color.red,0))
plot(showema ? ma5 : na, title='MA5', color=close > ma5 ?   color.new(#44f513, 0) :
color.new(#ff0000,0), linewidth=3, style=plot.style_line)
plot(showema ? ma6 : na, title='MA6', color=close > ma6 ?   color.new(color.green, 0)
: color.new(color.red,0))
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)
signal_1 = signalType == 'EMA' ? ta.ema(ta.pvt, signalLength) : ta.sma(ta.pvt,
signalLength)
//
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
    atr = mult * ta.atr(length)
    longStop = (useClose ? ta.highest(close, length) : ta.highest(length)) - atr
    longStopPrev = nz(longStop[1], longStop)
    longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) :
longStop
    shortStop = (useClose ? ta.lowest(close, length) : ta.lowest(length)) + atr
    shortStopPrev = nz(shortStop[1], shortStop)
    shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) :
shortStop
    var int dir = 1
    dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
    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
    var   bool   buy=false
    var   bool   sell = false
    var   bool   buy1=false
    var   bool   sell1 = false
    var float HighVal=na
    var float LowVal = na
    var   float Stoploss=na
    var   float Target1 = na
    var   float Target2 = na
    var   float Target3 = na
    var   float Target4 = na
    var   index = 0
    var   pos = 0
    var   bs = 0
    var   en = 0.0
    if    display
          if BUY and BUY[1]==false and buy==false
              bs := 1
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
        if SELL and SELL[1]==false and sell==false
            bs := -1
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
        if buy and high>HighVal and buy1==false
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
        if sell and low<LowVal and 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]
// ============== VWAP + MA Calculation
===================================================================================
vwapc(float src,string tf1,string tf2,string tf3) =>
    time_limit = timestamp(2222, 1, 31, 23, 00)
    display = timenow < time_limit
    v1 = display ? ta.vwap(src, timeframe.change(tf1)) : na
    v2 = display ? ta.vwap(src, timeframe.change(tf2)) : na
    v3 = display ? ta.vwap(src, timeframe.change(tf3)) : na
    [v1,v2,v3]
ma(float source,simple int length,string type) =>
    time_limit = timestamp(2222, 1, 31, 23, 00)
    display = timenow < time_limit
    if display
         switch type
             "SMA" => ta.sma(source, length)
             "EMA" => ta.ema(source, length)
             "SMMA (RMA)" => ta.rma(source, length)
             "WMA" => ta.wma(source, length)
             "VWMA" => ta.vwma(source, length)
    else
         na
// ============== IMPORT FUNCTIONS
===================================================================================
=
[bs,pos,index,e,sl,t1,t2,t3] = calculation(bfr)
plot(tm == "All Trade" and eb and pos != 0 ? e : na, title = "Entry",
color=color.new(#019a66,0), style = plot.style_linebr)
plot(tm == "All Trade" and tb1 and pos != 0 ? t1 : na, title = "TG
1",color=color.new(color.lime,0), style = plot.style_linebr)
plot(tm == "All Trade" and tb2 and pos != 0 ? t2 : na, title = "TG
2",color=color.new(color.lime,0), style = plot.style_linebr)
plot(tm == "All Trade" and tb3 and pos != 0 ? t3 : na, title = "TG
3",color=color.new(color.lime,0), style = plot.style_linebr)
plot(tm == "All Trade" and slb and pos != 0 ? sl : na, title =
"SL",color=color.new(color.red,0), style = plot.style_linebr)
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")
plot(vwapd?v1:na, title = "Daily VWAP", color=dvc, linewidth=2)
plot(vwapw?v2:na, title = "Weekly VWAP", color=wvc, linewidth=2)
plot(vwapm?v3:na, title = "Monthly VWAP", color=mvc, linewidth=2)
plot(mab1 ? ma(mas1,mal1,mat1) : na, title = "MA 1", color=c1)
plot(mab2 ? ma(mas2,mal2,mat2) : na, title = "MA 2", color=c2)
plot(mab3 ? ma(mas3,mal3,mat3) : na, title = "MA 3", color=c3)
//
===================================================================================
=====================================
signal()   =>
    vwap   = ta.vwap(close)
    rsi1   = ta.rsi(close,25)
    rsi2   = ta.rsi(close,55)
    length = 22
    mult = 3.0
    useClose = true
    atr = mult * ta.atr(length)
    longStop = (useClose ? ta.highest(close, length) : ta.highest(length)) - atr
    longStopPrev = nz(longStop[1], longStop)
    longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) :
longStop
    shortStop = (useClose ? ta.lowest(close, length) : ta.lowest(length)) + atr
    shortStopPrev = nz(shortStop[1], shortStop)
    shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) :
shortStop
    var int dir = 1
    dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
    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_t = input.bool(true,title="P/L Table",inline="1", group = "MTF SIGNAL")
mtf_p = input.string(title="Table Location", defval="Top Right", options=["Top
Right", "Middle Right", "Bottom Right",
              "Top Center", "Middle Center", "Bottom Center", "Top Left",   "Middle
Left",   "Bottom Left"], inline="1", group = "MTF SIGNAL")
mtf_s = input.string(title="Table Size", defval="Auto", options=["Auto",   "Huge",
"Large", "Normal", "Small", "Tiny"], inline="1", group = "MTF SIGNAL")
tf_1 = input.timeframe('3', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_2 = input.timeframe('5', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_3 = input.timeframe('15', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_4 = input.timeframe('30', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_5 = input.timeframe('45', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_6 = input.timeframe('60', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_7 = input.timeframe('120', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_8 = input.timeframe('180', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_9 = input.timeframe('240', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_10 = input.timeframe('D', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_11 = input.timeframe('W', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
tf_12 = input.timeframe('M', title = "Time Frame", inline = "1", group = "MTF
SIGNAL")
[_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)
plotrow1(n, tf) =>
    [buy,sell] = request.security_lower_tf(syminfo.tickerid, tf, signal())
    b = array.get(buy,array.size(buy)-1)
    s = array.get(sell,array.size(sell)-1)
    table.cell(table_id = mtf_Table, column = 0, row = n, text = str.tostring(tf),
text_color = color.new(color.white,0), text_size = _mtf_s, bgcolor = b ?
color.new(color.lime,0) : s ? color.new(color.red,0) : color.new(color.gray,0))
plotrow(n, tf) =>
    [b,s] = request.security(syminfo.tickerid, tf, signal())
    table.cell(table_id = mtf_Table, column = 0, row = n, text = str.tostring(tf),
text_color = color.new(color.white,0), text_size = _mtf_s, bgcolor = b ?
color.new(color.lime,0) : s ? color.new(color.red,0) : color.new(color.gray,0))
if barstate.islast and mtf_t
    table.cell(table_id = mtf_Table, column = 0, row = 0, text =
str.tostring(syminfo.ticker), text_color = color.new(color.white,0), text_size =
_mtf_s, bgcolor = color.new(#60040c,0))
    plotrow1(1, tf_1),plotrow(2, tf_2),plotrow(3, tf_3),plotrow(4, tf_4),plotrow(5,
tf_5),plotrow(6, tf_6)
    plotrow(7, tf_7),plotrow(8, tf_8),plotrow(9, tf_9),plotrow(10,
tf_10),plotrow(11, tf_11),plotrow(12, tf_12)
//
//Supertrend
showst = input(title='Supertrend', defval=false)
Mult_11 = input.float(2.2, minval=0, maxval=10)
Period_11 = input.int(10, minval=1, maxval=100)
[Trailings, Trend] = ta.supertrend(Mult_11, Period_11)
linecolor = Trend == 1 ? color.red : color.lime
plot(showst ? Trailings : na, color=linecolor, linewidth=1, title='SuperTrend')
//
//EMA200
showema200 = input(title='EMA 200', defval=true)
len200 = input.int(200, minval=1, title='MA6')
ma200 = ta.ema(close, len200)
plot(showema200 ? ma200 : na, title='EMA200', color=close > ma200 ?
color.new(#AAFF00, 0) : color.new(#EE4B2B,0), linewidth=2)
//
//one day moving average
showema_ = input(title='Daily EMA', defval=true)
showemalb = input(title="Daily EMA Labels", defval=true)
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)
plot(showema_ ? EMA50 : na, title='Daily EMA50',
color=color.new(#ff8103,0),style=plot.style_line, linewidth=2)
plot(showema_ ? EMA200 : na, title='Daily EMA200',
color=color.new(#ff8103,0),style=plot.style_line, linewidth=2)
plot(showema_ ? EMA200_15 : na, title='15Min EMA200',
color=color.new(#ff8103,0),style=plot.style_line, linewidth=2)
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
n1 = input(10, 'Channel Length')
n2 = input(21, 'Average Length')
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))
barcolor(ta.cross(wt1, wt2) ? wt2 - wt1 > 0 ? color.new(color.aqua,0) :
color.new(#00FF00, 0) : na)
//