Bollinger Bands Flexible SD

by stuart in category Trend at 10/08/2019
Description

I needed this for the Unholy Grail system by Nick Radge he uses a 3SD for the upper and a 1SD for the lower. The idea is to enter long when the price closes above the upper band and exit when it hits the lower.

Only looking for Longs on the daily after a period of downward movement.

Period: 100

SD lower:1

SD Upper: 3

Price: Close

MA Type: Simple

Download
79 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class BollingerBands2 : Indicator
    {
        private MovingAverage _movingAverage;
        private StandardDeviation _standardDeviation;

        [Parameter("Period", DefaultValue = 20)]
        public int Period { get; set; }

        [Parameter("SD Upper", DefaultValue = 2)]
        public int Kup { get; set; }

        [Parameter("SD Lower", DefaultValue = 2)]
        public int Klow { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Parameter()]
        public DataSeries Price { get; set; }

        [Output("Main", Color = Colors.Blue)]
        public IndicatorDataSeries Main { get; set; }

        [Output("Upper", Color = Colors.Red)]
        public IndicatorDataSeries Upper { get; set; }

        [Output("Lower")]
        public IndicatorDataSeries Lower { get; set; }

        protected override void Initialize()
        {
            _movingAverage = Indicators.MovingAverage(Price, Period, MaType);
            _standardDeviation = Indicators.StandardDeviation(Price, Period, MaType);
        }
        public override void Calculate(int index)
        {

            Main[index] = _movingAverage.Result[index];
            Upper[index] = _movingAverage.Result[index] + Kup * _standardDeviation.Result[index];
            Lower[index] = _movingAverage.Result[index] - Klow * _standardDeviation.Result[index];
        }
    }
}
Comments
0