sierra chart bollinger bands trading strategy
A Bollinger band around prices captures the majority of price execute in spite of appearanc an upper and lower band. Only once prices move on all the way outside the bands, we love something significant happened. Let's see how we can deal those situations with a drift-following strategy.
IN THIS ARTICLE:
# Veer following with the Bollinger Breakout strategy for TradingView
Curtis Religion is one of the original Turtles, and in his book Way of the Turtle (2007) he describes his experiences. Turtles were a chemical group of people trained in 1983 by Richard Dennis, a successful trader. He taught them two economic strategies and gave them an account up to $2 million to trade. Faith would end up earning more than $30 million for Dennis.
The Turtles were tendency following. Those type of traders capitalise connected large price movements that occur o'er different months (Faith, 2007). They buy when markets make liberal arts highs and go short when prices plummet. This with the Assumption that price momentum continues after a breakout. Trend following can be very paying only difficult too. Advance percentages are around 30-35% while drawdowns ordinarily match the system of rules's annual returns (Faith, 2007).
One trend-following strategy that Faith (2007) shares is the Bollinger Breakout. This strategy is originally described by Chuck LeBeau and David George Lucas in their 1992 book Technical Traders Guide to Computer Analysis of the Futures Markets. The Bollinger bands themselves are, atomic number 3 you may know, popularised by John Bollinger.
The idea behind Bollinger bands is that they capture the absolute majority (90 to 95%) of price action. This way the much of market 'noise' is privileged the bands. And then when prices move outside the bands, we know something significant happened. Those situations are what trend followers trade. Allow's run into what the strategy's trading rules are.
# Trading rules for the Bollinger Breakout scheme
The Bollinger Breakout scheme has these trading rules (Faith, 2007):
- Enter foresighted rules:
- Open a long put down when the close is above the high Bollinger band, which is based on a 350-twenty-four hours twisting average incremented with 2.5 standard deviations.
- Exit long rules:
- Sell the long position when prices cross below the 350-daytime moving modal.
- Enter pint-sized rules:
- Open a curtly position when the close is below the lower Bollinger band, based on a 350-sidereal day moving average decreased with 2.5 standard deviations.
- Exit short rules:
- Covering fire the short position when price cross above the 350-twenty-four hour period moving average.
- Position sizing:
- For long and short positions, determine the position by dividing 0.5% of fairness by the prise of the commercialise's 20-bar Average True Range (ATR) in terms of dollars.
While this strategy does not specify a stop-loss order there's calm down an implicit stop. Once prices move against our position, at some point they'll cross the moving average and generate the drop dead indicate. This way losses are limited, but non in the way that we know our passing point in advance.
The profitable backtest that Faith (2007) performed utilised daily information and a wide range of futures markets, including foreign exchange (Australian dollar, British pound, Euro), commodities (gold, crude oil, copper, natural gas), soft commodities (cotton, burnt umber, Bos taurus, soybeans), and fixed-income futures (Exchequer notes and bonds).
# Programing the Bollinger Prisonbreak trading scheme for TradingView
Now Lashkar-e-Tayyiba's program this strategy. Unrivalled way that makes it easier to code TradingView strategies is to use a template. That breaks up the large task into small, easier-to-manage pieces. And information technology becomes less likely we overlook something. Plus it adds a bit of structure.
We'll use of goods and services the following template to code the Bollinger Breakout scheme:
//@version=3 // 1. Specify strategy settings // 2. Calculate strategy values // 3. Output strategy data // 4. Determine long trading conditions // 5. Code short trading conditions // 6. Submit entranceway orders // 7. Submit exit orders If you need to follow along with the code give-and-take in this clause, make a new strategy script in TradingView's Pine Editor and spread in the above template.
To get a horse sense of what the code we're going to write in reality does, here's how the pure strategy looks like on the chart:
Now let's begin to turn the Bollinger Breakout's trading rules into halal TradingView encipher.
# Step 1: Define strategy settings and input options
We first define the book settings and attain its input options. The code we use for that is:
// 1. Delineate strategy settings strategy(title= "Bollinger Breakout" , overlay= true , pyramiding= 0 , initial_capital= 100000 , commission_type= strategy.commission.cash_per_order , commission_value= 4 , slippage= 2) smaLength = input(title= "SMA Length" , character= integer , defval= 350) stdLength = input(title= "StdDev Length" , case= integer , defval= 350) ubOffset = input(title= "Upper Band Offset" , type= float , defval= 2.5 , step= 0.5) lbOffset = input(title= "Lower Band Offset" , type= float , defval= 2.5 , step= 0.5) usePosSize = input signal(title= "Use Put on Sizing?" , typecast= bool , defval= typical) riskPerc = input signal(championship= "Adventure %" , type= float , defval= 0.5 , step= 0.25) We first define the scheme's settings here with the strategy() function. We startle with 100,000 Johnny Cash (initial_capital) and don't scale into positions (pyramiding=0). The commission is 4 currency (commission_value) per single order (strategy.direction.cash_per_order). The slippage for market and break orders is 2 ticks (slippage=2). Both commission and slippage are high than you'd get in real trading. This makes the strategy's results a minute pessimistic.
Then we use the input() function to make the strategy's input options. The first two inputs are whole number input options (type=integer). These set the length of the unreeling average (onymous 'SMA Length') and standard divagation ('StdDev Distance'). We give way both a default value of 350.
Next we have input() make two drifting-luff inputs. The first, 'Lower Band Cancel', specifies how many standard deviations the upper band is above the simple moving average. The other, 'Lower Band Offset', defines how much standard deviations the lower dance orchestra is below the SMA. Both inputs start with a value of 2.5.
Then we make a right/false checkbox input option (case=bool). We turn this option on by default (defval=true) and public figure it 'Apply Position Sizing?'. The next and last stimulant option also relates to the strategy's position size. This afloat-point stimulus sets the risk share and begins with a value of 0.5.
The input() function returns the input option's current value. Here we store each of those values in its personal variable. That way we posterior refer to the option's current setting by using the adaptable.
# Footfall 2: Calculate trading strategy values
Next we figure out the scheme's values:
// 2. Calculate strategy values smaValue = sma(close , smaLength) stdDev = stdev(ungenerous , stdLength) upperBand = smaValue + (stdDev * ubOffset) lowerBand = smaValue - (stdDev * lbOffset) riskEquity = (riskPerc / 100) * strategy.equity atrCurrency = (atr(20) * syminfo.pointvalue) posSize = usePosSize ? floor(riskEquity / atrCurrency) : 1 First we calculate the SMA which is the basis for the Bollinger bands. We get that value with sma(). That function executes here connected closing prices (close) and for smaLength bars, the input variable we gave a default of 350 earlier. Then we calculate the standard deviation of closing prices over the same full stop with stdev(). We store both values in variables for enjoyment later.
To reckon the upper circle we increase the SMA with the standard deviation increased with the 'Speed Banding Outgrowth' input signal value, which we stored in the ubOffset variable. We arrive at the glower band value when we deduct the standard deviation times lbOffset (the 'Lower Band Offset' input option) from the SMA.
To calculate the put back size we first do 2 separate calculations: the 0.5% of risk equity and the ATR in currency time value. For the start we translate the riskPerc input variable from a percentage-based value (like 1%) to a fractional percentage (0.01). Then we multiply that with scheme.equity, a variable that returns the strategy's first great, accumulated net profit, and open position profit (TradingView, n.d.).
For the second figuring we fetch the 20-bar ATR with atr(20) and multiply that with syminfo.pointvalue. That variable star returns the currency economic value of one stop of price movement (for the E-miniskirt Sdanamp;P 500 subsequent it returns 50, e.g.).
Next we produce the posSize variable and determine the literal position size of it. For that we water parting the percentage of equity (riskEquity) with the ATR in currency value (atrCurrency). We use the floor() function to attack that value down to the nighest integer. This calculation is, however, only done when the usePosSize input varied is true. When that 'Use Location Size?' checkbox is rotated remove, we have the conditional manipulator retrovert 1 every bit the regular office size up for each order.
# Step 3: Output the strategy's data and project signals
To easily avow if the playscript actually trades the Bollinger bands, we plot those values on the chart:
// 3. Output strategy information plot(serial=smaValue, title= "SMA" , color= cyan) plot(series=upperBand, title= "UB" , color= fleeceable , linewidth= 2) plot(series=lowerBand, title= "LB" , color= ruddy , linewidth= 2) We plot the information with TradingView's plot() function. The first plot() statement shows the SMA (smaValue) coloured in teal.
The second and third plot() function Call display the amphetamine and depress band. We have the upperBand values show in the green colour piece lowerBand values come out in red. With the linewidth argumentation we make some line plots a bit thicker than normal.
# Pace 4: Code the long-term trading rules
Next we encrypt the strategy's elongate trading rules. As you echo the scheme goes long when prices cross above the upper band. And we close positions when prices drop below the 350-BAR moving middling. Here's how we translate those rules into true/invalid values:
// 4. Determine long trading conditions enterLong = crossover voter(close , upperBand) exitLong = crossunder(close , smaValue) The first Boolean variable, enterLong, holds typical whenever the bar closes higher up the upper Bollinger isthmus (and is false otherwise). To code that we employment TradingView's crossover() function, which returns genuine when the value of its first argument crossed above the second argument (TradingView, n.d.). When much a mark doesn't happen, the function returns false.
The other multivariate, exitLong, gets its prise also. Here we use crossunder(), a social occasion that returns true when the value of its first disputation born below the second on the current legal community (TradingView, n.d.). We run that function on closing prices and the SMA. That returns true when prices crossed under the traveling average and false otherwise.
# Step 5: Plan the unretentive trading conditions
Then we encipher the short trading conditions. From the trading rules above we know the strategy goes short-circuit when prices evenfall on a lower floor the frown band. And that shorts are closed when prices motility foul above the simple moving fair. We code these situations like so:
// 5. Code half-length trading conditions enterShort = crossunder(confining , lowerBand) exitShort = crossover(close , smaValue) For the first Boolean variable we employ the crossunder() purpose to check if prices dropped under the lower Bollinger band (lowerBand). When that's the encase, the enterShort variable gets a true value (and holds inharmonious otherwise).
The next program line uses the crossover() function to check if closing prices crossed over the 350-bar SMA (smaValue). When that happens, our exitShort variable holds true. Else it's value is false.
# Step 6: Open a trading position with entry orders
Now that we got the trading conditions outlined we terminate submit their entryway orders:
// 6. Relegate launching orders if (enterLong) strategy.entry(id= "EL" , long-wooled= trusty , qty=posSize) if (enterShort) strategy.debut(id= "Einsteinium" , long= false , qty=posSize) The first if statement here checks if the enterLong variable quantity is veracious. When it is, we call the strategy.entry() function to open a long position (long=true). We give that order the 'EL' identifier. And set its quantity to the posSize variable we calculated earlier.
The second if statement evaluates enterShort. When that variable is true, strategy.first appearance() opens a short position (long=false). We ID that order with 'Einsteinium' and have it trade posSize number of contracts.
# Step 7: Private market positions with exit orders
The finis bit of scheme code closes positions when the get out signal happens. Here's how we code that in the Bollinger Breakout strategy:
// 7. Submit exit orders scheme.close(id= "EL" , when=exitLong) scheme.closing(id= "ES" , when=exitShort) We exit our open market positions with strategy.juxtaposed(). That function closes an entry rescript specified by its id arguin. It uses a marketplace order for that whenever its when argument is true up (TradingView, n.d.).
The first scheme.close() function call here close our long entry order (ID="EL") when the exitLong Boolean variable is reliable. Based on how we coded that variable, the exit society is send when prices sealed below the 350-bar moving average.
The other strategy.close() financial statement exits short orders (id="ES"). It does that when exitShort is true during the current script calculation. For that to materialize prices demand to cross above the simple vibrating average, in which case exitShort becomes literal.
This completes the total TradingView strategy. Now let's charter a quick peek at its performance.
# Performance of the Bollinger Breakout strategy for TradingView
Let's get on a positive note. The Bollinger Prison-breaking scheme profits well from long-term trends, like this approximate 50% up act upon in fossil oil futures:
Unfortunately, the Bollinger Breakout strategy is also a typical swerve-tailing scheme. Those strategies lose money doubly: when trends reverse (and open position profit is lost) and when markets are range bound. In the first scenario the Bollinger Breakout strategy does not close positions excitable plenty. And when markets propel sideways the strategy suffers from whipsaw trades.
For instance, in this multi-year full point the strategy lost money for both reasons:
The table below shows the results of the Bollinger Jailbreak strategy on two instruments: petroleum futures and 10-year T-mention futures. These results are without position size. That path the strategy traded every setup, which increased the add up of trades in the backtest. (Even though in that location are still not enough trades to draw conclusions from this mini-backtest.)
| Performance metric | Rock oil (Atomic number 17) | 10-year T-note (ZN) |
|---|---|---|
| First trade | 1984-10-17 | 2001-10-31 |
| Live on trade | 2016-05-11 | 2016-11-09 |
| Time physical body | 1 day | 1 twenty-four hours |
| Net profit | -$4,182 | -$21,283 |
| Consummate profit | $92,862 | $5,741 |
| Total loss | -$97,044 | -$27,024 |
| Max drawdown | $46,826 | $21,287 |
| Profit factor out | 0.957 | 0.212 |
| Total trades | 19 | 10 |
| Winning trades | 6 | 3 |
| Win percentage | 31% | 30% |
| Avg trade | -$220 | -$2,128 |
| Avg win trade | $15,477 | $1913 |
| Avg losing trade | -$7,464 | -$3,860 |
| Win/loss ratio | 2.073 | 0.496 |
| Commission paid | $156 | $84 |
| Slippage | 2 ticks | 2 ticks |
# Ideas to better the Bollinger Breakout scheme
As we lav see from the table above, the Bollinger Breakout strategy can definitely economic consumption some improvement. Hither are few ideas you mightiness find useful to explore:
- The strategy had frenzied swings in performance, partly caused by combining a very long (350-bars) moving average with a daily time frame. The strategy power respond quicker to entry and exit signals when the clip frame is lower. At least that would reach us more trades so we have Thomas More data to pull out conclusions from.
- Even without a antithetic time soma, the 350-bar moving average smooth power need some tweaking. There are two disadvantages thereupon very long traveling average. First, it makes the Bollinger bands rather wide. That makes the strategy Modern to react when prices begin to trend. Second, the 350-debar moving average is rather far outside from launching prices. That increases swap risk since it gives a grownup gap between where we enter and exit trades.
- Faith (2007) did not specify why he choose the parameter settings that he did. The scheme might perform better with different parameters, especially when they suit the time framing and instruments we backtest.
- As with each trend-following strategies, the Bollinger Breakout scheme would benefit from a sheer filter. That way there are less losing trades when the strategy does not trade oblique markets as much.
- The strategy doesn't use full stop-loss orders, although positions are closed supported on a 350-daylight rolling average (which acts as an implicit check loss). That moving average is, all the same, far away from the ledger entry price. And in that location are probably situations in which we know sooner that the patronage isn't going anywhere. Perchance a trailing stop-loss closer to the entry price will help. Even if a stop consonant-departure order does non increment the strategy's performance, it can still give heartsease knowing that there's a stoppage in the markets to protect against big losses.
- The Bollinger Prisonbreak scheme suffered from its sporting part of false breakouts. If we can filter out those situations, the scheme's losing trades and transaction costs would reduction.
- Risk management is another way to improve the strategy. We can, e.g., trammel the strategy's maximum position sized. Or stop trading after hitting the uttermost drawdown. See the risk management class for more inspiration.
# Full code: the Bollinger Breakout scheme for TradingView
The entire code of the Bollinger Breakout scheme shows downstairs. See the discussion above for more information about each strategy part.
//@version=3 // 1. Define strategy settings scheme(title= "Bollinger Breakout" , overlay= true , pyramiding= 0 , initial_capital= 100000 , commission_type= strategy.commission.cash_per_order , commission_value= 4 , slippage= 2) smaLength = input signal(title= "SMA Length" , character= whole number , defval= 350) stdLength = input signal(title= "StdDev Length" , eccentric= whole number , defval= 350) ubOffset = input signal(title of respect= "Upper Band Offset" , type= float , defval= 2.5 , step= 0.5) lbOffset = input(title= "Lower Band Countervail" , character= drift , defval= 2.5 , step= 0.5) usePosSize = input(deed of conveyance= "Use Position Sizing?" , type= bool , defval= true) riskPerc = input(championship= "Risk %" , case= float , defval= 0.5 , whole tone= 0.25) // 2. Calculate scheme values smaValue = sma(finish , smaLength) stdDev = stdev(close , stdLength) upperBand = smaValue + (stdDev * ubOffset) lowerBand = smaValue - (stdDev * lbOffset) riskEquity = (riskPerc / 100) * strategy.equity atrCurrency = (atr(20) * syminfo.pointvalue) posSize = usePosSize ? floor(riskEquity / atrCurrency) : 1 // 3. Output scheme data plot(serial=smaValue, title= "SMA" , colouring material= teal) plot(serial publication=upperBand, title= "UB" , color= green , linewidth= 2) plot(series=lowerBand, title= "Pound" , colorize= red , linewidth= 2) // 4. Fix long-life trading conditions enterLong = crossover(close , upperBand) exitLong = crossunder(close , smaValue) // 5. Code short trading conditions enterShort = crossunder(close , lowerBand) exitShort = crossover(conclusion , smaValue) // 6. Submit entry orders if (enterLong) strategy.entry(Idaho= "Elevated" , long= true , qty=posSize) if (enterShort) scheme.entry(id= "ES" , long= delusive , qty=posSize) // 7. Submit give-up the ghost orders scheme.close(id= "EL" , when=exitLong) strategy.shut in(id= "ES" , when=exitShort) Visualise all TradingView example strategies for other ideas you said it to code different strategies. And for indicator scripts and how to code them, see all TradingView deterrent example indicators.
References
Faith, C.M. (2007). Way of the Capsize: The Secluded Methods that Turned Ordinary People into Legendary Traders. New York, Empire State: McGraw-James Jerome Hill.
TradingView (n.d.). Pine Playscript Language Reference Hand-operated. Retrieved connected Sept 13, 2022, from https://www.tradingview.com/study-script-reference/
Last updated on (published ).
« Whol TradingView example strategies articles
sierra chart bollinger bands trading strategy
Source: https://kodify.net/tradingview/strategies/bollinger-breakout/
Posted by: hayesreflud1983.blogspot.com

0 Response to "sierra chart bollinger bands trading strategy"
Post a Comment