0% found this document useful (0 votes)
82 views3 pages

Super Auto Trend Signals

This document contains a Pine Script® code for an 'Auto Trend Signals' indicator that allows users to select a timeframe and customize moving average settings. It calculates a smoothed moving average and a cloud to visualize trends, with dynamic colors indicating uptrends and downtrends. Additionally, it includes a 'Supertrend' feature that provides buy/sell signals based on the average true range (ATR) and allows for alerts on trend changes.

Uploaded by

Aj Deshmukh
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)
82 views3 pages

Super Auto Trend Signals

This document contains a Pine Script® code for an 'Auto Trend Signals' indicator that allows users to select a timeframe and customize moving average settings. It calculates a smoothed moving average and a cloud to visualize trends, with dynamic colors indicating uptrends and downtrends. Additionally, it includes a 'Supertrend' feature that provides buy/sell signals based on the average true range (ATR) and allows for alerts on trend changes.

Uploaded by

Aj Deshmukh
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

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

0
at [Link]
// © SirAlgo

//@version=6
indicator('Auto Trend Signals', overlay=true)

// === Inputs ===


// Timeframe Selection
selectedTF = [Link]("", title='Timeframe')

// MA Settings
maType = [Link]('EMA', title='MA Type', options=['SMA', 'EMA', 'WMA', 'RMA'])
maLength = [Link](50, title='MA Length', minval=1)
cloudMultiplier = [Link](0.25, title='Cloud Width Factor (StDev)', step=0.05)

// Smoothing
smoothLength = [Link](3, title='Smoothing Length', minval=1, tooltip="Smooths
final output to create soft, curved lines")

// Appearance
//maColor = [Link]([Link](219, 219, 219), title='MA Line Color')
maWidth = [Link](1, title='MA Line Width', minval=1)
// Dynamic Cloud Colors
cloudUpColor = [Link]([Link]([Link], 85), title='Cloud Fill Color
(Uptrend)')
cloudDownColor = [Link]([Link]([Link], 85), title='Cloud Fill Color
(Downtrend)')
borderUpColor = [Link]([Link]([Link], 100), title='Cloud Border Color
(Uptrend)')
borderDownColor = [Link]([Link]([Link], 100), title='Cloud Border Color
(Downtrend)')

// === MA Calculation Function ===


getMA(src, len) =>
switch maType
'SMA' => [Link](src, len)
'EMA' => [Link](src, len)
'WMA' => [Link](src, len)
'RMA' => [Link](src, len)

// === Get Raw Series (MTF or chart TF)


maRaw = [Link]([Link], selectedTF, getMA(close, maLength))
stdRaw = [Link]([Link], selectedTF, [Link](close, maLength *
2))

// === Cloud Calculation


cloudWidth = stdRaw * cloudMultiplier
upperRaw = maRaw + cloudWidth
lowerRaw = maRaw - cloudWidth

// === Post-Smoothing
maSmoothed = [Link](maRaw, smoothLength)
upperSmooth = [Link](upperRaw, smoothLength)
lowerSmooth = [Link](lowerRaw, smoothLength)

// === Trend Detection


isUptrend = maSmoothed > maSmoothed[1]
// === Dynamic Colors
dynamicFillColor = isUptrend ? cloudUpColor : cloudDownColor
dynamicBorderColor = isUptrend ? borderUpColor : borderDownColor
// === Plot
plot(maSmoothed, title='Smoothed MA', color=dynamicFillColor, linewidth=maWidth)
p1 = plot(upperSmooth, title='Upper Cloud', color=dynamicBorderColor)
p2 = plot(lowerSmooth, title='Lower Cloud', color=dynamicBorderColor)
fill(p1, p2, title='Cloud Fill', color=dynamicFillColor)

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0
at [Link]
// © SirAlgo

//icator('Supertrend', overlay = true, format = [Link], precision = 2,


timeframe = '')

Periods = input(title = 'SuperTrend ATR Period', defval = 10)


src = input(hl2, title = 'SuperTrend Source')
Multiplier = [Link](title = 'SuperTrend ATR Multiplier', step = 0.1, defval =
3.0)
changeATR = input(title = 'SuperTrend Change ATR Calculation Method ?', defval =
true)
showsignals = input(title = 'Show Buy/Sell Signals ?', defval = true)
highlighting = input(title = 'Highlighter On/Off ?', defval = true)
atr2 = [Link]([Link], Periods)
atr = changeATR ? [Link](Periods) : atr2
up = src - Multiplier * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? [Link](up, up1) : up
dn = src + Multiplier * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? [Link](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 = [Link]([Link], 0))
buySignal = trend == 1 and trend[1] == -1 and close> maSmoothed
plotshape(buySignal ? up : na, title = 'UpTrend Begins', location =
[Link], style = [Link], size = [Link], color =
[Link]([Link], 0))
plotshape(buySignal and showsignals ? up : na, title = 'Buy', text = 'Buy',
location = [Link], style = [Link], size = [Link], color =
[Link]([Link], 0), textcolor = [Link]([Link], 0))
dnPlot = plot(trend == 1 ? na : dn, title = 'Down Trend', style =
plot.style_linebr, linewidth = 2, color = [Link]([Link], 0))
sellSignal = trend == -1 and trend[1] == 1 and close< maSmoothed
plotshape(sellSignal ? dn : na, title = 'DownTrend Begins', location =
[Link], style = [Link], size = [Link], color =
[Link]([Link], 0))
plotshape(sellSignal and showsignals ? dn : na, title = 'Sell', text = 'Sell',
location = [Link], style = [Link], size = [Link], color =
[Link]([Link], 0), textcolor = [Link]([Link], 0))
mPlot = plot(ohlc4, title = '', style = plot.style_circles, linewidth = [Link](1,
0))
longFillColor = highlighting ? trend == 1 ? [Link] : [Link] : [Link]
shortFillColor = highlighting ? trend == -1 ? [Link] : [Link] : [Link]
//fill(mPlot, upPlot, title = 'UpTrend Highligter', color = longFillColor)
//fill(mPlot, dnPlot, title = 'DownTrend Highligter', color = shortFillColor)
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!')

You might also like