Category Oscilators  Published on 04/04/2023

Supply Demand Directional Volume

Description

Supply Demand Directional Volume is a volume indicator that offers a simple way to estimate the movement and balance (or lack thereof) of supply and demand volume based on the shape of the price bar.

Use the crossing supply/demand components as trading zones.


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

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mSupplyDemandDirectionalVolume : Indicator
    {
        [Parameter("Main Period (10)", DefaultValue = 10)]
        public int inpMainPeriod { get; set; }
        [Parameter("Smooth Period (3)", DefaultValue = 3)]
        public int inpSmoothPeriod { get; set; }

        [Output("NetVolume", LineColor = "Black", PlotType = PlotType.Histogram, LineStyle = LineStyle.Solid, Thickness = 3)]
        public IndicatorDataSeries outNetVolume { get; set; }
        [Output("Demand", LineColor = "Green", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outDemand { get; set; }
        [Output("Supply", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outSupply { get; set; }

        private IndicatorDataSeries _body, _barrange, _wick, _realrange, _bscore, _bullscore, _bearscore, _demand, _supply, _netvolume;
        private MovingAverage _wmad1, _wmad0, _wmas1, _wmas0;


        protected override void Initialize()
        {
            _body = CreateDataSeries();
            _barrange = CreateDataSeries();
            _wick = CreateDataSeries();
            _realrange = CreateDataSeries();
            _bscore = CreateDataSeries();
            _bullscore = CreateDataSeries();
            _bearscore = CreateDataSeries();
            _demand = CreateDataSeries();
            _supply = CreateDataSeries();
            _wmad1 = Indicators.MovingAverage(_bullscore, inpMainPeriod, MovingAverageType.Weighted);
            _wmad0 = Indicators.MovingAverage(_wmad1.Result, inpSmoothPeriod, MovingAverageType.Weighted);
            _wmas1 = Indicators.MovingAverage(_bearscore, inpMainPeriod, MovingAverageType.Weighted);
            _wmas0 = Indicators.MovingAverage(_wmas1.Result, inpSmoothPeriod, MovingAverageType.Weighted);
            _netvolume = CreateDataSeries();
        }

        public override void Calculate(int i)
        {
            _body[i] = Math.Abs(Bars.ClosePrices[i] - Bars.OpenPrices[i]);
            _barrange[i] = Bars.HighPrices[i] - Bars.LowPrices[i];
            _wick[i] = _barrange[i] - _body[i];
            _realrange[i] = _barrange[i] + _wick[i];
            _bscore[i] = _barrange[i] > 0 ? Bars.ClosePrices[i] > Bars.OpenPrices[i] ? _barrange[i] / _realrange[i] : _wick[i] / _realrange[i] : 0.50;
            _bullscore[i] = _bscore[i] * Bars.TickVolumes[i];
            _bearscore[i] = Bars.TickVolumes[i] - _bullscore[i];
            _demand[i] = _wmad0.Result[i];
            _supply[i] = _wmas0.Result[i];
            _netvolume[i] = _demand[i] - _supply[i];            
            
            outNetVolume[i] = _netvolume[i];
            outDemand[i] = _demand[i];
            outSupply[i] = _supply[i];
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mSupplyDemandDirectionalVolume.algo
  • Rating: 5
  • Installs: 1127
Comments
Log in to add a comment.
No comments found.