Category Trend  Published on 10/04/2023

PWMA CrossOver Signal

Description

This was adapted from the "Power Weighted Moving Average" indicator created / uploaded by mfieza

Power Weighted / Weighted delta Indicator | Algorithmic Forex Trading | cTrader Community

This is a slightly better weighted moving average crossover in that you can vary the weight accordingly

What this does is give you earlier / later signals depending on the Power value (weight) chosen.

Please be aware that values for the H1 do not neccessarily apply to the D1 - you have find the best settings for your chosen timeframe

Please feel free to fine-tune the code and share your improvements (if any) on this portal.

Enjoy!

P.S

Theres also the Linear Weighted Moving Average indicator LWMA CrossOver Signal Indicator | Algorithmic Forex Trading | cTrader Community

Settings for the H1

 

Settings for the D1 (these settings are by no means holy) - find the combination that suits you best


using cAlgo.API;
using System;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class PWMA_CrossOver_Signal_H1 : Indicator
    {    
        [Parameter("Source (close)")]
        public DataSeries Source { get; set; }
        
        [Parameter("Fast LWMA (7)",DefaultValue = 7)]
        public int Fast_LWMA { get; set; }
        
        [Parameter("Slow LWMA (6)", DefaultValue = 6)]
        public int Slow_LWMA { get; set; }

        [Parameter("Power (1.7)", DefaultValue = 1.7)]
        public double Power { get; set; }

        
        
        [Output("CrossUp", LineColor = "Lime", PlotType = PlotType.Points, LineStyle = LineStyle.Dots, Thickness = 8)]
        public IndicatorDataSeries CrossUp { get; set; }
        
        [Output("CrossDn", LineColor = "HotPink", PlotType = PlotType.Points, LineStyle = LineStyle.Dots, Thickness = 8)]
        public IndicatorDataSeries CrossDn { get; set; }


        private double GetValue(int idx, int prd, double pwr)
        {
            double summ = 0.0, sumpw = 0.0;

            for (int j = 0; j < prd; j++)
            {
                var pw = Math.Pow(prd - j, pwr);

                summ += pw * (idx > prd + 1 ? Source[idx - j] : Source[idx]);
                sumpw += pw;
            }

            return (sumpw != 0 ? summ / sumpw : double.NaN);
        }

        protected override void Initialize(){}

        public override void Calculate(int index)
        { 
            double AvgRange = 0.0;
              
            for(int x = 11; x > 0; x--)
            {
                AvgRange += Math.Abs(Bars.HighPrices.Last(x) - Bars.LowPrices.Last(x));
            }

            double Range = AvgRange * 0.1;

            int i = index -1;

            double fasterLWMAnow = GetValue(i, Fast_LWMA, Power);
            double fasterLWMAprevious = GetValue(i +1, Fast_LWMA, Power);
            double fasterLWMAafter = GetValue(i -1, Fast_LWMA, Power);

            double slowerLWMAnow = GetValue(i, Slow_LWMA, Power);
            double slowerLWMAprevious = GetValue(i +1, Slow_LWMA, Power);
            double slowerLWMAafter = GetValue(i -1, Slow_LWMA, Power);

            if (fasterLWMAnow.CompareTo(slowerLWMAnow) > 0 && fasterLWMAprevious.CompareTo(slowerLWMAprevious) < 0 && fasterLWMAafter.CompareTo(slowerLWMAafter) > 0)
            {
                CrossUp[index] = Bars.LowPrices[index] - Range * 0.5;
            }
            else if(fasterLWMAnow.CompareTo(slowerLWMAnow) < 0 && fasterLWMAprevious.CompareTo(slowerLWMAprevious) > 0 && fasterLWMAafter.CompareTo(slowerLWMAafter) < 0)
            {
                CrossDn[index] = Bars.HighPrices[index] + Range * 0.5;
            }
        }
   }    
}

GM
gmkenneyy

Joined on 20.03.2020 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: PWMA_CrossOver_Signal_H1.algo
  • Rating: 5
  • Installs: 804
  • Modified: 20/03/2023 19:58
Comments
Log in to add a comment.
No comments found.