Skip to content

Commit

Permalink
Merge pull request #25 from GeorgeFreelanceDeveloper/feature/bollinge…
Browse files Browse the repository at this point in the history
…r-band-strategy-page

web: update bollinger band strategy page
  • Loading branch information
LucyFreelanceDeveloper authored Sep 14, 2024
2 parents 05d48a4 + 092a099 commit e81bab8
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/_includes/navigation.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<nav class="navbar navbar-expand-lg navbar-dark sticky-top bg-dark">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="{{ site.baseurl }}/"
>trend-follow.io</a
Expand Down
231 changes: 231 additions & 0 deletions docs/_pages/strategies/pages/bollinger-band-strategy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
---
title: Bollinger band strategy
layout: page
permalink: /strategies/pages/bollinger-band-strategy/
---
# BollingerBandTrendFollow
The purpose of this strategy is to use the Bollinger Bands to generate trading signals designed to capture powerful breakout price moves and to capitalize on the resulting trends from these breakouts. Strategy developed Australian trader Nick Radge.

**Table of Contents**
* [About strategy](#about-strategy)
* [Author](#author)
* [Entry and exit conditions for long side](#entry-and-exit-conditions-for-long-side)
* [Filters](#filters)
* [Position sizing](#position-sizing)
* [Management of position](#management-of-position)
* [Code example](#code-example)
* [Backtests](#backtests)
* [Suitable markets for trading](#suitable-markets-for-trading)
* [Resources](#resources)

## About strategy
The purpose of this strategy is to use the Bollinger Bands to generate trading signals designed to capture powerful breakout price moves and to capitalize on the resulting trends from these breakouts.

The Bollinger Bands are often used for the purpose of generating signals to determine when price is entering over-sold or over-bought areas on the chart, relative to recent price. This strategy utilizes the Bollinger Bands in a completely different way – to identify breakout trade opportunities which often lead to price trending in a defined direction for an extended period of time.

By definition, all price trends must begin with a breakout from a range. There are many different ways that we can identify and quantify price ranges. As we know, the Bollinger Bands consist of an upper and lower band which are plotted two standard deviations on either side of a 20-period simple moving average (20SMA). For the purposes of this strategy, the range that we are going to use to generate breakout signals is the range between the upper and lower bands of the Bollinger Bands.

**Prerequisites**
* Liquidity
* Volatility
* Trending market

<img src="../../../assets/images/bollinger_example.png" class="img-fluid">

## Author
Nick Radge is a respected figure in the trading community, renowned for his expertise in systematic trading and trend-following strategies. Hailing from Australia, Radge has made significant contributions to the field of trading through his books, courses, and seminars.

Radge is the author of "Unholy Grails - A New Road to Wealth", where he discusses his approach to trading and the importance of disciplined, rule-based strategies. He emphasizes the need for traders to remain objective and stick to their trading plans, rather than succumbing to emotional impulses.

As the founder of The Chartist, Radge provides trading education and research services to traders seeking to improve their skills and profitability in the financial markets. He is known for his practical and down-to-earth approach, offering insights that can be applied by traders of all levels.

Radge's work centers on trend following and momentum strategies, aiming to capture profits from sustained market movements while managing risk effectively. His dedication to empirical research and systematic methods has earned him a reputation as a trusted mentor and educator in the trading community.

## Entry and exit conditions for long side
**Entry**
* Daily close price is above upper band


**Exit**
* Daily close price is below lower band

```c#
int length = 20
double multiplierUpper = 1
double multiplierLower = 0.5
double upperBand = ta.sma(close, length) + multiplierUpper * ta.stdev(close, length)
double lowerBand = ta.sma(close, length) - multiplierLower * ta.stdev(close, length)
```

## Filters
**Simple**
* Daily close price is above 200 day moving average (bullish environment)

**Advance**

I think using Super trend indicator is more accurate determination of medium-term trend changes from bear market to bull market and vice versa.

* Daily close price is above Super trend indicator(Time frame: Weekly, ATR lenght: 10, Factor: 3)

## Position sizing
The size of the position is determined on the basis of volatility, the more volatile the market, the smaller the positions, and conversely, the less volatile the market, the larger positions are traded so that the risk per trade is always the same in various volatile markets.

**Simple by ATR**
```c#
private double ComputeTradeAmount(){
int AtrMultiplier = 2;
double amount = (RiskPerTradeInPercentage * AccountSize) / AtrMultiplier * ATR(20, Days)
return amount;
}

```

**Advance accurately determine the percentage risk**
```c#
//entryPrice: your entry to market
//stopPrice: value of lowerband
private double ComputeTradeAmount(double entryPrice, double stopPrice)
{
double riskPerTrade = (RiskPercentage / 100) * Account.Balance;
double move = entryPrice - stopPrice;
double amountRaw = riskPerTrade / ((Math.Abs(move) / Symbol.PipSize) * Symbol.PipValue);
double amount = ((int)(amountRaw / Symbol.VolumeInUnitsStep)) * Symbol.VolumeInUnitsStep;
return amount;
}
```

## Management of position
- Only one position open for one market.

## Code example
Example strategy implementation in C# programming language for trading platform cTrader.

```c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class BollingerBandTrendFollow_cBot : Robot
{
// ********************************
// User defined inputs
// ********************************
// Basic settings
[Parameter("Length", Group ="Basic settings", DefaultValue = 20)]
public int Length { get; set; }

[Parameter("Upper", Group ="Basic settings", DefaultValue = 1)]
public int MultiplierUpper { get; set; }

[Parameter("Lower", Group ="Basic settings", DefaultValue = 0.5)]
public double MultiplierLower { get; set; }

[Parameter("Risk percentage", Group ="Basic settings", DefaultValue = 2.5)]
public double RiskPercentage { get; set; }

[Parameter("Atr Multiplier", Group ="Basic settings", DefaultValue = 2)]
public int AtrMultiplier {get; set;}

[Parameter("Atr Length", Group ="Basic settings", DefaultValue = 20)]
public int AtrLength { get; set; }

// Filter settings
[Parameter("Enable Filter", Group ="Filter settings", DefaultValue =false)]
public bool EnableFilter {get; set;}

[Parameter("Price above SMA(X)", Group ="Filter settings", DefaultValue =200)]
public int SmaLength {get;set;}

[Parameter("RSI > X", Group ="Filter settings", DefaultValue = 0)]
public int RsiValue {get;set;}

protected override void OnStart()
{

}

protected override void OnBarClosed()
{
// **********************************
// Perform calculations and analysis
// **********************************
double stdLastValue = Indicators.StandardDeviation(Bars.ClosePrices, Length, MovingAverageType.Simple).Result.LastValue;
double smaLastValue = Indicators.SimpleMovingAverage(Bars.ClosePrices, Length).Result.LastValue;

double upperBand = smaLastValue + (MultiplierUpper * stdLastValue);
double lowerBand = smaLastValue - (MultiplierLower * stdLastValue);

string label = $"BollingerBandTrendFollow_cBot-{Symbol.Name}";

// Filter
double lastClosePrice = Bars.ClosePrices.LastValue;
bool priceAboveSMA = lastClosePrice > Indicators.SimpleMovingAverage(Bars.ClosePrices, SmaLength).Result.LastValue;
bool rsiAboveValue = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 14).Result.LastValue > RsiValue;
bool filter = EnableFilter ? priceAboveSMA && rsiAboveValue : true;

// Check position
Position position = Positions.Find(label);
bool isOpenPosition = position != null;

// Trade amount
double qty = ((RiskPercentage/100) * Account.Balance) / (AtrMultiplier * Indicators.AverageTrueRange(AtrLength, MovingAverageType.Simple).Result.LastValue);
double qtyInLots = ((int)(qty /Symbol.VolumeInUnitsStep)) * Symbol.VolumeInUnitsStep;

bool buyCondition = lastClosePrice > upperBand && !isOpenPosition && filter;
bool sellCondition = lastClosePrice < lowerBand && isOpenPosition;


// ********************************
// Manage trade
// ********************************
// Entry
if(buyCondition)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, qtyInLots, label);
}

// Exit
if(sellCondition) {
position.Close();
}

Print("Sucessful call OnBarClosed() method.");
}
}
}
```

## Backtests
**Nasdaq 100 index**
Period: 5 years (2019-2024)

<img src="../../../assets/images/bollinger_band_backtest_equity.png" class="img-fluid">

<img src="../../../assets/images/bollinger_band_backtest_statistics.PNG" class="img-fluid">

* [All backtests](../../../backtests/)

## Suitable markets for trading
* Cryptocurrencies (Bitcoin, Ethereum)
* Stock indexies (S&P 500, Nasdaq, DJI, NIFTY50)
* Stocks in long-term uptrend (AAPL, MSFT, NVDA, TSLA, AMZN, NFLX, SHOP, MA, ASML, PANW)
* Forex pairs in long-term uptrend (USDTRY, EURTRY, GBPTRY, USDINR, USDCNH) - <span style="color:red">warning: in reality impossible to trade due to high swap</span>

## Resources
* [nick-radge-the-chartist-a-systematic-trading-expert - zenandtheartoftrading.com](https://zenandtheartoftrading.com/blog/nick-radge-the-chartist-a-systematic-trading-expert/)
* [bollinger-bands-trading-strategy-momentum - aheadofthetrade.com](https://www.aheadofthetrade.com/bollinger-bands-trading-strategy-momentum/)
* [bollinger-band-trading-strategy - bettersystemtrader.com](https://bettersystemtrader.com/bollinger-band-trading-strategy/)
* [nick-radge - bettersystemtrader.com](https://bettersystemtrader.com/004-nick-radge/)
* [Unholy Grails - A New Road to Wealth - book](https://www.amazon.co.uk/dp/B007T97DJQ?tag=bst08-20&geniuslink=true)
2 changes: 1 addition & 1 deletion docs/_pages/strategies/strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Trend following is when you try to capture extended moves in the financial marke
* [Turtle strategy](/strategies/pages/turtle-strategy/)
* [Turtle Pro strategy]()
* [Supertrend strategy]()
* [Bollinger Band strategy]()
* [Bollinger Band strategy](/strategies/pages/bollinger-band-strategy.md)
* [Keltner strategy]()

## What is trend following trading?
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ <h4 class="card-title">Bollinger Band Breakout</h4>
</p>
</div>
<div class="card-footer">
<a href="strategies/#bollinger-band-breakout" class="btn btn-primary">Find Out More!</a>
<a href="../strategies/pages/bollinger-band-strategy/" class="btn btn-primary">Find Out More!</a>
</div>
</div>
</div>
</div>
<!-- /.row -->
<!-- /.row -->

<div class="shadow h-100 card-footer d-grid gap-2 d-md-flex justify-content-md-center">
<a href="../strategies/" class="btn btn-primary">More Strategies</a>
</div>

0 comments on commit e81bab8

Please sign in to comment.