Time Segmented Volume indicator free

by mfejza in category Oscilator at 23/01/2023
Description

Time Segmented Volume indicator

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.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AutoRescale = false, AccessRights = AccessRights.None)]
    public class mTimeSegmentedVolume : Indicator
    {
        [Parameter("Main Periods (13)", DefaultValue = 13)]
        public int inpPeriodsMain { get; set; }
        [Parameter("Smooth Periods (7)", DefaultValue = 7)]
        public int inpPeriodsSmooth { get; set; }

        [Output("Time Segmented Volume", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outTSV { get; set; }
        [Output("Time Segmented Volume Smooth", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outTSVsmooth { get; set; }
        
        private IndicatorDataSeries _delta, _segment;
        private MovingAverage _smoothma;
        

        protected override void Initialize()
        {
            _delta = CreateDataSeries();
            _segment = CreateDataSeries();
            _smoothma = Indicators.MovingAverage(_segment, inpPeriodsSmooth, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            _delta[i] = i>1 && Bars.ClosePrices[i] != Bars.ClosePrices[i-1] ? (Bars.ClosePrices[i] - Bars.ClosePrices[i-1]) * Bars.TickVolumes[i] : 0;
            _segment[i] = _delta.Sum(inpPeriodsMain);
            
            outTSV[i] = _segment[i];
            outTSVsmooth[i] = _smoothma.Result[i];
        }
    }
}
Comments
0