0% found this document useful (0 votes)
13 views4 pages

This Pine Script

This Pine Script™ code implements a trading indicator called 'DSL & Trendlines' that includes Supertrend, Donchian Channel, and various moving averages. It provides buy/sell signals based on market trends and includes alert conditions for significant changes. The script also features customizable parameters for users to adjust the indicator settings according to their trading strategies.

Uploaded by

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

This Pine Script

This Pine Script™ code implements a trading indicator called 'DSL & Trendlines' that includes Supertrend, Donchian Channel, and various moving averages. It provides buy/sell signals based on market trends and includes alert conditions for significant changes. The script also features customizable parameters for users to adjust the indicator settings according to their trading strategies.

Uploaded by

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

/// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.

0/
// © salmanghani41

//@version=5
indicator("DSL & Trendlines", overlay=true)

// Supertrend Calculation
Periods = input(title='ATR Period', defval=10)
src = input(hl2, title='Source')
Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=3.0)
changeATR = input(title='Change ATR Calculation Method ?', defval=true)
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(#40b444, 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(#5aa65b, 0))
plotshape(buySignal and showsignals ? up : na, title='Buy', text='Buy', location=location.absolute, style=shape.labelup
, size=size.tiny, color=color.new(#509751, 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(#d86e6e, 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(#cb8787, 0))
plotshape(sellSignal and showsignals ? dn : na, title='Sell', text='Sell', location=location.absolute, style=shape.labe
ldown, size=size.tiny, color=color.new(#b16161, 0), textcolor=color.new(color.white, 0))
mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0)
alertcondition(buySignal, title='SuperTrend Buy', message='SuperTrend Buy!')
alertcondition(sellSignal, title='SuperTrend Sell', message='SuperTrend Sell!')
changeCond = trend != trend[1]
alertcondition(changeCond, title='SuperTrend Direction Change', message='SuperTrend has changed direction!')

//Donchian Channel Calculation


length = input.int(20, minval = 1)
offset = input.int(0)
lower = ta.lowest(length)
upper = ta.highest(length)
basis = math.avg(upper, lower)
plot(basis, "Basis", color = #FF6D00, offset = offset)
u = plot(upper, "Upper", color = #2962FF, offset = offset)
l = plot(lower, "Lower", color = #2962FF, offset = offset)
fill(u, l, color = color.rgb(33, 150, 243, 95), title = "Background")

// Add the middle line (ssl channel) to the plot


wicks = input(false, "Take Wicks into Account ?")
highlightState = input(true, "Highlight State ?")
ma(source, length, type) =>
type == "SMA" ? ta.sma(source, length) :
type == "EMA" ? ta.ema(source, length) :
type == "SMMA (RMA)" ? ta.rma(source, length) :
type == "WMA" ? ta.wma(source, length) :
type == "VWMA" ? ta.vwma(source, length) :
na

show_ma1 = input(true , "MA High", inline="MA #1", group="Channel №1")


ma1_type = input.string("SMA" , "" , inline="MA #1", options=["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"], group="Channel №1")
ma1_source = input(high , "" , inline="MA #1", group="Channel №1")
ma1_length = input.int(200 , "" , inline="MA #1", minval=1, group="Channel №1")
ma1_color = input(color.green, "" , inline="MA #1", group="Channel №1")
ma1 = ma(ma1_source, ma1_length, ma1_type)

show_ma2 = input(true , "MA Low", inline="MA #2", group="Channel №1")


ma2_type = input.string("SMA" , "" , inline="MA #2", options=["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"], group="Channel №1")
ma2_source = input(low , "" , inline="MA #2", group="Channel №1")
ma2_length = input.int(200 , "" , inline="MA #2", minval=1, group="Channel №1")
ma2_color = input(color.red, "" , inline="MA #2", group="Channel №1")
ma2 = ma(ma2_source, ma2_length, ma2_type)
showLabels1 = input(true, "Show Buy/Sell Labels ?", group="Channel №1")

show_ma3 = input(false , "MA High", inline="MA #3", group="Channel №2")


ma3_type = input.string("SMA" , "" , inline="MA #3", options=["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"], group="Channel №2")
ma3_source = input(high , "" , inline="MA #3", group="Channel №2")
ma3_length = input.int(20 , "" , inline="MA #3", minval=1, group="Channel №2")
ma3_color = input(color.orange, "" , inline="MA #3", group="Channel №2")
ma3 = ma(ma3_source, ma3_length, ma3_type)

show_ma4 = input(false , "MA Low", inline="MA #4", group="Channel №2")


ma4_type = input.string("SMA" , "" , inline="MA #4", options=["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"], group="Channel №2")
ma4_source = input(low , "" , inline="MA #4", group="Channel №2")
ma4_length = input.int(20 , "" , inline="MA #4", minval=1, group="Channel №2")
ma4_color = input(color.blue, "" , inline="MA #4", group="Channel №2")
ma4 = ma(ma4_source, ma4_length, ma4_type)
showLabels2 = input(true, "Show Buy/Sell Labels ?", group="Channel №2")

Hlv1 = float(na)
Hlv1 := (wicks ? high : close) > ma1 ? 1 : (wicks ? low : close) < ma2 ? -1 : Hlv1[1]
sslUp1 = Hlv1 < 0 ? ma2 : ma1
sslDown1 = Hlv1 < 0 ? ma1 : ma2

Color1 = Hlv1 == 1 ? ma1_color : ma2_color


fillColor1 = highlightState ? (color.new(Color1, 90)) : na

highLine1 = plot(show_ma1 ? sslUp1 : na, title="UP", linewidth=2, color = Color1)


lowLine1 = plot(show_ma2 ? sslDown1 : na, title="DOWN", linewidth=2, color = Color1)

plotshape(show_ma1 and showLabels1 and Hlv1 == 1 and Hlv1[1] == -1, title="Buy


Label", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=Color1, textcolor=color.whit
e)
plotshape(show_ma2 and showLabels1 and Hlv1 == -1 and Hlv1[1] == 1, title="Sell
Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=Color1, textcolor=color.w
hite)

fill(highLine1, lowLine1, color = fillColor1)

Hlv2 = float(na)
Hlv2 := (wicks ? high : close) > ma3 ? 1 : (wicks ? low : close) < ma4 ? -1 : Hlv2[1]
sslUp2 = Hlv2 < 0 ? ma4 : ma3
sslDown2 = Hlv2 < 0 ? ma3 : ma4

Color2 = Hlv2 == 1 ? ma3_color : ma4_color


fillColor2 = highlightState ? (color.new(Color2, 90)) : na

highLine2 = plot(show_ma3 ? sslUp2 : na, title="UP", linewidth=2, color = Color2)


lowLine2 = plot(show_ma4 ? sslDown2 : na, title="DOWN", linewidth=2, color = Color2)

plotshape(show_ma3 and showLabels2 and Hlv2 == 1 and Hlv2[1] == -1, title="Buy


Label", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=Color2, textcolor=color.whit
e)
plotshape(show_ma4 and showLabels2 and Hlv2 == -1 and Hlv2[1] == 1, title="Sell
Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=Color2, textcolor=color.w
hite)

fill(highLine2, lowLine2, color = fillColor2)

// Alerts
alertcondition(Hlv1 == 1 and Hlv1[1] == -1, title="SSL Channel (1) Buy Alert", message = "SSL Channel (1): BUY")
alertcondition(Hlv1 == -1 and Hlv1[1] == 1, title="SSL Channel (1) Sell Alert", message = "SSL Channel (1): SELL")
alertcondition(Hlv2 == 1 and Hlv2[1] == -1, title="SSL Channel (2) Buy Alert", message = "SSL Channel (2): BUY")
alertcondition(Hlv2 == -1 and Hlv2[1] == 1, title="SSL Channel (2) Sell Alert", message = "SSL Channel (2): SELL")

//Vwap Calculation
vwap = ta.vwap
plot(vwap, title="Vwap", color=color.rgb(151, 158, 89), linewidth=2)

src1(source, length, type) =>


type == "SMA" ? ta.sma(source, length) :
type == "EMA" ? ta.ema(source, length) :
type == "SMMA (RMA)" ? ta.rma(source, length) :
type == "WMA" ? ta.wma(source, length) :
type == "VWMA" ? ta.vwma(source, length) :
na

//LinReg Candles

signal_length = input.int(title='Signal Smoothing', minval=1, maxval=200, defval=11)


sma_signal = input(title='Simple MA (Signal Line)', defval=true)

lin_reg = input(title='Lin Reg', defval=true)


linreg_length = input.int(title='Linear Regression Length', minval=1, maxval=200, defval=11)

bopen = lin_reg ? ta.linreg(open, linreg_length, 0) : open


bhigh = lin_reg ? ta.linreg(high, linreg_length, 0) : high
blow = lin_reg ? ta.linreg(low, linreg_length, 0) : low
bclose = lin_reg ? ta.linreg(close, linreg_length, 0) : close

r = bopen < bclose

signal = sma_signal ? ta.sma(bclose, signal_length) : ta.ema(bclose, signal_length)

plotcandle(r ? bopen : na, r ? bhigh : na, r ? blow : na, r ? bclose : na, title='LinReg
Candles', color=color.green, wickcolor=color.green, bordercolor=color.green, editable=true)
plotcandle(r ? na : bopen, r ? na : bhigh, r ? na : blow, r ? na : bclose, title='LinReg
Candles', color=color.red, wickcolor=color.red, bordercolor=color.red, editable=true)

plot(signal, color=color.new(color.white, 0))

//Purple Cloud Settings


atrPeriod = input(10, "Supertrend ATR Length")
factor = input.float(3.0, "Supertrend Factor", step = 0.01)

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

x1 = input(14, "Period")
alpha = input.float(0.7, "Alpha", step = 0.1)

bpt=input.float(1.4,"Buying Pressure Threshold %", step = 0.1)


spt=input.float(1.4,"Selling Pressure Threshold %", step = 0.1)

x2 = ta.atr(x1) * alpha
xh = close + x2
xl = close - x2
a1=ta.vwma(hl2*volume,math.ceil(x1/4))/ta.vwma(volume,math.ceil(x1/4))
a2=ta.vwma(hl2*volume,math.ceil(x1/2))/ta.vwma(volume,math.ceil(x1/2))
a3=2*a1-a2
a4=ta.vwma(a3,x1)

b1 = 0.0
b1 := na(b1[1]) ? ta.sma(close, x1) : (b1[1] * (x1 - 1) + close) / x1

a5=2*a4*b1/(a4+b1)

buy = a5<=xl and close>b1*(1+bpt*0.01)


sell = a5>=xh and close<b1*(1-spt*0.01)
xs = 0
xs := buy ? 1 : sell ? -1 : xs[1]
barcolor( color = xs==1 ? color.green :xs==-1? color.red:na)

plotshape(buy and xs != xs[1]


, title = "BUY", text = 'B', style = shape.labelup, location = location.belowbar, color= color.green, textcolor =
color.white, size = size.tiny)
plotshape(sell and xs != xs[1] , title = "SELL", text = 'S', style = shape.labeldown, location = location.abovebar, col
or= color.red, textcolor = color.white, size = size.tiny)

plotshape(buy and xs != xs[1] and direction < 0 , title = "Strong


BUY", text = '🚀', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white,
size = size.tiny)
plotshape(sell and xs != xs[1] and direction > 0 , title = "Strong
SELL", text = '☄️
', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white,
size = size.tiny)

ema200=input(false,"Ema 200")
ema50=input(false,"Ema 50")
ema20=input(false,"Ema 20")

plot(ta.ema(close,200),color=ema200?#dee4f6:na,title="Ema 200",linewidth = 4)
plot(ta.ema(close,50),color=ema50?color.blue:na,title="EMA 50",linewidth = 3)
plot(ta.ema(close,20),color=ema20?color.orange:na,title="EMA 20",linewidth = 2)
alertcondition(buy and xs != xs[1], "PC Long", "PC Long")
alertcondition(sell and xs != xs[1], "PC Short", "PC Short")

You might also like