Category Oscilators  Published on 15/03/2023

VWAP SMA delta indicator

Description

This custom indicator represent the difference between Continual VWAP and SMA in same bars period calculations.
There is a strategy to use the difference as indication of trade zones, and this indicator produse those trade zones; indicator positive values indicate trading Long, and negative values trading Short. In this strategy as close confirmation indicator is used SMA (simple moving average) to identify average momentum price position. In another words SMA Long confirmation is when price above the SMA, and via versa.
As additional help to identify zones into chart, bars are colored, based on zones.

VWAP Continual custom indicator you can find here


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
 
namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mVWAPvsSMA : Indicator
    {
        [Parameter("Periods (10)", DefaultValue = 10)]
        public int inpPeriods { get; set; }
        [Parameter("Show Bars Color (yes)", DefaultValue = true)]
        public bool inpShowBarsColors { get; set; }
 
        [Output("Delta of VWAPc vs SMA", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outVWAPcSMA { get; set; }

        private MovingAverage _sma; 
        private IndicatorDataSeries _vwap, _result;

 
        protected override void Initialize()
        {
            _sma = Indicators.MovingAverage(Bars.ClosePrices, inpPeriods, MovingAverageType.Simple);
            _vwap = CreateDataSeries();
            _result = CreateDataSeries();
        }
 
        public override void Calculate(int i)
        {
            _vwap[i] = ((Bars.TypicalPrices.Sum(inpPeriods) * Bars.TickVolumes.Sum(inpPeriods)) / Bars.TickVolumes.Sum(inpPeriods)) / inpPeriods;
            _result[i] = _sma.Result[i] - _vwap[i];

            outVWAPcSMA[i] = _result[i];

            if(inpShowBarsColors == true)
            {
                if(Bars.OpenPrices[i] < Bars.ClosePrices[i])
                    Chart.SetBarColor(i, Color.LawnGreen);
                else
                    Chart.SetBarColor(i, Color.Orange);
                
                if(Bars.ClosePrices[i] > _sma.Result[i] && _result[i] > 0)
                    Chart.SetBarColor(i, Color.Green);
                if(Bars.ClosePrices[i] < _sma.Result[i] && _result[i] < 0)
                    Chart.SetBarColor(i, Color.Red);
            }
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mVWAPvsSMA.algo
  • Rating: 5
  • Installs: 978
  • Modified: 14/03/2023 21:42
Comments
Log in to add a comment.
GM
gmkenneyy · 1 year ago

Hello,

Thanks for uploading this interesting indicator

Something i saw on the 1st line of the OnCalculate event

((Bars.TypicalPrices.Sum(Periods) * Bars.TickVolumes.Sum(Periods)) / Bars.TickVolumes.Sum(Periods)) / Periods;

is the same as 

Bars.TypicalPrices.Sum(Periods) / Periods; 

MO
montuorikandi1759 · 1 year ago

Using a confirmation indicator such as SMA can help to increase the reliability of the signals generated by the custom indicator. When the price is above the SMA, it can be seen as a confirmation of a Long trade, and vice versa for Short trades.

More information: https://ctrader.com/algos/indicators/show/3315vampire survivors