cAlgo Backtesting Log issue

Created at 28 Mar 2018, 12:37
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!
irmscher9's avatar

irmscher9

Joined 22.12.2016

cAlgo Backtesting Log issue
28 Mar 2018, 12:37


Hi there

I'm Backtesting bots a lot. I output a lot of data about the trading process through the Log. So up until now I've been backtesting my bots from 2014 up to a present day and getting all the neccessary info through Log from 2014 up to the end (Ok, may be the first half of 2014 used to be cut)

Now when I'm running backtests I'm only getting Log data from Nov 2017... I simply canno't slide the Log lower to get 2016, 2015 and 2014 data anymore.

This issue is present for a couple of days. 


@irmscher9
Replies

PanagiotisCharalampous
28 Mar 2018, 12:40

Hi irmscher,

Which version do you use, 2.01 or 3.0?

Best Regards,

Panagiotis


@PanagiotisCharalampous

irmscher9
28 Mar 2018, 12:49

2.1


@irmscher9

irmscher9
28 Mar 2018, 13:18

Everything was OK with that version up until recently. Only half of 2014 year log data has been cut but I thought it's because I output too much "Print" commands. Now I don't know...


@irmscher9

PanagiotisCharalampous
28 Mar 2018, 14:19

Hi irmscher9,

A maximum of 10000 records can be shown in the Log grid. Can you check if you are not exceeding that number?

Best Regards,

Panagiotis


@PanagiotisCharalampous

irmscher9
28 Mar 2018, 19:50

Right, Ok, I think I know what the issue might be.

In order to calculate rows I've right-clicked on the Log, copied all and then pasted to Excel spreadsheet. Yes, it's showing 10k rows.

But the problem is, most of the rows are taken by things like this "22/11/2017 08:14:04.056 | → Modifying position PID608 (SL: 1.17568241403729, TP: null) SUCCEEDED, Position PID608". 

So I guess it's 10k but for not only my outputs. How do I make those "Modifying position" messages not show up? 10k will be enough then I guess.

By the way, why is it limited to 10k?


@irmscher9

PanagiotisCharalampous
29 Mar 2018, 09:29

Hi irmscher9,

There is no option to avoid these messages. A workaround would be to save these messages yourself in a csv file. This way you will have no limits in the number of messages you can store.

Best Regards,

Panagiotis


@PanagiotisCharalampous

irmscher9
29 Mar 2018, 12:00

What do you mean by "save these messages yourself in a csv file"

How do I do that?


@irmscher9

PanagiotisCharalampous
29 Mar 2018, 12:06

Hi irmscher9

Here is a nice article on Reading and Writing CSV Files in C#

Best Regards,

Panagiotis


@PanagiotisCharalampous

irmscher9
29 Mar 2018, 13:45

Thanks Panagiotis :)


@irmscher9

MaRCHeW
29 Mar 2018, 17:08

RE:

Hi,

Try this: https://joshclose.github.io/CsvHelper/

Regards

MaRCHeW

Panagiotis Charalampous said:

Hi irmscher9

Here is a nice article on Reading and Writing CSV Files in C#

Best Regards,

Panagiotis

 


@MaRCHeW

irmscher9
29 Mar 2018, 18:05

Panagiotis, but why is it limited to 10000 records? It's not a web application that's consuming server resources...

It's just a bit weird. Now it seriously hurdles my backtesting process. Even if I make it export to csv it will significantly slow down the whole process.

So I'm wondering what is the actual reason for limiting it to 10k?


@irmscher9

PanagiotisCharalampous
30 Mar 2018, 09:19

Hi irmscher9,

Programmers always put limits in such functionalities to avoid any unexpected issues. It is a part of a defensive programming strategy. So our programmers set an arbitrary high limit for this functionality as well. There is no justification why 10000 and not 9000 or 11000. It is just a high enough number that is adequate for almost all use cases and ensures the smooth operation of the application as well. Apparently, nobody complained for years :) If this is so important for you, I can investigate if it can be increased in one of the following updates.

Best Regards,

Panagiotis


@PanagiotisCharalampous

irmscher9
30 Mar 2018, 11:20

Yes, that would be wonderful.

Well, actually 10k was enough for me too up until I have implemented a number of Trailing Stop blocks in my bot so every time the position is modified it gets outlined in the log and I think it takes like 50-70% of the space.

Actually if there would be 10k limit solely for "Info" section of the log, that would be OK I guess.

 


@irmscher9

irmscher9
04 Jun 2018, 20:46

Hey Panagiotis,

Firstly, is there any news on expanding the 10k limit?

Secondly, I've tried writing the data to an .csv file from the cBot and I'm getting some errors (I'm not very much of a C# coder):

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

using System.Collections.Generic;
using System.IO;
using System.Text;


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class WriteFiles : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        /// <summary>
        /// Class to store one CSV row
        /// </summary>
        public class CsvRow : List<string>
        {
            public string LineText { get; set; }
        }

        /// <summary>
        /// Class to write data to a CSV file
        /// </summary>
        public class CsvFileWriter : StreamWriter
        {
            public CsvFileWriter(Stream stream) : base(stream)
            {
            }

            public CsvFileWriter(string filename) : base(filename)
            {
            }

            /// <summary>
            /// Writes a single row to a CSV file.
            /// </summary>
            /// <param name="row">The row to be written</param>
            public void WriteRow(CsvRow row)
            {
                StringBuilder builder = new StringBuilder();
                bool firstColumn = true;
                foreach (string value in row)
                {
                    // Add separator if this isn't the first value
                    if (!firstColumn)
                        builder.Append(',');
                    // Implement special handling for values that contain comma or quote
                    // Enclose in quotes and double up any double quotes
                    if (value.IndexOfAny(new char[] 
                    {
                        '"',
                        ','
                    }) != -1)
                        builder.AppendFormat("\"{0}\"", value.Replace("\"", "\"\""));
                    else
                        builder.Append(value);
                    firstColumn = false;
                }
                row.LineText = builder.ToString();
                WriteLine(row.LineText);
            }
        }

        void WriteTest()
        {
            // Write sample data to CSV file
            using (CsvFileWriter writer = new CsvFileWriter("WriteTest.csv"))
            {
                for (int i = 0; i < 100; i++)
                {
                    CsvRow row = new CsvRow();
                    for (int j = 0; j < 5; j++)
                        row.Add(String.Format("Column{0}", j));
                    writer.WriteRow(row);
                }
            }
        }

        protected override void OnStart()
        {
            string A = "hello";
            
            //-- Any of these 2 should work, I guess?
            //CsvFileWriter.WriteRow(A);
            WriteTest(A);
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

 


@irmscher9

PanagiotisCharalampous
05 Jun 2018, 10:32

Hi irmscher9,

There are no updates about this. Regarding your code, the issue is that you pass a parameter to a function that does not take a parameter. What are you trying to achieve with this piece of code?

Best Regards,

Panagiotis


@PanagiotisCharalampous

irmscher9
06 Jun 2018, 18:13

I'm trying to write data to an CSV file, since "ModifyPosition" notifications takes all of the log and I can't analyze the backtesting of my bots properly.


@irmscher9

ClickAlgo
09 Jun 2018, 08:22 ( Updated at: 21 Dec 2023, 09:20 )

You can use this assembly which encapsulates (hides) all the complex code and allows you to write to a file with a single line of code.

Its free and there is also a video demo on the product page.

https://clickalgo.com/ctrader-cbot-indicator-data-logger

EXAMPLE USAGE

Paul Hayes
Sales & Marketing
Emailcontact@clickalgo.com
Phone: (44) 203 289 6573
Websitehttps://clickalgo.com

 


@ClickAlgo

ryanoia@gmail.com
21 Jul 2019, 09:41 ( Updated at: 21 Dec 2023, 09:21 )

RE:

ClickAlgo said:

You can use this assembly which encapsulates (hides) all the complex code and allows you to write to a file with a single line of code.

Its free and there is also a video demo on the product page.

https://clickalgo.com/ctrader-cbot-indicator-data-logger

EXAMPLE USAGE

Paul Hayes
Sales & Marketing
Emailcontact@clickalgo.com
Phone: (44) 203 289 6573
Websitehttps://clickalgo.com

 

The link posted doesn't work anymore. Is this still being offered? 


@ryanoia@gmail.com