Got NaA when accessing moving average result. LoadMoreHistory() does not help either
Created at 02 Oct 2020, 06:42
Got NaA when accessing moving average result. LoadMoreHistory() does not help either
02 Oct 2020, 06:42
Hi there,
I got NaN values when I have very long MA periods. Please sample code below.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class DualMA : Robot
{
[Parameter("Fast MA period", DefaultValue = 500)]
public int FastPeriods { get; set; }
[Parameter("Slow MA period", DefaultValue = 1500)]
public int SlowPeriods { get; set; }
MovingAverage FastMa, SlowMa;
DataSeries Closed;
protected override void OnStart()
{
Closed = Bars.ClosePrices;
FastMa = Indicators.MovingAverage(Closed, FastPeriods, MovingAverageType.Simple);
SlowMa = Indicators.MovingAverage(Closed, SlowPeriods, MovingAverageType.Simple);
}
protected override void OnTick()
{
int bars = 0;
do
{
bars = Bars.LoadMoreHistory();
Print("Loaded {0} bars, Closed {1:F5} fast {2:F5} slow {3:F5}",
bars, Closed.LastValue, FastMa.Result.LastValue, SlowMa.Result.LastValue);
} while (double.IsNaN(SlowMa.Result.LastValue));
}
protected override void OnStop()
{
}
}
}
I can't access values of MA when I used 1hour timeframe. But closed price was fine.
But I I run on 1m timeframe. It worked fine. How can I code to access MA values when I have 1000+ periods?
BTW, The error are shown on back testing.
Thanks in advance
Noppanon
PanagiotisCharalampous
02 Oct 2020, 09:38
Hi noppanon,
LoadMoreHistory() is not supported in Backtesting at the moment
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous