Description
Polychromatic Momentum Extended indicator
Denis Meyers that invented Polychromatic Momentum, describes it as:
Momentum is defined as the difference, or percent change, between the current bar and a bar some lookback period in the past. The major problem with using momentum based indicators is that the optimum lookback period seems to change over time creating losses with the current chosen lookback period.
To avoid the errors due to a single lookback period we create an indicator that takes an weighted average of all significant lookback periods for the tradable. We named this indicator polychromatic because poly means many and chromatic means colors. Thus, Polychromatic Momentum for this indicator translates into the sum of many Momentums.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class mPolychromaticMomentumExtended : Indicator
{
[Parameter("Momentum Period (20)", DefaultValue = 20)]
public int inpPeriodMomentum { get; set; }
[Parameter("Smooth Period (5)", DefaultValue = 5)]
public int inpPeriodSmooth { get; set; }
[Parameter("Average Source (close)", DefaultValue = "Close")]
public DataSeries inpSource { get; set; }
[Output("SmootherMomentumStops", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outPolychromaticMomentum { get; set; }
[Output("PolychromaticMomentumFIR", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outPolychromaticMomentumFIR { get; set; }
private double alpha;
private IndicatorDataSeries _mom, _mom1, _mom2, _price, _fir;
protected override void Initialize()
{
alpha = 2.0 / (1.0 + Math.Sqrt(inpPeriodSmooth));
_mom = CreateDataSeries();
_mom1 = CreateDataSeries();
_mom2 = CreateDataSeries();
_price = CreateDataSeries();
_fir = CreateDataSeries();
}
public override void Calculate(int i)
{
_mom1[i] = _mom1[i - 1] + alpha * (inpSource[i] - _mom1[i - 1]);
_mom2[i] = _mom2[i - 1] + alpha * (_mom1[i] - _mom2[i - 1]);
_price[i] = _mom2[i];
double sumMom = 0;
double sumWgh = 0;
for (int j = 0; j < inpPeriodMomentum && (i - j - 1) >= 0; j++)
{
double weight = Math.Sqrt(j + 1);
sumMom += (inpSource[i] - inpSource[i - j - 1]) / weight;
sumWgh += weight;
}
_mom[i] = (sumWgh != 0) ? sumMom / sumWgh : 0;
_fir[i] = (i > inpPeriodMomentum + 3 ? (_mom[i] + 2.0 * _mom[i - 1] + 2.0 * _mom[i - 2] + _mom[i - 3]) / 6.0 : _mom[i]);
outPolychromaticMomentum[i] = _mom[i];
outPolychromaticMomentumFIR[i] = _fir[i];
}
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mPolychromaticMomentumExtended.algo
- Rating: 5
- Installs: 732
- Modified: 25/01/2023 22:02