Information

Username: ianmackers
Member since: 28 Dec 2023
Last login: 28 Dec 2023
Status: Active

Activity

Where Created Comments
Algorithms 0 2
Forum Topics 0 1
Jobs 0 0

Last Algorithm Comments

IA
ianmackers · 5 months ago

The source code seems be be snipped… Are you able to reupload or provide a link to it?

IA
ianmackers · 6 months ago

The volume weighted moving average (VWMA) is similar to the simple moving average; however, the VWMA places more emphasis on the volume recorded for each period.  A period is defined as the time interval preferred by the respective trader (i.e, 5, 15, 30).

Therefore, if you place a 20-period simple moving average (SMA) on your chart and at the same time, a 20-period volume weighted moving average, you will see that they pretty much follow the same trajectory.  However, on further review, you will notice the averages do not mirror each other exactly.

The reason for this discrepancy, as we previously stated is the VWMA emphasizes volume, while the SMA only factors the average of the closing price per period.

## Updated to sort out obsolete attributes ##

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class VWMA : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 14)]
        public int Periods { get; set; }

        [Output("Main", LineColor = "Aqua")] // Updated
        public IndicatorDataSeries Result { get; set; }

        public override void Calculate(int index)
        {
            double sum = 0.0;
            double totvol = 0.0;

            for (int i = index - Periods + 1; i <= index; i++)
            {
                sum += (Source[i] * Bars.TickVolumes[i]); // Updated
                totvol += Bars.TickVolumes[i]; // Updated
            }
            
            Result[index] = sum / totvol;        
        }
    }
}