Hull Moving Average (HMA MTF) in cBot
Created at 10 Nov 2020, 22:09
NO
Hull Moving Average (HMA MTF) in cBot
10 Nov 2020, 22:09
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class HMAMTF : Indicator
{
[Parameter("TimeFrame")]
public TimeFrame CustomTimeFrame { get; set; }
[Parameter("Price")]
public HMA.PriceType Price { get; set; }
[Parameter("Period", DefaultValue = 14, MinValue = 1)]
public int Period { get; set; }
[Parameter("MA Type", DefaultValue = MovingAverageType.Weighted)]
public MovingAverageType MaType { get; set; }
[Output("UpTrend", PlotType = PlotType.DiscontinuousLine, LineColor = "#00FFFF", Thickness = 3)]
public IndicatorDataSeries UpTrend { get; set; }
[Output("DownTrend", PlotType = PlotType.DiscontinuousLine, LineColor = "#DC143C", Thickness = 3)]
public IndicatorDataSeries DownTrend { get; set; }
public IndicatorDataSeries Result { get; private set; }
private MarketSeries _marketSeries;
private HMA _hma;
protected override void Initialize()
{
Result = CreateDataSeries();
_marketSeries = MarketData.GetSeries(CustomTimeFrame);
_hma = Indicators.GetIndicator<HMA>(_marketSeries, Price, Period, MaType);
}
public override void Calculate(int index)
{
var barIndex = _marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index]);
if (barIndex < 0)
return;
var result = _hma.Result[barIndex];
var trend = _hma.Trend[barIndex];
for (var i = index; i >= MarketSeries.OpenTime.GetIndexByTime(_marketSeries.OpenTime[barIndex]); i--)
{
Result[i] = result;
if (trend > 0)
{
UpTrend[i] = result;
UpTrend[i - 1] = Result[i - 1];
DownTrend[i] = double.NaN;
}
else if (trend < 0)
{
DownTrend[i] = result;
DownTrend[i - 1] = Result[i - 1];
UpTrend[i] = double.NaN;
}
}
}
}
}
Hi! I want to add this indicator in a cBot, I hope someone has an example of how it is implemented. Thanks
firemyst
11 Nov 2020, 14:10
Link on Spotware's site on how to include custom indicators witihn indicators. It's the same for bots.
@firemyst