PROTECTED SOURCE SCRIPT

MarathiStockTraders AI

34
//version=5
indicator("MarathiStockTraders AI", overlay=true, format=format.price, precision=2)


// === INPUTS ===
// SuperTrend Inputs
atrPeriod = input.int(10, title="ATR Period")
multiplier = input.float(3.0, title="ATR Multiplier", step=0.1)
changeATR = input.bool(true, title="Change ATR Calculation Method?")
showSignals = input.bool(true, title="Show Buy/Sell Signals?")
highlighting = input.bool(true, title="Highlighter On/Off?")

// Bollinger Band Inputs
bbLength = input.int(20, title="BB Period (for SuperTrend source)")
bbSrc = input.source(close, title="BB Source")
showBB = input.bool(true, title="Show Bollinger Bands?")
bbMult = input.float(2.0, title="BB Multiplier", step=0.1)

// === Bollinger Band Calculation ===
bbBasis = ta.sma(bbSrc, bbLength)
bbUpper = bbBasis + bbMult * ta.stdev(bbSrc, bbLength)
bbLower = bbBasis - bbMult * ta.stdev(bbSrc, bbLength)

// === ATR Calculation ===
atr_standard = ta.atr(atrPeriod)
atr_sma = ta.sma(ta.tr, atrPeriod)
atr = changeATR ? atr_standard : atr_sma

// === SuperTrend Calculations using BB Basis ===
src = bbBasis

upperBand = src - (multiplier * atr)
lowerBand = src + (multiplier * atr)

upperBand := close[1] > nz(upperBand[1]) ? math.max(upperBand, nz(upperBand[1])) : upperBand
lowerBand := close[1] < nz(lowerBand[1]) ? math.min(lowerBand, nz(lowerBand[1])) : lowerBand

trend = 0
trend := nz(trend[1], 1)
trend := trend == -1 and close > nz(lowerBand[1]) ? 1 :
trend == 1 and close < nz(upperBand[1]) ? -1 : trend

// === Plotting SuperTrend Lines ===
upPlot = plot(trend == 1 ? upperBand : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
dnPlot = plot(trend == -1 ? lowerBand : na, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)

// === Buy/Sell Signals ===
buySignal = trend == 1 and trend[1] == -1
sellSignal = trend == -1 and trend[1] == 1

plotshape(buySignal ? upperBand : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green)
plotshape(buySignal and showSignals ? upperBand : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white)

plotshape(sellSignal ? lowerBand : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red)
plotshape(sellSignal and showSignals ? lowerBand : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white)

// === Highlighting ===
basePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.new(color.green, 85) : na) : na
shortFillColor = highlighting ? (trend == -1 ? color.new(color.red, 85) : na) : na

fill(basePlot, upPlot, title="UpTrend Highlighter", color=longFillColor)
fill(basePlot, dnPlot, title="DownTrend Highlighter", color=shortFillColor)

// === Optional Bollinger Bands Display ===
plot(showBB ? bbBasis : na, title="BB Basis", color=color.gray)
plot(showBB ? bbUpper : na, title="BB Upper", color=color.blue)
plot(showBB ? bbLower : na, title="BB Lower", color=color.blue)

// === Alerts ===
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
alertcondition(trend != trend[1], title="SuperTrend Direction Change", message="SuperTrend has changed direction!")

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.