Topics

Forum Topics not found

Replies

bonedrak
16 May 2022, 11:21

RE: RE: RE: RE: Indicator data series from external data

amusleh said:

bonedrak said:

amusleh said:

bonedrak said:

Hi xabbu

 

did you ever find a solution to this 

 

thanks

anthony 

 

 

Hi,

Solution for which issue? Reading CSV file?

For creating an indicator data series from external source, either csv or json. 
 

Thanks

anthony 

Hi,

You can easily do that by reading the file, de-serializing it to an object, and then using them to populate an indicator data series.

For reading files: How to read from a text file - C# Programming Guide | Microsoft Docs

For CSV files use CsvHelper: A .NET library for reading and writing CSV files. Extremely fast, flexible, and easy to use. | CsvHelper (joshclose.github.io)

For JSON use System.Text.Json (cTrader 4.2 >): How to serialize and deserialize JSON using C# - .NET | Microsoft Docs

The last part is what I’m wondering about. Using the data to populate an indicator data series. How do you do that. 


@bonedrak

bonedrak
16 May 2022, 11:12

RE: RE: Indicator data series from external data

amusleh said:

bonedrak said:

Hi xabbu

 

did you ever find a solution to this 

 

thanks

anthony 

 

 

Hi,

Solution for which issue? Reading CSV file?

For creating an indicator data series from external source, either csv or json. 
 

Thanks

anthony 


@bonedrak

bonedrak
15 May 2022, 05:31

Indicator data series from external data

Hi xabbu

 

did you ever find a solution to this 

 

thanks

anthony 

 

 


@bonedrak

bonedrak
15 May 2022, 05:28 ( Updated at: 21 Dec 2023, 09:22 )

RE: indicator data series from external data

xabbu said:

Hello Panagiotis,

good news, thanks to your help, I managed to read a sample .csv file into an indicator. I read the site you gave me and get the best result with this adapted solution (and maybe it could help others when searching "cTrader import / importing csv file / data":

 

using System;
using System.IO;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using Microsoft.VisualBasic.FileIO;
using System.Globalization;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
    public class NewIndicator : Indicator
    {

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }




        protected override void Initialize()
        {
            var path = "C:\\Users\\xabbu\\Desktop\\evzTestklein.csv";
            //var path = "C:\\Users\\xabbu\\Desktop\\evzTest Kopie.csv";

            using (TextFieldParser csvParser = new TextFieldParser(path))
            {
                csvParser.CommentTokens = new string[] 
                {
                    "#"
                };
                csvParser.SetDelimiters(new string[] 
                {
                    ";"
                });
                csvParser.HasFieldsEnclosedInQuotes = true;

                // Skip the row with the column names
                csvParser.ReadLine();

                while (!csvParser.EndOfData)
                {
                    // Read current line fields, pointer moves to the next line.
                    string[] fields = csvParser.ReadFields();
                    string _datefield = fields[0];

                    string _evzValue = fields[1];
                    Print("Datum. " + Convert.ToDateTime(_datefield, CultureInfo.InvariantCulture) + " $EVZ: " + Convert.ToDouble(_evzValue, CultureInfo.InvariantCulture));
                }
            }
        }


        public override void Calculate(int index)
        {




        }
    }
}

 

I could also convert the fields in the .csv-file to an date and double value and printed it to the log:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

There are so many sources of C# knowledge and tutorials out there (I bought some c# courses on Udemy), but in combination with cTrader the internet wisdom is very limited. I found only 2 tutorials about cTrader / cAlgo programming to buy. One is extremly bad and outdatet and hardly to understand. The other one I bought for around $50 but it touches only the "standard" questions an procedures.

I think that is very frustrating, because cTrader is THE modern platform and years in advance compaired to the MarkeT-Leaders (-;... BUT: the interaction between the platform and the users in meaning of the choice of cBots and indicators is very small compared to the other platforms, if one compares the resources and indicators / bots available...

 

 

I would like to ask for your knowledge and kind help again:

How can I now, with this imported data from the .csv file, create the indicator data series correct, so that the imported values (date, value) can form the output of an cTrader indicator?

Kindest regards,

 

 

 

 

 


@bonedrak

bonedrak
14 Mar 2022, 10:03

RE: RE: RE: RE: can this be used for indicators as well as cbots?

amusleh said:

bonedrak said:

amusleh said:

bonedrak said:

is this possible using "private void RenkoSeries_OnBar(object sender, OhlcBar newBar, OhlcBar oldBar)" instead of "calculate(int index)"

 

Hi,

You should use RenkoSeries OnBar only in backtesting environment and the Calculate method on live mode.

I want to use a custom indicator in backtesting a cbot, but it wont allow me because it says the time frames are different, for the cbot  (which uses your renko bars) and the indicator (which uses "calculate(int index)").  So my question is, can an indicator be built that uses your library and renko bars? or will it only work on cbots?

Hi,

You can't feed a custom indicator the Renko generated bars, it's not possible.

The solution is to create a class for your indicator inside cBot project, pass it the Renko generated bars data and then call it's OnBar method whenever you receive a bar from Renko library.

It's little complicated but it's possible.

Thanks,

is it possible to show me an example of how to that, or to give an outline of the parts needed?


@bonedrak

bonedrak
14 Mar 2022, 08:47

RE: RE: can this be used for indicators as well as cbots?

amusleh said:

bonedrak said:

is this possible using "private void RenkoSeries_OnBar(object sender, OhlcBar newBar, OhlcBar oldBar)" instead of "calculate(int index)"

 

Hi,

You should use RenkoSeries OnBar only in backtesting environment and the Calculate method on live mode.

I want to use a custom indicator in backtesting a cbot, but it wont allow me because it says the time frames are different, for the cbot  (which uses your renko bars) and the indicator (which uses "calculate(int index)").  So my question is, can an indicator be built that uses your library and renko bars? or will it only work on cbots?


@bonedrak

bonedrak
14 Mar 2022, 05:20

can this be used for indicators as well as cbots?

is this possible using "private void RenkoSeries_OnBar(object sender, OhlcBar newBar, OhlcBar oldBar)" instead of "calculate(int index)"

 


@bonedrak