Bollinger Band Shift
Bollinger Band Shift
30 Apr 2019, 23:42
Would anyone be able to able to help me with adding a shift to the bands? Please note that the upper and lower bands work independently of one another.
Your help would be greatly apppreciated. Thank you!
Jay
using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class BB : Indicator { private MovingAverage _movingAverage; private StandardDeviation _standardDeviationUpper; private StandardDeviation _standardDeviationLower; [Parameter("Source MA")] public DataSeries Source { get; set; } [Parameter("Source Upper")] public DataSeries SourceUpper { get; set; } [Parameter("Source Lower")] public DataSeries SourceLower { get; set; } [Parameter("Periods MA", DefaultValue = 20, MinValue = 1)] public int Periods { get; set; } [Parameter("Periods Upper", DefaultValue = 20, MinValue = 1)] public int PeriodsUpper { get; set; } [Parameter("Periods Lower", DefaultValue = 20, MinValue = 1)] public int PeriodsLower { get; set; } [Parameter("Standard Deviation Upper", DefaultValue = 2.0, MaxValue = 10, MinValue = 0.0001)] public double StandardDeviationsUpper { get; set; } [Parameter("Standard Deviation Lower", DefaultValue = 2.0, MaxValue = 10, MinValue = 0.0001)] public double StandardDeviationsLower { get; set; } [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)] public MovingAverageType MAType { get; set; } [Output("Main")] public IndicatorDataSeries Main { get; set; } [Output("Top")] public IndicatorDataSeries Top { get; set; } [Output("Bottom")] public IndicatorDataSeries Bottom { get; set; } protected override void Initialize() { this._movingAverage = this.Indicators.MovingAverage(this.Source, this.Periods, this.MAType); this._standardDeviationUpper = this.Indicators.StandardDeviation(this.SourceUpper, this.PeriodsUpper, this.MAType); this._standardDeviationLower = this.Indicators.StandardDeviation(this.SourceLower, this.PeriodsLower, this.MAType); } public override void Calculate(int index) { double numUpper = this._standardDeviationUpper.Result[index] * this.StandardDeviationsUpper; double numLower = this._standardDeviationLower.Result[index] * this.StandardDeviationsLower; this.Main[index] = this._movingAverage.Result[index]; this.Bottom[index] = this._movingAverage.Result[index] - numLower; this.Top[index] = this._movingAverage.Result[index] + numUpper; } } }
Replies
JMich
02 May 2019, 12:53
RE:
FireMyst said:
As a side note, you might get some responses if you add a bit more details to the requirements you're wanting.
For example:
1) do you want this "shift" to be parameterized so it can be easily configured/adjusted without having to recompile code each time?
2) what exactly do you mean by "Shift"? What you think you are referring to might be different than what the reader understands.
etc.
Thank you for the response and suggestions. Please see below for an explanation, hope this makes sense and that I have clarified?
1. I would definitely like it to be parameterized.
2. I would like to add a parameter to shift my bands by x amount of periods. eg. I would like to be able to shift my bands 1 period to the right from its initial position.
Thank you,
Jared
@JMich
firemyst
02 May 2019, 05:31
As a side note, you might get some responses if you add a bit more details to the requirements you're wanting.
For example:
1) do you want this "shift" to be parameterized so it can be easily configured/adjusted without having to recompile code each time?
2) what exactly do you mean by "Shift"? What you think you are referring to might be different than what the reader understands.
etc etc.
@firemyst