You are on page 1of 3

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

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

//@version=5
indicator("Sayan", overlay=true)

// SuperTrend 1
Periods1 = input.int(title="ATR Period", defval=60, group='SuperTrend 1')
src1 = input.source(hl2, title="Source", group='SuperTrend 1')
Multiplier1 = input.float(title="ATR Multiplier", step=0.1, defval=2.0,
group='SuperTrend 1')
changeATR1 = input.bool(title="Change ATR Calculation Method ?", defval=true,
group='SuperTrend 1')

// SuperTrend 2
Periods2 = input.int(title="ATR Period", defval=60, group='SuperTrend 2')
src2 = input.source(hl2, title="Source", group='SuperTrend 2')
Multiplier2 = input.float(title="ATR Multiplier", step=0.1, defval=4.0,
group='SuperTrend 2')
changeATR2 = input.bool(title="Change ATR Calculation Method ?", defval=true,
group='SuperTrend 2')

// Initializing parameters
src = input.source(title='Source', defval=close, group ="RSI + BB (EMA) +
Dispersion (2.0)") // Set the price type for calculations
for_rsi = input.int(title='RSI_period', defval=14, group ="RSI + BB (EMA) +
Dispersion (2.0)") // Period for RSI
for_ma = input.int(title='Basis_BB', defval=20, group ="RSI + BB (EMA) + Dispersion
(2.0)") // Period for MA inside BB
for_mult = input.int(title='Stdev', defval=2, minval=1, maxval=5, group ="RSI + BB
(EMA) + Dispersion (2.0)") // Number of standard deviations for BB
for_sigma = input.float(title='Dispersion', defval=0.1, minval=0.01, maxval=1,
group ="RSI + BB (EMA) + Dispersion (2.0)") // Dispersion around MA

super_trend(Periods, src, Multiplier, changeATR) =>

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
[trend, up, dn]

[trend1, up1, dn1] = super_trend(Periods1, src1, Multiplier1, changeATR1)


[trend2, up2, dn2] = super_trend(Periods2, src2, Multiplier2, changeATR2)

upPlot1 = plot(trend1 == 1 ? up1 : na, title="Up Trend", style=plot.style_linebr,


linewidth=2, color=color.green)
buySignal1 = trend1 == 1 and trend1[1] == -1
dnPlot1 = plot(trend1 == 1 ? na : dn1, title="Down Trend", style=plot.style_linebr,
linewidth=2, color=color.red)
sellSignal1 = trend1 == -1 and trend1[1] == 1

upPlot2 = plot(trend2 == 1 ? up2 : na, title="Up Trend", style=plot.style_linebr,


linewidth=2, color=color.green)
buySignal2 = trend2 == 1 and trend2[1] == -1

dnPlot2 = plot(trend2 == 1 ? na : dn2, title="Down Trend", style=plot.style_linebr,


linewidth=2, color=color.red)
sellSignal2 = trend2 == -1 and trend2[1] == 1

// Script operating conditions


current_rsi = ta.rsi(src, for_rsi) // Current position of the RSI indicator
basis = ta.ema(current_rsi, for_ma)
dev = for_mult * ta.stdev(current_rsi, for_ma)
upper = basis + dev
lower = basis - dev
disp_up = basis + (upper - lower) * for_sigma // Minimum acceptable threshold in
the moving average area that RSI must overcome (top)
disp_down = basis - (upper - lower) * for_sigma // Minimum acceptable threshold in
the moving average area that RSI must overcome (bottom)
color_rsi = current_rsi >= disp_up ? color.lime : current_rsi <= disp_down ?
color.red : #ffea00 // Current RSI color, depending on its location within the BB

// Additional lines and fill for areas for RSI


h1 = hline(70, color=#d4d4d4, linestyle=hline.style_dotted, linewidth=1)
h2 = hline(30, color=#d4d4d4, linestyle=hline.style_dotted, linewidth=1)

// Alerts and trigger conditions


rsi_Green = ta.crossover(current_rsi, disp_up)
rsi_Red = ta.crossunder(current_rsi, disp_down)

// Results and color


plot(basis, color=color.new(color.black, 0))
plot(upper, color=color.new(#00fff0, 0), linewidth=2)
plot(lower, color=color.new(#00fff0, 0), linewidth=2)
s1 = plot(disp_up, color=color.new(color.white, 0))
s2 = plot(disp_down, color=color.new(color.white, 0))
// fill(s1, s2, color=color.new(color.white, 80))
plot(current_rsi, color=color_rsi, linewidth=2)

var int buyC = 0


var int sellC = 0

buy = trend1 == 1 and trend2 == 1 and color_rsi == color.lime and buyC == 0


sell = trend1 == -1 and trend2 == -1 and color_rsi == color.red and sellC == 0

if buy
buyC := 1

if sell
sellC := 1

buy_exit = (trend1 == -1 or trend2 == -1 or color_rsi != color.lime) and buyC == 1

if buy_exit
buyC := 0

sell_exit = (trend1 == 1 or trend2 == 1 or color_rsi != color.red) and sellC == 1

if sell_exit
sellC := 0

alertcondition(buy, "Buy", "Buy")


alertcondition(buy_exit, "Buy Exit", "Buy Exit")

alertcondition(sell, "Sell", "Sell")


alertcondition(sell_exit, "Sell Exit", "Sell Exit")

plotshape(buy, title='Buy', location=location.abovebar, color=color.green,


style=shape.arrowdown, text='Buy', textcolor=color.green)
plotshape(buy_exit, title='Buy Exit', location=location.abovebar,
color=color.green, style=shape.arrowdown, text='Buy exit', textcolor=color.green)

plotshape(sell, title='Sell', location=location.belowbar, color=color.red,


style=shape.arrowdown, text='Sell', textcolor=color.red)
plotshape(sell_exit, title='Sell Exit', location=location.belowbar,
color=color.red, style=shape.arrowdown, text='Sell Exit', textcolor=color.red)

You might also like