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

Stoooooop Trend

This document is a TradingView Pine Script for a Bollinger Bands Stop indicator. It allows users to customize inputs such as source, length, and multipliers to visualize Bollinger Bands, stop levels, and entry zones on price charts. The script also includes features for detecting overbought and oversold conditions, trend changes, and plotting relevant signals on the chart.
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)
29 views2 pages

Stoooooop Trend

This document is a TradingView Pine Script for a Bollinger Bands Stop indicator. It allows users to customize inputs such as source, length, and multipliers to visualize Bollinger Bands, stop levels, and entry zones on price charts. The script also includes features for detecting overbought and oversold conditions, trend changes, and plotting relevant signals on the chart.
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

//@version=6

indicator(title = '[RS]Bollinger Bands Stop V0', shorttitle = 'BBS', overlay =


true)

// Inputs
bb_src = input.source(title = 'Bollinger Band Source:', defval = close)
stop_src = input.source(title = 'Stop Source:', defval = close)
length = input.int(title = 'Length', defval = 20, minval = 1)
mult = input.float(title = 'Band Deviation Multiplier:', defval = 2.0, minval =
0.001, maxval = 50)
risk_multiplier = input.float(title = 'Risk Multiplier:', defval = 0.5, minval =
0.001, maxval = 50)
SHOW_BB = input.bool(title = 'Show Bollinger Bands?', defval = false)
SHOW_ENTRY_ZONE = input.bool(title = 'Show Entry Zone?', defval = false)
SHOW_POINTS = input.bool(title = 'Show Points?', defval = false)
SHOW_TREND_CIRCLES = input.bool(title = 'Show Trend Change Circles?', defval =
true) // New Input for Trend Circles

// Bollinger Bands Calculation


basis = ta.sma(bb_src, length)
dev = mult * ta.stdev(bb_src, length)
upper = basis + dev
lower = basis - dev

// Plot Bollinger Bands


plot(title = 'BB-M', series = not SHOW_BB ? na : basis, color = color.gray)
p1 = plot(title = 'BB-U', series = not SHOW_BB ? na : upper, color = color.silver)
p2 = plot(title = 'BB-L', series = not SHOW_BB ? na : lower, color = color.silver)
fill(p1, p2, color = color.new(color.black, 90), title = 'BBf', editable = true)

// Trend and Stop Levels


var int trend = na
trend := na(trend[1]) ? 1 : stop_src > upper[1] ? +1 : stop_src < lower[1] ? -1 :
trend[1]

// Declare variables with `var` to ensure they are initialized properly


var float smin = na
var float smax = na
var float adjusted_min = na
var float adjusted_max = na
smin := trend < 0 ? math.min(nz(smin[1], upper[1]), upper) : na
smax := trend > 0 ? math.max(nz(smax[1], lower[1]), lower) : na
adjusted_min := trend < 0 ? math.min(nz(adjusted_min[1], smin[1]), smin -
risk_multiplier * dev) : na
adjusted_max := trend > 0 ? math.max(nz(adjusted_max[1], smax[1]), smax +
risk_multiplier * dev) : na

// Plot Stop Levels


s0 = plot(title = 'S-', series = smin, style = plot.style_circles, color =
#f50515,linewidth = 2)
s1 = plot(title = 'S+', series = smax, style = plot.style_circles, color =
#056656,linewidth = 2)
s2 = plot(title = 'E-', series = not SHOW_ENTRY_ZONE ? na : adjusted_min, style =
plot.style_linebr, color = color.new(color.black, 0))
s3 = plot(title = 'E+', series = not SHOW_ENTRY_ZONE ? na : adjusted_max, style =
plot.style_linebr, color = color.new(color.black, 0))
fill(s0, s2, color = color.new(color.red, 80), title = 'Z-', editable = true)
fill(s1, s3, color = color.new(color.lime, 80), title = 'Z+', editable = true)
// Detect Crosses
overbought_end = ta.crossunder(stop_src, upper) // ‫کراس نزولی‬
oversold_end = ta.crossover(stop_src, lower) // ‫کراس صعودی‬

// Plot Circles for Crosses


plotshape(title = 'Overbought End (Down)', series = not SHOW_POINTS ? na :
overbought_end ? low : na,
style = shape.circle, location = location.belowbar, color =
color.new(color.red, 0), size = size.large)
plotshape(title = 'Oversold End (Up)', series = not SHOW_POINTS ? na : oversold_end
? high : na,
style = shape.circle, location = location.abovebar, color =
color.new(color.green, 0), size = size.large)

// Entry and Exit Signals


buy_entry_zone = stop_src < adjusted_max and stop_src > smax
sel_entry_zone = stop_src > adjusted_min and stop_src < smin

plot(title = 'Bz', series = not SHOW_POINTS ? na : buy_entry_zone ? low : na, style


= plot.style_circles, color = color.new(color.green, 0), linewidth = 4)
plot(title = 'Sz', series = not SHOW_POINTS ? na : sel_entry_zone ? high : na,
style = plot.style_circles, color = color.new(color.maroon, 0), linewidth = 4)
plot(title = 'Be', series = not SHOW_POINTS ? na : overbought_end ? high : na,
style = plot.style_circles, color = color.new(color.black, 0), linewidth = 4)
plot(title = 'Se', series = not SHOW_POINTS ? na : oversold_end ? low : na, style =
plot.style_circles, color = color.new(color.black, 0), linewidth = 4)

// Detect Cross Between smin and smax


cross_smin_smax = ta.cross(smin, smax)

// Plot a Big Point on Cross


plot(title = 'Cross Point', series = not SHOW_POINTS ? na : cross_smin_smax ? (high
+ low) / 2 : na,
style = plot.style_circles, color = color.new(color.blue, 0), linewidth = 6)

// Show Trend Change Points


trend_change = trend != trend[1]
plotshape(title = 'Trend Change Up', series = not SHOW_TREND_CIRCLES ? na :
trend_change and trend == 1 ? smax : na,
style = shape.circle, location = location.absolute, color =
color.new(color.green, 0), size = size.small)
plotshape(title = 'Trend Change Down', series = not SHOW_TREND_CIRCLES ? na :
trend_change and trend == -1 ? smin : na,
style = shape.circle, location = location.absolute, color =
color.new(color.red, 0), size = size.small)

You might also like