Description
I cant believe nobody took the time to convert this simple and useful Metatrader indicator to cAlgo
Thats what i have just done. Please feel free to fine tune & share your improvements on this portal
There's also the Power Weighted MovingAverage Crossover indicator PWMA CrossOver Signal Indicator | Algorithmic Forex Trading | cTrader Community
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class LWMA_CrossOver_Signal : Indicator
{
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("Fast LWMA (5)",DefaultValue = 5)]
public int Fast_LWMA { get; set; }
[Parameter("Slow LWMA (6)", DefaultValue = 6)]
public int Slow_LWMA { get; set; }
[Parameter("M.A Type", DefaultValue = MovingAverageType.Weighted )]
public MovingAverageType MA_Type { get; set; }
[Parameter("Shift (1)", DefaultValue = 1)]
public int Shift { 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 MovingAverage FasterLWMA, SlowerLWMA;
protected override void Initialize()
{
FasterLWMA = Indicators.MovingAverage(Source, Fast_LWMA, MA_Type);
SlowerLWMA = Indicators.MovingAverage(Source, Slow_LWMA, MA_Type);
}
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/10.0;
int i = 1;
double fasterLWMAnow = FasterLWMA.Result.Last(i);
double fasterLWMAprevious = FasterLWMA.Result.Last(i+1);
double fasterLWMAafter = FasterLWMA.Result.Last(i -1);
double slowerLWMAnow = SlowerLWMA.Result.Last(i);
double slowerLWMAprevious = SlowerLWMA.Result.Last(i+1);
double slowerLWMAafter = SlowerLWMA.Result.Last(i -1);
if(fasterLWMAnow.CompareTo(slowerLWMAnow) > 0 && fasterLWMAprevious.CompareTo(slowerLWMAprevious) < 0 && fasterLWMAafter.CompareTo(slowerLWMAafter) > 0)
{
CrossUp[index-Shift-1] = Bars.LowPrices[index-Shift-1] - Range * 0.5;
}
else if(fasterLWMAnow.CompareTo(slowerLWMAnow) < 0 && fasterLWMAprevious.CompareTo(slowerLWMAprevious) > 0 && fasterLWMAafter.CompareTo(slowerLWMAafter) < 0)
{
CrossDn[index-Shift-1] = Bars.HighPrices[index-Shift-1] + Range * 0.5;
}
}
}
}
GM
gmkenneyy
Joined on 20.03.2020 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: LWMA_CrossOver_Signal.algo
- Rating: 5
- Installs: 1023
- Modified: 16/03/2023 22:14
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
I don't yet understand how to fine-tune the indicators