Category Trend  Published on 05/03/2020

StandardDeviationOscillator

Description

This oscillator straightens up the famous Bollinger Bands, replicating a %B but with candles and standard deviations marks instead than a simple 0-100 scale.


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Levels(0, 1, 2, 3, -1, -2, -3)]
    [Indicator(IsOverlay = false, ScalePrecision = 1, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class STDOscillator : Indicator
    {
        [Parameter(DefaultValue = 20)]
        public int Period { get; set; }
        [Parameter(DefaultValue = 5)]
        public int Thickness { get; set; }

        [Output("Open", PlotType = PlotType.Points, LineColor = "Black")]
        public IndicatorDataSeries Open { get; set; }
        [Output("High", PlotType = PlotType.Points, LineColor = "Black")]
        public IndicatorDataSeries High { get; set; }
        [Output("Loe", PlotType = PlotType.Points, LineColor = "Black")]
        public IndicatorDataSeries Low { get; set; }
        [Output("Close", PlotType = PlotType.Points, LineColor = "Black")]
        public IndicatorDataSeries Close { get; set; }

        [Output("0", LineColor = "Gray")]
        public IndicatorDataSeries ZeroLine { get; set; }
        [Output("1", LineColor = "FFFF999A")]
        public IndicatorDataSeries FirstUpperBand { get; set; }
        [Output("2", LineColor = "FFFF5B62")]
        public IndicatorDataSeries SecondUpperBand { get; set; }
        [Output("3", LineColor = "FFFF0000")]
        public IndicatorDataSeries ThirdUpperBand { get; set; }
        [Output("-1", LineColor = "FF9CFF9C")]
        public IndicatorDataSeries FirstLowerBand { get; set; }
        [Output("-2", LineColor = "FF4EFF4E")]
        public IndicatorDataSeries SecondLowerBand { get; set; }
        [Output("-3", LineColor = "FF00FF00")]
        public IndicatorDataSeries ThirdLowerBand { get; set; }

        StandardDeviation STD;
        SimpleMovingAverage SMA;

        protected override void Initialize()
        {
            STD = Indicators.StandardDeviation(Bars.ClosePrices, Period, MovingAverageType.Simple);
            SMA = Indicators.SimpleMovingAverage(Bars.ClosePrices, Period);
        }

        public override void Calculate(int index)
        {
            Close[index] = (Bars[index].Close - SMA.Result[index]) / STD.Result[index];
            Open[index] = (Bars[index].Open - SMA.Result[index]) / STD.Result[index];
            High[index] = (Bars[index].High - SMA.Result[index]) / STD.Result[index];
            Low[index] = (Bars[index].Low - SMA.Result[index]) / STD.Result[index];

            IndicatorArea.DrawTrendLine("HL " + index, index, High[index], index, Low[index], Close[index] > Open[index] ? Color.Green : Color.Red);
            IndicatorArea.DrawTrendLine("Body " + index, index, Close[index], index, Open[index], Close[index] > Open[index] ? Color.Green : Color.Red, Thickness);

            ZeroLine[index] = 0;
            FirstLowerBand[index] = -1;
            FirstUpperBand[index] = 1;
            SecondLowerBand[index] = -2;
            SecondUpperBand[index] = 2;
            ThirdLowerBand[index] = -3;
            ThirdUpperBand[index] = 3;
        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: STDOscillator.algo
  • Rating: 0
  • Installs: 1389
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
No comments found.