Bollinger bands as reversal signal
Bollinger bands as reversal signal
27 Apr 2016, 22:12
Hi,
I do not know c# but used to use Easylanguage.
I'm interested in whether anyone has coded a script to use the Bollinger Bands (BB) as reversal signals.
The idea being sell/close on price hitting upper band and close/buy on price hitting lower band. No positions on Category 1/2 news events.
Take profit and stop loss can be added to handle risk.
Obviously this algo loses money when price never reverses but it can be adapted with use of major support/ resistance levels to try and handle this.
I'd appreciate it if anyone could start me off with the BB and position entry code.
Thanks.
Replies
cyfer
10 May 2016, 23:53
Basically , It will be something Like this
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Cyf_ROB_BollyBand_Bounce : Robot { private BollingerBands bb; private Position position; private bool CanOpenTrade; [Parameter(DefaultValue = 20)] public int bb_Periods { get; set; } [Parameter(DefaultValue = 2.0)] public double bb_stdDev { get; set; } [Parameter("Source")] public DataSeries bb_Source { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 1000, Step = 1000)] public int Volume { get; set; } [Parameter("Stop at", DefaultValue = 20)] public int StopLoss { get; set; } protected override void OnStart() { CanOpenTrade = true; bb_Source = CreateDataSeries(); bb = Indicators.BollingerBands(MarketSeries.Close, bb_Periods, bb_stdDev, MovingAverageType.Simple); } protected override void OnBar() { if (MarketSeries.Close.Last(0) < bb.Top.Last(0) && MarketSeries.Close.Last(1) > bb.Top.Last(1) && CanOpenTrade) { var result = ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "BollyBand_Sell", StopLoss, null); if (result.IsSuccessful) { position = result.Position; CanOpenTrade = false; } } /////////////////// if (MarketSeries.Close.Last(0) > bb.Bottom.Last(0) && MarketSeries.Close.Last(1) < bb.Bottom.Last(1) && CanOpenTrade) { ChartObjects.DrawText("Buy_Signal" + MarketSeries.Open.Count, Bullet, MarketSeries.Open.Count, MarketSeries.High.LastValue, vAlign, hAlign, Colors.Orange); var result = ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BollyBand_Buy", StopLoss, null); if (result.IsSuccessful) { position = result.Position; CanOpenTrade = false; } } } protected override void OnTick() { // Put your core logic here if (Positions.Count != 0 && position.TradeType == TradeType.Sell) { if (MarketSeries.Close.Last(0) >= bb.Main.Last(0))// Main or Bottom ???? ClosePosition(position); CanOpenTrade = true; } if (Positions.Count != 0 && position.TradeType == TradeType.Buy) { if (MarketSeries.Close.Last(0) <= bb.Main.Last(0)) // Main or TOP ????? ClosePosition(position); CanOpenTrade = true; } } protected override void OnStop() { // Put your deinitialization logic here } } }
But This is so simplified and there is no Real TP or SL Targets here .
usually the best SL & TP is related to ATR of that TF .
I Don't think it's a winning strategy , Bollinger bands are based on volatility .. So if Price Goes UP till it hits the upper band and then reverses to the lower band .. and then
exceeds the lower band and then reverses and Goes Up again and hit the upper band again .. and keep doing this imaginary cycle .. This could be a winning strategy
obviously this doesn't happen
@cyfer
cyfer
10 May 2016, 23:54
RE:
cyfer said:
Basically , It will be something Like this
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Cyf_ROB_BollyBand_Bounce : Robot { private BollingerBands bb; private Position position; private bool CanOpenTrade; [Parameter(DefaultValue = 20)] public int bb_Periods { get; set; } [Parameter(DefaultValue = 2.0)] public double bb_stdDev { get; set; } [Parameter("Source")] public DataSeries bb_Source { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 1000, Step = 1000)] public int Volume { get; set; } [Parameter("Stop at", DefaultValue = 20)] public int StopLoss { get; set; } protected override void OnStart() { CanOpenTrade = true; bb_Source = CreateDataSeries(); bb = Indicators.BollingerBands(MarketSeries.Close, bb_Periods, bb_stdDev, MovingAverageType.Simple); } protected override void OnBar() { if (MarketSeries.Close.Last(0) < bb.Top.Last(0) && MarketSeries.Close.Last(1) > bb.Top.Last(1) && CanOpenTrade) { var result = ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "BollyBand_Sell", StopLoss, null); if (result.IsSuccessful) { position = result.Position; CanOpenTrade = false; } } /////////////////// if (MarketSeries.Close.Last(0) > bb.Bottom.Last(0) && MarketSeries.Close.Last(1) < bb.Bottom.Last(1) && CanOpenTrade) { var result = ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BollyBand_Buy", StopLoss, null); if (result.IsSuccessful) { position = result.Position; CanOpenTrade = false; } } } protected override void OnTick() { // Put your core logic here if (Positions.Count != 0 && position.TradeType == TradeType.Sell) { if (MarketSeries.Close.Last(0) >= bb.Main.Last(0))// Main or Bottom ???? ClosePosition(position); CanOpenTrade = true; } if (Positions.Count != 0 && position.TradeType == TradeType.Buy) { if (MarketSeries.Close.Last(0) <= bb.Main.Last(0)) // Main or TOP ????? ClosePosition(position); CanOpenTrade = true; } } protected override void OnStop() { // Put your deinitialization logic here } } }But This is so simplified and there is no Real TP or SL Targets here .
usually the best SL & TP is related to ATR of that TF .
I Don't think it's a winning strategy , Bollinger bands are based on volatility .. So if Price Goes UP till it hits the upper band and then reverses to the lower band .. and then
exceeds the lower band and then reverses and Goes Up again and hit the upper band again .. and keep doing this imaginary cycle .. This could be a winning strategy
obviously this doesn't happen
@cyfer
Spotware
11 May 2016, 11:48
RE:
Dear Trader,
Currenlty, we don't provide users with the ability to edit their posts.
We will consider providing it in the future.
Additionally, you can post your ideas/suggestions to http://vote.spotware.com/
cyfer said:
@ SpotWare Forum Mods
We can't Edit our own Posts ???
Is there any sanity in this ?
@Spotware
Stokes Bay
11 May 2016, 22:00
RE: RE:
Thanks for your help cyfer
cyfer said:
cyfer said:
Basically , It will be something Like this
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Cyf_ROB_BollyBand_Bounce : Robot { private BollingerBands bb; private Position position; private bool CanOpenTrade; [Parameter(DefaultValue = 20)] public int bb_Periods { get; set; } [Parameter(DefaultValue = 2.0)] public double bb_stdDev { get; set; } [Parameter("Source")] public DataSeries bb_Source { get; set; } [Parameter("Volume", DefaultValue = 10000, MinValue = 1000, Step = 1000)] public int Volume { get; set; } [Parameter("Stop at", DefaultValue = 20)] public int StopLoss { get; set; } protected override void OnStart() { CanOpenTrade = true; bb_Source = CreateDataSeries(); bb = Indicators.BollingerBands(MarketSeries.Close, bb_Periods, bb_stdDev, MovingAverageType.Simple); } protected override void OnBar() { if (MarketSeries.Close.Last(0) < bb.Top.Last(0) && MarketSeries.Close.Last(1) > bb.Top.Last(1) && CanOpenTrade) { var result = ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "BollyBand_Sell", StopLoss, null); if (result.IsSuccessful) { position = result.Position; CanOpenTrade = false; } } /////////////////// if (MarketSeries.Close.Last(0) > bb.Bottom.Last(0) && MarketSeries.Close.Last(1) < bb.Bottom.Last(1) && CanOpenTrade) { var result = ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BollyBand_Buy", StopLoss, null); if (result.IsSuccessful) { position = result.Position; CanOpenTrade = false; } } } protected override void OnTick() { // Put your core logic here if (Positions.Count != 0 && position.TradeType == TradeType.Sell) { if (MarketSeries.Close.Last(0) >= bb.Main.Last(0))// Main or Bottom ???? ClosePosition(position); CanOpenTrade = true; } if (Positions.Count != 0 && position.TradeType == TradeType.Buy) { if (MarketSeries.Close.Last(0) <= bb.Main.Last(0)) // Main or TOP ????? ClosePosition(position); CanOpenTrade = true; } } protected override void OnStop() { // Put your deinitialization logic here } } }But This is so simplified and there is no Real TP or SL Targets here .
usually the best SL & TP is related to ATR of that TF .
I Don't think it's a winning strategy , Bollinger bands are based on volatility .. So if Price Goes UP till it hits the upper band and then reverses to the lower band .. and then
exceeds the lower band and then reverses and Goes Up again and hit the upper band again .. and keep doing this imaginary cycle .. This could be a winning strategy
obviously this doesn't happen
@Stokes Bay
ironmine
10 May 2016, 03:51
You should try the Visual Strategy Builder (https://quant.fxpro.co.uk/app/), it's quite easy to learn how to use it.
@ironmine