Got NaA when accessing moving average result. LoadMoreHistory() does not help either

Created at 02 Oct 2020, 06:42
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
NO

noppanon

Joined 17.05.2017

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


@noppanon
Replies

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

noppanon
02 Oct 2020, 11:54

Hi Panagiotis,

   Thank you for response on this problem. 

   So what is your suggestion to get MA value?

 

Noppanon


@noppanon