Lal Online
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adidasanlal

//@version=5
indicator('Lal Online', shorttitle='Lal Online', overlay=true)

getSeries(e, timeFrame) =>
    request.security(syminfo.tickerid, timeFrame, e, lookahead=barmerge.lookahead_on)


//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//Supertrend-1 Begins
Periods = input(title='ATR Period-1', defval=10)
src = input(hl2, title='Source')
Multiplier = input.float(title='ATR Multiplier-1', step=0.1, defval=3.0)
changeATR = input(title='Change ATR Calculation Method ?', defval=false)
showsignals = input(title='Show Buy/Sell Signals ?', defval=true)
highlighting = input(title='Highlighter On/Off ?', defval=true)
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
up = src - Multiplier * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = src + Multiplier * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title='Up Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.green, 0))
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title='UpTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))
plotshape(buySignal and showsignals ? up : na, title='Buy', text='', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.white, 0))
dnPlot = plot(trend == 1 ? na : dn, title='Down Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.red, 0))
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title='DownTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))
plotshape(sellSignal and showsignals ? dn : na, title='Sell', text='', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0))
mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? trend == 1 ? color.green : color.white : color.white
shortFillColor = highlighting ? trend == -1 ? color.red : color.white : color.white
fill(mPlot, upPlot, color=color.new(color.green,90))
fill(mPlot, dnPlot, color=color.new(color.red,90))
changeCond = trend != trend[1]

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// RoundToHundreds() rounds the close price to 100 strikes 
RoundToHundreds(value) =>
    math.round(value / 100.0) * 100

// Calculate and Strike Price
CallStrike = close[0]
PutStrike = close[0]

//Find Call option Strike
STdown= trend==-1 ? label.new(bar_index, na, 'Down Trend : BUY PUT ' + '( Strike ' + str.tostring(RoundToHundreds(PutStrike)) + ' or above)', color=#DC250C, textcolor=color.white, size=size.large, style=label.style_label_down, yloc=yloc.abovebar) : na
label.delete(STdown[1])

//Find Put Option Strike
STup= trend==1 ? label.new(bar_index, na, 'Up Trend : BUY CALL ' + '( Strike ' + str.tostring(RoundToHundreds(CallStrike)) + ' or below)', color=#18C522, textcolor=color.white, size=size.large, style=label.style_label_down, yloc=yloc.abovebar) : na
label.delete(STup[1])




