DA
Topics
29 Aug 2019, 20:50
1628
6
22 Aug 2019, 12:56
1121
1
24 Jul 2019, 14:27
1113
4
Replies
danblack9988
31 Aug 2019, 14:28
Hi
Thank you very much for that, i see how it works now.
Unfortunately I am still not getting the result I expected when i call Print(dma.MA1.Last(1));
It returns Nan, which I have read menas not a number. I was expecting a Y axis position to be returned so that i could compare the MA level with price and other MAs.
Can you tell me why it is returning NaN?
//CODE OF ROBOT ---------------------------
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SRBotWIP : Robot
{
[Parameter("Timeframe 1", DefaultValue = "Minute15")]
public TimeFrame MATimeframe1 { get; set; }
[Parameter("Periods DMA", DefaultValue = 14)]
public int PeriodsDMA { get; set; }
[Parameter("Type DMA", DefaultValue = MovingAverageType.Weighted)]
public MovingAverageType typeDMA { get; set; }
double dpp, dr1, dr2, dr3, ds1, ds2, ds3, wpp, wr1, wr2,
wr3, ws1, ws2, ws3, mpp, mr1, mr2, mr3, ms1, ms2,
ms3;
public MTFMA dma;
protected override void OnStart()
{
dma = Indicators.GetIndicator<MTFMA>(MATimeframe1, PeriodsDMA, typeDMA);
}
//INDICATOR CODE ----------------
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None, TimeZone = TimeZones.UTC)]
public class MTFMA : Indicator
{
[Parameter("Timeframe 1", DefaultValue = "Minute15")]
public TimeFrame MATimeframe1 { get; set; }
[Parameter(DefaultValue = 14)]
public int Periods1 { get; set; }
[Parameter("FMA Type", DefaultValue = MovingAverageType.Weighted)]
public MovingAverageType MAType { get; set; }
[Output("Timeframe 1", Color = Colors.Lime, Thickness = 1)]
public IndicatorDataSeries MA1 { get; set; }
private MarketSeries series1;
private MovingAverage Ma1;
protected override void Initialize()
{
series1 = MarketData.GetSeries(MATimeframe1);
Ma1 = Indicators.MovingAverage(series1.Close, Periods1, MAType);
}
public override void Calculate(int index)
{
{
var index1 = GetIndexByDate(series1, MarketSeries.OpenTime[index]);
if (index1 != -1)
{
MA1[index] = Ma1.Result[index1];
}
}
}
private int GetIndexByDate(MarketSeries series, DateTime time)
{
for (int i = series.Close.Count - 1; i > 0; i--)
{
if (time == series.OpenTime[i])
return i;
}
return -1;
}
}
}
@danblack9988
danblack9988
24 Jul 2019, 20:47
@danblack9988
danblack9988
05 Sep 2019, 21:30
Ah thats great thank you very much!
@danblack9988