Getting NaN values for Previous Day MarketData while exporting csv

Created at 01 Sep 2023, 21:46
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!
AS

ashish.sah.np

Joined 19.12.2022

Getting NaN values for Previous Day MarketData while exporting csv
01 Sep 2023, 21:46


getting NaN values in column dailyO,dailyH,dailyL,dailyC. What Might have gone wrong in this case.

using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class DumpToCSV : Robot
    {
        protected override void OnStop()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var folderPath = Path.Combine(desktopFolder, "trendbars");
            Directory.CreateDirectory(folderPath);
            var filePath = Path.Combine(folderPath, Symbol.Code + " " + TimeFrame + ".csv");
            using (var writer = File.CreateText(filePath))
            {
                writer.WriteLine(ConcatWithComma("time", "open", "high", "low", "close", "volume","dopen", "dhigh", "dlow", "dclose"));
                for (var i = 0; i < MarketSeries.Close.Count; i++)
                {   
                    // Assuming Bars.OpenTimes[i] is a DateTime object
                    DateTime openTime = Bars.OpenTimes[i];
                    // Format the DateTime as a string in ISO 8601 format
                    string formattedDateTime = openTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    var daily = MarketData.GetSeries(TimeFrame.Daily);
                    double dailyH = daily.High.Last(1);     
                    double dailyL = daily.Low.Last(1);     
                    double dailyO = daily.Open.Last(1);     
                    double dailyC = daily.Close.Last(1);     
                    // Write the formatted string to your output
                    writer.WriteLine(ConcatWithComma(
                        formattedDateTime,
                        MarketSeries.Open[i],
                        MarketSeries.High[i],
                        MarketSeries.Low[i],
                        MarketSeries.Close[i],
                        MarketSeries.TickVolume[i],
                        dailyO,
                        dailyH,
                        dailyL,
                        dailyC
                        ));

                }
            }
        }

        private string ConcatWithComma(params object[] parameters)
        {
            return string.Join(",", parameters.Select(p => p.ToString()));
        }
    }
}

@ashish.sah.np