Category Oscilators  Published on 09/01/2023

CoVariance indicator

Description

CoVariance function as indicator to interpret trade sentiment zones


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

namespace cAlgo
{
    [Levels(0)]
    [Cloud("ZoneUp", "ZoneDn", FirstColor = "Red", SecondColor = "Green", Opacity = 0.2)]  
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mCoVariance : Indicator
    {
        [Parameter("Fast Period (8)", DefaultValue = 8)]
        public int inpPeriodFast { get; set; }
        [Parameter("Slow Period (16)", DefaultValue = 16)]
        public int inpPeriodSlow { get; set; }
        [Parameter("Bands Period (8)", DefaultValue = 8)]
        public int inpPeriodBands { get; set; }
        [Parameter("Bands Deviation (1.382)", DefaultValue = 0.764)]
        public double inpDeviationBands { get; set; }

        [Output("CoVariance", IsHistogram = false, LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outCoVariance { get; set; }
        [Output("Top", LineColor = "CadetBlue", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outBBup { get; set; }
        [Output("Down", LineColor = "CadetBlue", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outBBdn { get; set; }
        [Output("ZoneUp", LineColor = "Transparent")]
        public IndicatorDataSeries outZoneUp { get; set; }
        [Output("ZoneDn", LineColor = "Transparent")]
        public IndicatorDataSeries outZoneDn { get; set; }
        
        private MovingAverage _mafast, _maslow, _maweight;
        private IndicatorDataSeries _rawprice, _covariance;
        private BollingerBands _bb;
        

        protected override void Initialize()
        {
            _mafast = Indicators.MovingAverage(Bars.ClosePrices, inpPeriodFast,  MovingAverageType.Simple);
            _maslow = Indicators.MovingAverage(Bars.ClosePrices, inpPeriodSlow,  MovingAverageType.Simple);
            _maweight = Indicators.MovingAverage(Bars.ClosePrices, inpPeriodSlow,  MovingAverageType.Weighted);
            _covariance = CreateDataSeries();
            _rawprice = CreateDataSeries();
            _bb = Indicators.BollingerBands(_covariance, inpPeriodBands, inpDeviationBands, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            _rawprice[i] = Bars.ClosePrices[i] * Bars.ClosePrices[i];
            _covariance[i] = 0.1 * (_maweight.Result[i] - _mafast.Result[i] * _maslow.Result[i]);
            
            outCoVariance[i] = _covariance[i];
            outBBup[i] = _bb.Top[i];
            outBBdn[i] = _bb.Bottom[i];
            outZoneUp[i] =  _covariance[i];
            outZoneDn[i] =  _covariance[i] > _bb.Top[i] ? _bb.Top[i] : _covariance[i] < _bb.Bottom[i] ? _bb.Bottom[i] : _covariance[i];
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mCoVariance.algo
  • Rating: 5
  • Installs: 702
  • Modified: 09/01/2023 00:08
Comments
Log in to add a comment.
No comments found.