Daily Market Series error

Created at 06 Aug 2019, 12:58
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!
IA

iandliversage@gmail.com

Joined 06.08.2019

Daily Market Series error
06 Aug 2019, 12:58


Hi guys,
I am having trouble getting daily data for certain indices. The code works fine for each of the 28 FX pairs I have tried and is not a problem on #Japan225, #US30 or #USSPX500, but as soon as I try to run it on #AUS200, #Euro50, #France40, #Germany30, #UK100 or #USNDAQ100 I get the error.

I am not a very experienced programmer so I may have missed something obvious. Any help with this would be greatly appreciated.

protected override void OnStart()
        {
            try
            {
                Print("Connecting...");
                SQLConnection.DatabaseUsername = "********";
                SQLConnection.DatabasePassword = "********";
                SQLConnection.DatabaseLocation = "********";
                SQLConnection.DatabaseName = "bar";
                Print("Done");

                Print("Getting Market Series");
                //}
                //Series1 = MarketData.GetSeries(TimeFrame.Minute);
                //Series2 = MarketData.GetSeries(TimeFrame.Minute2);
                //Series3 = MarketData.GetSeries(TimeFrame.Minute3);
                //Series4 = MarketData.GetSeries(TimeFrame.Minute4);
                Series5 = MarketData.GetSeries(TimeFrame.Minute5);
                Print("Minute5");
                //Series6 = MarketData.GetSeries(TimeFrame.Minute6);
                //Series7 = MarketData.GetSeries(TimeFrame.Minute7);
                //Series8 = MarketData.GetSeries(TimeFrame.Minute8);
                //Series9 = MarketData.GetSeries(TimeFrame.Minute9);
                //Series10 = MarketData.GetSeries(TimeFrame.Minute10);
                Series11 = MarketData.GetSeries(TimeFrame.Minute15);
                Print("Minute15");
                //Series12 = MarketData.GetSeries(TimeFrame.Minute20);
                //Series13 = MarketData.GetSeries(TimeFrame.Minute30);
                //Series14 = MarketData.GetSeries(TimeFrame.Minute45);
                Series15 = MarketData.GetSeries(TimeFrame.Hour);
                Print("Hour");
                //Series16 = MarketData.GetSeries(TimeFrame.Hour2);
                //Series17 = MarketData.GetSeries(TimeFrame.Hour3);
                Series18 = MarketData.GetSeries(TimeFrame.Hour4);
                Print("Hour4");
                //Series19 = MarketData.GetSeries(TimeFrame.Hour6);
                //Series20 = MarketData.GetSeries(TimeFrame.Hour8);
                //Series21 = MarketData.GetSeries(TimeFrame.Hour12);
                Series22 = MarketData.GetSeries(TimeFrame.Daily);
                Print("Daily");
                //Series23 = MarketData.GetSeries(TimeFrame.Day2);
                //Series24 = MarketData.GetSeries(TimeFrame.Day3);
                Series25 = MarketData.GetSeries(TimeFrame.Weekly);
                Print("Weekly");
                Series26 = MarketData.GetSeries(TimeFrame.Monthly);
                Print("Monthly");

                Print("Done");
                //UpdateTimeframe(Series1, "M1");
                //UpdateTimeframe(Series2, "M2");
                //UpdateTimeframe(Series3, "M3");
                //UpdateTimeframe(Series4, "M4");
                UpdateTimeframe(Series5, "M5");
                //UpdateTimeframe(Series6, "M6");
                //UpdateTimeframe(Series7, "M7");
                //UpdateTimeframe(Series8, "M8");
                //UpdateTimeframe(Series9, "M9");
                //UpdateTimeframe(Series10, "M10");
                UpdateTimeframe(Series11, "M15");
                //UpdateTimeframe(Series12, "M20");
                //UpdateTimeframe(Series13, "M30");
                //UpdateTimeframe(Series14, "M45");
                UpdateTimeframe(Series15, "H1");
                //UpdateTimeframe(Series16, "H2");
                //UpdateTimeframe(Series17, "H3");
                UpdateTimeframe(Series18, "H4");
                //UpdateTimeframe(Series19, "H6");
                //UpdateTimeframe(Series20, "H8");
                //UpdateTimeframe(Series21, "H12");
                UpdateTimeframe(Series22, "D1");
                //UpdateTimeframe(Series23, "D2");
                //UpdateTimeframe(Series24, "D3");
                UpdateTimeframe(Series25, "W1");
                UpdateTimeframe(Series26, "MN");
                lastm1barcommited = Series5.OpenTime[Series5.Close.Count - 1];
                //SendDebug(Symbol.Code + " Connected!");
            } catch
            {
                Print("Error");
            }
        }

 


@iandliversage@gmail.com
Replies

firemyst
17 Aug 2019, 18:19

RE:

A few suggestions:

1) You know it gets to line 35 from the log file and prints out "Hour4", so comment out every line after that and see if things work. If so, Uncomment line by line to see exactly which one is causing you the error.

2) Change your "catch" statement to "catch (Exception e)" and then change the print statement to be:

Print("Error: {0}", e.Message);

 

That should hopefully give you a good start.


@firemyst

leohermoso
17 Aug 2019, 21:09

using System;
using System.Linq;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.IO;
using System.Text;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.ESouthAmericaStandardTime, AccessRights = AccessRights.FullAccess)]
    public class DataGet : Robot
    {



        string fname;
        List<string> mylist = new List<string>();

        protected override void OnStart()
        {

            fname = Symbol.Name + TimeFrame.ToString();
            string directory = string.Format("{0}{1}", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "\\Data\\");

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            fname = string.Format("{0}{1}{2}", directory, fname, ".csv");



            for (int idx = MarketSeries.Close.Count; idx > 0; idx--)
            {
                if (double.IsNaN(MarketSeries.High.Last(idx)))
                    continue;
                mylist.Add(MarketSeries.OpenTime.Last(idx).ToString() + ";" + MarketSeries.OpenTime.Last(idx).DayOfWeek + ";" + MarketSeries.High.Last(idx).ToString().Replace(",", ".") + ";" + MarketSeries.Low.Last(idx).ToString().Replace(",", ".") + ";" + MarketSeries.Close.Last(idx).ToString().Replace(",", ".") + ";" + MarketSeries.Open.Last(idx).ToString().Replace(",", "."));

            }

            Stop();

        }




        protected override void OnStop()
        {
            File.WriteAllLines(fname, mylist, Encoding.UTF8);
        }
    }

}

I use this code the generate csv files... Then you can dump it to your mysql database! Just scroll the chart back for the time you want the data from, choose the time frame and hit the play button on the bot! It will save it under documents/data/SymbolNameTimeFrame.csv 


@leohermoso