JayRogers

Sigma Band Break Trend System

Honorable Mentions:
  • @glaz - found it, waved it in my direction, ported correct method for identifying trend breakout. Massive thanks! :)
Sourced from:
  • http://indexswingtrader.blogspot.gr/2012/07/sigma-band-break-system.html
Excerpt from source article:
  • "Basically the Sigma Band Break System uses multiple Bollinger Bands set at 0.5 / 1 / 1.5 / 2 standard deviation above and below the midline. When a pricebar closes above the +0.5 band, the beginning of an uptrend is assumed, while a bar with a closing price below the -0.5 band indicates the start of a downtrend. Both bands can also be useful for determining stop loss or exit levels."
Add-Lib Tweaks:
  • Had a brain-fart and added Multi Time Frame trend cross-referencing - details below!
  • Buy/Sell zone entry signal shapes added - can easily be toggled off.
  • Trend entry signal shapes added - can easily be toggled off.
  • Bar colouring - also easily toggled off.
  • Cross-reference bands can be set up independently of the basis with their own section of dedicated inputs
  • Cross-referencing can easily be disabled for "traditional" band break trend looks/usage.
  • Added my usual array of MA selections, because choices are good.
Additional Notes:
In order to make this system as malleable as possible to fit different assets and pairs, there's a lot going on in the settings. first up, there's the MA basis selection from which you can choose:
  • SMA (simple)
  • EMA (exponential)
  • WMA (weighted)
  • VWMA ( volume weighted)
  • SMMA (smoothed)
  • DEMA (double exponential)
  • TEMA (triple exponential)
  • HullMA (hull)
  • LSMA (least squares *)
...all of which move very differently, which can greatly effect the behaviour of the deviations. Then there's all the inputs for the bands themselves, and an input for the offset of least squares ma if needed.

Here needs to be noted that the "Bands Multiplier" is purely for visual effect - the "Trend Tolerance Band Multiplier" is what is going to be giving you the actual trend conditions. I decided to separate the two In order to gain greater visual functionality.

Next in the inputs we have a toggle for the higher time frame reference, and the resolution at which to look - and then we have another duplicate set of inputs for this set of bands.

But what is it all for?
  • Primary set of bands on the current chart resolution gives us the base trend conditions as detailed in the article.
  • Second set of bands, set to a higher resolution does exactly the same as the first - but gives us a trend for the higher time frame.
  • Slap the two together and you get a sweet filter for the current chart resolution, that lets us take a look at the minor trend direction changes, and see if we should actually call them a "buy zone" instead of a "down trend" and visa versa!
  • A trend change is only confirmed when BOTH sets of bands say so.

...or of course you can just toggle all this fun stuff off and use the most basic method :D

Anyhoo... I hope some of you find this not-so-little nugget useful in your pip popping travels, feel free to ask anything or comment - good or bad, both are useful!

Happy Hunting!
Comment: Currently working on some revisions and tweaks. While the overall functionality will not change, there will be the addition of fixed resolution for the fast bands which may serve well to help find better position entry on a lower time frame, while using the script to give you higher time frame cue's. There will also be the addition of Arnaud Legoux MA as an option for the basis, including relevant inputs. Also I have aimed to get better visual segregation of the input blocks to make it less confusing/daunting.

I plan to add signals for outer band breaks, with the intention of better filtering entry/exit for the buy and sell zones. We'll see how it goes.
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2

study(title="Sigma Band Break Trend System", shorttitle="Sigma Trend", overlay = true)

// Revision:        1
// Author:          @JayRogers
// Mentions:        @glaz - found it, waved it in my direction, ported correct method for identifying trend breakout. Massive thanks! :)
// Sourced from:    http://indexswingtrader.blogspot.gr/2012/07/sigma-band-break-system.html
//
// Excerpt from source article:
//      "Basically the Sigma Band Break System uses multiple Bollinger Bands set at 0.5 / 1 / 1.5 / 2 standard deviation
//      above and below the midline. When a pricebar closes above the +0.5 band, the beginning of an uptrend is assumed,
//      while a bar with a closing price below the -0.5 band indicates the start of a downtrend. Both bands can also be
//      useful for determining stop loss or exit levels."
//
// Add-Lib Tweaks:
//  - Had a brainfart and added Multi Time Frame trend crossreferencing to find potential buy/sell zone entries - worked a treat!
//  - Buy/Sell zone entry signal shapes added - can easily be toggled off.
//  - Trend entry signal shapes added - can easily be toggled off.
//  - Bar colouring - also easily toggled off.
//  - Crossreference bands can be set up independantly of the basis with their own section of dedicated inputs
//  - Crossreferencing can easily be disabled for "traditional" band break trend looks/usage.
//  - Added my usual array of MA selections, because choices are good.

// - INPUTS
basisType       = input(defval = "SMA", title = "Basis Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, LSMA ( case sensitive )", type = string)
basisSource     = input(defval = close, title = "Basis Source")
lsmaOffset      = input(defval = 0, title = "Offset for LSMA ( only affects LSMA )")
basisLength     = input(defval = 20, title = "Basis Period", minval = 1)
devMultiply     = input(defval = 1.0, title = "Bands Multiplier", minval = 0.1, step = 0.05)
sigmaMultiply   = input(defval = 0.5, title = "Trend Tollerance Band Multiplier", minval = 0.05, step = 0.05)
MTFcheck        = input(defval = true, title = "Reference Higher Resolution for Buy/Sell Zones? ( disable for traditional method )")
MTFreso         = input(defval = "60", title = "Reference Resolution ( should be higher than current chart )", type = resolution)
MTFbasisType    = input(defval = "SMA", title = "Reference Basis Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, LSMA ( case sensitive )", type = string)
MTFsource       = input(defval = close, title = "Reference Basis Source")
MTFlsmaOffset   = input(defval = 0, title = "Reference Offset for LSMA ( only affects LSMA )")
MTFlength       = input(defval = 20, title = "Reference Basis Period", minval = 1)
MTFdevMultiply  = input(defval = 1.0, title = "Reference Bands Multiplier", minval = 0.1, step = 0.05)
MTFsigmaMultiply= input(defval = 0.5, title = "Reference Trend Tollerance Band Multiplier", minval = 0.05, step = 0.05)
buySellSigs     = input(defval = true, title = "Show Buy/Sell Zone Entry Signals? ( requires higher resolution referencing )")
trendSigs       = input(defval = true, title = "Show Trend Entry Signals?")
useColours      = input(defval = true, title = "Show Bar Colours?")
// - END INPUTS

// - VARIABLES/FUNCTIONS
// Returns MA input selection variant, default to SMA if blank or typo.
variant(type, src, len, lsma) =>
    v1 = sma(src, len)                                                  // Simple
    v2 = ema(src, len)                                                  // Exponential
    v3 = wma(src, len)                                                  // Weighted
    v4 = vwma(src, len)                                                 // Volume Weighted
    v5 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len    // Smoothed
    v6 = 2 * v2 - ema(v2, len)                                          // Double Exponential
    v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)               // Triple Exponential
    v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))   // Hull
    v9 = linreg(src, len, lsma)                                         // Least Squares
    // return variant, defaults to SMA if input invalid.
    type=="EMA"?v2 : type=="WMA"?v3 : type=="VWMA"?v4 : type=="SMMA"?v5 : type=="DEMA"?v6 : type=="TEMA"?v7 : type=="HullMA"?v8 : type=="LSMA"?v9 : v1
// basis lines and deviation
basis               = variant(basisType, basisSource, basisLength, lsmaOffset)
deviation           = stdev(basisSource, basisLength)
MTFbasis            = security(tickerid, MTFreso, variant(MTFbasisType, MTFsource, MTFlength, MTFlsmaOffset))
MTFdeviation        = security(tickerid, MTFreso, stdev(MTFsource, MTFlength))
// multiply functions for standard deviation bands, because writing the same calc over and over.. pfft
basisDevMult(num) => basis + (deviation * (num * devMultiply))
MTFbasisDevMult(num) => MTFbasis + (MTFdeviation * (num * MTFdevMultiply))
// trend identification conditions
upCondition         = basisSource > basisDevMult(sigmaMultiply)
downCondition       = basisSource < basisDevMult(-sigmaMultiply)
MTFupCondition      = basisSource > MTFbasisDevMult(MTFsigmaMultiply)
MTFdownCondition    = basisSource < MTFbasisDevMult(-MTFsigmaMultiply)
// determine current, and higher timeframe trend
trendState          = upCondition ? true : downCondition ? false : trendState[1] // if condition is met for change, switch it up and retain.
MTFtrendState       = MTFupCondition ? true : MTFdownCondition ? false : MTFtrendState[1]
// figure out the bar colours
MTFtrendUpColours   = MTFcheck and (MTFtrendState and trendState) ? #009900 : MTFcheck and (MTFtrendState and not trendState) ? #33FF66 : na
MTFtrendDownColours = MTFcheck and (not MTFtrendState and not trendState) ? #CC0000 : MTFcheck and (not MTFtrendState and trendState) ? #FF9900 : na
baseTrendColours    = not MTFcheck and trendState ? #009900 : #CC0000
// are we showing buy and sell signals?
showBuySell() => buySellSigs and MTFcheck
// buy zone signal determination
buyZoneEnter() =>
    prevState    = trendState[1] and MTFtrendState[1] // lower and major trends both in UP state?
    currState     = not trendState and MTFtrendState // lower trend DOWN, but still UP in major?
    r = showBuySell() and prevState and currState
// sell zone signal determination
sellZoneEnter() =>
    prevState    = not trendState[1] and not MTFtrendState[1] // lower and major trends both in DOWN state?
    currState     = trendState and not MTFtrendState // lower trend UP, but still DOWN in major?
    r = showBuySell() and prevState and currState
// trend up signal
trendUpStart() =>
    prevState = MTFcheck ? MTFtrendState[1] : trendState[1]
    currState = MTFcheck ? MTFtrendState : trendState
    r = trendSigs and currState and not prevState
// trend up signal
trendDownStart() =>
    prevState = MTFcheck ? MTFtrendState[1] : trendState[1]
    currState = MTFcheck ? MTFtrendState : trendState
    r = trendSigs and not currState and prevState
// - END VARIABLES/FUNCTIONS

// - BAR COLOURING
barcolor(color = useColours ? MTFtrendUpColours : na, title = "MTF Cross reference Up-Trend Colours")
barcolor(color = useColours ? MTFtrendDownColours : na, title = "MTF Cross reference Down-Trend Colours")
barcolor(color = useColours ? baseTrendColours : na, title = "Basic Trend Colours")
// - END BAR COLOURING

// - PLOTTING
// signal shapes
plotshape(buyZoneEnter(), title="Buy Tag", style=shape.labelup, location=location.belowbar, color=#00FFCC, transp=0, textcolor=silver, size=size.tiny)
plotshape(sellZoneEnter(), title="Sell Tag", style=shape.labeldown, location=location.abovebar, color=#FF00CC, transp=0, textcolor=silver, size=size.tiny)
plotshape(trendUpStart(), title="Trend Up", style=shape.arrowup, location=location.belowbar, color=green, transp=0, text="Trend Up", textcolor=silver, size=size.large)
plotshape(trendDownStart(), title="Trend Down", style=shape.arrowdown, location=location.abovebar, color=red, transp=0, text="Trend Down", textcolor=silver, size=size.large)
// basis line
plot(basis, title = "Basis Line", color = #999999, style = line, linewidth = 2, transp = 60)
// sigma tollerance bands
plot(basisDevMult(sigmaMultiply),   title = "Trend Tollerance Upper Band", color = #BBFFDD, style = circles, linewidth = 1, transp = 20)
plot(basisDevMult(-sigmaMultiply),  title = "Trend Tollerance Lower Band", color = #BBFFDD, style = circles, linewidth = 1, transp = 20)
// percentile deviation bands
plot(basisDevMult(0.5),     title = "50% Deviation Upper Band", color = #009999, style = line, linewidth = 1, transp = 60)
plot(basisDevMult(-0.5),    title = "50% Deviation Lower Band", color = #009999, style = line, linewidth = 1, transp = 60)
plot(basisDevMult(1),       title = "Base Deviation Upper Band", color = #00BBBB, style = line, linewidth = 1, transp = 60)
plot(basisDevMult(-1),      title = "Base Deviation Lower Band", color = #00BBBB, style = line, linewidth = 1, transp = 60)
plot(basisDevMult(1.5),     title = "150% Deviation Upper Band", color = #00DDDD, style = line, linewidth = 1, transp = 60)
plot(basisDevMult(-1.5),    title = "150% Deviation Lower Band", color = #00DDDD, style = line, linewidth = 1, transp = 60)
plot(basisDevMult(2),       title = "200% Deviation Upper Band", color = #00FFFF, style = line, linewidth = 1, transp = 60)
plot(basisDevMult(-2),      title = "200% Deviation Lower Band", color = #00FFFF, style = line, linewidth = 1, transp = 60)
// higher resolution extreme bands visual
plot(MTFcheck ? MTFbasisDevMult(2) : na,    title = "Higher Reference 200% Upper Band", color = silver, style = circles, linewidth = 1, transp = 50)
plot(MTFcheck ? MTFbasisDevMult(-2) : na,   title = "Higher Reference 200% Lower Band", color = silver, style = circles, linewidth = 1, transp = 50)
// fill for higher resolution sigma tollerance channel visual
MTFchannelUpper = plot(MTFcheck ? MTFbasisDevMult(MTFsigmaMultiply) : na, transp = 100, editable = false)
MTFchannelLower = plot(MTFcheck ? MTFbasisDevMult(-MTFsigmaMultiply) : na, transp = 100, editable = false)
fill(MTFchannelUpper, MTFchannelLower, color=silver, transp=80, title="Higher Reference Trend Tollerance Channel")
// - END PLOTTING

Related Ideas

vdubus PRO
a year ago
wow very nice :) gonna give this a whirl
+1 Reply
JayRogers vdubus
a year ago
Put a lot of effort into making it right.. Will be using it myself in conjunction with the scalp jockey. Hope it helps get you some good returns! :)
+1 Reply
Great job coding. TDI compliments this very well ! Thanks for sharing your efforts.
+1 Reply
JayRogers coondawg71
a year ago
Very welcome! and much appreciated. :)
Reply
zodiac7007
a year ago
Good job , I'll try it.
+1 Reply
HardyxGamer
a year ago
AMAZING! Thanks!
+1 Reply
JayRogers HardyxGamer
a year ago
Welcome :)
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out