Twilight
Twilight
0
at https://mozilla.org/MPL/2.0/
// © deven0
//@version=5
strategy(' Twilight ', overlay=true)
// Inputs
Periods = input(title='Sensitivity⚙️', defval=25)
src = input(hl2, title='Source')
Multiplier = input.float(title='Tuner ', step=0.1, defval=5.0)
changeATR = input(title='Change ATR Calculation Method ', defval=true)
showsignals = input(title='Show Signals ', defval=false)
highlighting = input(title='Highlighter ', defval=true)
barcoloring = input(title='Bar Coloring ', defval=true)
// ATR Calculation
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
// SuperTrend Calculation
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
longCondition = buySignal
if longCondition
strategy.entry('BUY', strategy.long, when=window())
strategy.exit('EXIT', 'BUY', stop=low - atr * stopLoss, limit=high + atr *
takeProfit)
shortCondition = sellSignal
if shortCondition
strategy.entry('SELL', strategy.short, when=window())
strategy.exit('EXIT', 'SELL', stop=high + atr * stopLoss, limit=low - atr *
takeProfit)
// Bar Coloring
buy1 = ta.barssince(buySignal)
sell1 = ta.barssince(sellSignal)
color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : na
barcolor(barcoloring ? color1 : na)