0% found this document useful (0 votes)
36 views2 pages

Twilight

Twilight

Uploaded by

amrik51072
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

Twilight

Twilight

Uploaded by

amrik51072
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

0
at https://mozilla.org/MPL/2.0/
// © deven0

// Join telegram >> https://t.me/Algopoint043

//@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

// Buy and Sell Signals


buySignal = trend == 1 and trend[1] == -1
sellSignal = trend == -1 and trend[1] == 1

// Show Signal Labels


showLabels = input.bool(true, title="Show Signal Labels?")
if buySignal and showLabels
label.new(bar_index, low - atr * 2, 'Get\nReady\nto\nLong',
style=label.style_label_up, color=color.new(color.green, 65),
textcolor=color.white, size=size.normal)
if sellSignal and showLabels
label.new(bar_index, high + atr * 2, 'Get\nReady\nto\nShort',
style=label.style_label_down, color=color.new(color.red, 65),
textcolor=color.white, size=size.normal)

// Date Range Inputs


FromMonth = input.int(defval=9, title='From Month', minval=1, maxval=12)
FromDay = input.int(defval=1, title='From Day', minval=1, maxval=31)
FromYear = input.int(defval=2018, title='From Year', minval=999)
ToMonth = input.int(defval=1, title='To Month', minval=1, maxval=12)
ToDay = input.int(defval=1, title='To Day', minval=1, maxval=31)
ToYear = input.int(defval=9999, title='To Year', minval=999)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
window() =>
time >= start and time <= finish

// Strategy Entries with Stop Loss and Take Profit


stopLoss = input.float(1.5, title="Stop Loss (ATR Multiplier)")
takeProfit = input.float(5.0, title="Take Profit (ATR Multiplier)")

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)

// Background Highlight Logic


var int currentSignal = na // 1 for buy, -1 for sell, na for none
if buySignal
currentSignal := 1
if sellSignal
currentSignal := -1

bgColor = currentSignal == 1 ? color.new(color.green, 90) : currentSignal == -1 ?


color.new(color.red, 90) : na
bgcolor(highlighting ? bgColor : na)

// 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)

// Add Label for Short Trade


if shortCondition and showLabels
label.new( bar_index, close, text='Short Was Opened at\n' + '' +
str.tostring(close) + '\'' + ': ' + str.tostring(year(time)) + '-' +
str.tostring(month(time)) + '-' + str.tostring(dayofmonth(time)) + '\n' + 'Time: '
+ str.tostring(hour(time)) + ':' + str.tostring(minute(time)),
xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_right,
color=color.new(color.red, 65) )

// Add Label for Long Trade


if longCondition and showLabels
label.new( bar_index, close, text='Long Was Opened at\n' + '' +
str.tostring(close) + '\ ' +': ' + str.tostring(year(time)) + '-' +
str.tostring(month(time)) + '-' + str.tostring(dayofmonth(time)) + '\n' + 'Time: '
+ str.tostring(hour(time)) + ':' + str.tostring(minute(time)),xloc=xloc.bar_index,
yloc=yloc.price, style=label.style_label_right, color=color.new(color.green, 65)
)

You might also like