TimeSeriesMovingAverage and historic data problem
TimeSeriesMovingAverage and historic data problem
28 Apr 2018, 05:12
When using a TimeSeriesMovingAverage on an hourly dataseries, it returns Nan for several days until enough data is collected, however something like ExponentialMovingAverage works straight away
Does anyone know of a workaround for this issue?
Code example:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { public ExponentialMovingAverage ema; public TimeSeriesMovingAverage tsma; public RelativeStrengthIndex RSI; private MarketSeries time; private int min; public bool CalcTime() { bool result = false; if (min != Server.Time.Minute) { result = true; min = Server.Time.Minute; } return (result); } protected override void OnStart() { time = MarketData.GetSeries(Symbol, TimeFrame.Hour); RSI = Indicators.RelativeStrengthIndex(time.Close, 14); ema = Indicators.ExponentialMovingAverage(RSI.Result, 200); tsma = Indicators.TimeSeriesMovingAverage(RSI.Result, 200); } protected override void OnBar() { if (CalcTime()) { Print("tsma: " + tsma.Result.Last(0)); Print("ema: " + ema.Result.Last(0)); } } } }
Replies
MHBB
07 May 2018, 14:29
RE:
Hi Panagiotis,
Because of the limit of data loaded through GetSeries, there isn't enough data to calculate the TSMA
In a forum post before Spotware said they would add the feature to select how much data to load, is this still in progress?
Example:
MarketData.GetSeries("MARKET", TimeFrame.Hour, 200)
or something like
MarketData.GetSeries("MARKET", TimeFrame.Hour, TimeSpan.OneMonth)
This feature would be very useful
Thanks, Simon
@MHBB
PanagiotisCharalampous
07 May 2018, 17:22
Hi Simon,
This feature is in our backlog, however we do not have a release date or release version yet.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
07 May 2018, 11:49 ( Updated at: 29 Aug 2022, 08:36 )
Hi Simon,
There is no issue here, this is the way these averages are calculated. EMA allows you to calculate from the first value while TSMA does not.
Best Regards,
Panagiotis
@PanagiotisCharalampous