Load more Historical Data

Created at 26 Sep 2016, 11: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!
JO

jonnylee.mc

Joined 03.03.2016

Load more Historical Data
26 Sep 2016, 11:46


Hello,

1. Is there any way to load data from a specified datetime? Like:

private MarketSeries seriesD;

seriesD = MarketData.GetSeries(TimeFrame.Daily, from Datetime ???);

 

2. How to force Indicator load more historical data by coding?

3. What is the maximum number of MarketSeries element? Or maximum of the "index" in:

public override void Calculate(int index)

Thanks!!


@jonnylee.mc
Replies

elmpie
27 Mar 2020, 20:27

Any news on this?


@elmpie

PanagiotisCharalampous
30 Mar 2020, 08:04

Hi elmpie,

See an example below on how to load more history

Print("{0} bar on the chart. Loading 10 000 bars", Bars.Count);
while (Bars.Count < 10000)
{
    var loadedCount = Bars.LoadMoreHistory();
    Print("Loaded {0} bars", loadedCount);
    if (loadedCount == 0)
        break;
}
Print("Finished, total bars {0}", Bars.Count);

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

septumrar
01 May 2020, 09:01

RE:

PanagiotisCharalampous said:

Hi elmpie,

See an example below on how to load more history

Print("{0} bar on the chart. Loading 10 000 bars", Bars.Count);
while (Bars.Count < 10000)
{
    var loadedCount = Bars.LoadMoreHistory();
    Print("Loaded {0} bars", loadedCount);
    if (loadedCount == 0)
        break;
}
Print("Finished, total bars {0}", Bars.Count);

Best Regards,

Panagiotis 

Join us on Telegram

Thanks!!! It's really works


@septumrar

jani
10 Jan 2022, 20:08

Code is crashing cTrader

Hello,

 

I tried to use below in an indicator:

Print("{0} bar on the chart. Loading 10 000 bars", Bars.Count);
while (Bars.Count < 10000)
{
    var loadedCount = Bars.LoadMoreHistory();
    Print("Loaded {0} bars", loadedCount);
    if (loadedCount == 0)
        break;
}
Print("Finished, total bars {0}", Bars.Count);

and it practically crashed my cTrader every time I compiled the code while the indicator was attached to a 1H chart.


@jani

amusleh
11 Jan 2022, 08:37

RE: Code is crashing cTrader

jani said:

Hello,

 

I tried to use below in an indicator:

Print("{0} bar on the chart. Loading 10 000 bars", Bars.Count);
while (Bars.Count < 10000)
{
    var loadedCount = Bars.LoadMoreHistory();
    Print("Loaded {0} bars", loadedCount);
    if (loadedCount == 0)
        break;
}
Print("Finished, total bars {0}", Bars.Count);

and it practically crashed my cTrader every time I compiled the code while the indicator was attached to a 1H chart.

Hi,

I just tested your code on Spotware cTrader beta for EURUSD and GBPUSD H1 and it worked fine.

But there is an issue with your code, what if the symbol doesn't have that number of bars? then you will end up with an infinite loop which will crash your cTrader.

You don't know how many bars are available, so if you use a fixed number and symbol doesn't had that number of bars then it will crash your platform.


@amusleh

jani
11 Jan 2022, 12:04

RE: RE: Code is crashing cTrader

Hi,

thanks for the reply.  

I tried with different values for Bars.Count from 500 to 2000 and it seems to get  my computer stuck and takes cTrader CPU usage from the normal 7-20% to over 50% ( I have Windows 10, Intel i5-7600 CPU and 32 GB RAM)

My total bars on H1 after the code is done is over 70 000, so the issue should not be an infinite loop due to insufficient history bars.

 

amusleh said:

jani said:

Hello,

 

I tried to use below in an indicator:

Print("{0} bar on the chart. Loading 10 000 bars", Bars.Count);
while (Bars.Count < 10000)
{
    var loadedCount = Bars.LoadMoreHistory();
    Print("Loaded {0} bars", loadedCount);
    if (loadedCount == 0)
        break;
}
Print("Finished, total bars {0}", Bars.Count);

and it practically crashed my cTrader every time I compiled the code while the indicator was attached to a 1H chart.

Hi,

I just tested your code on Spotware cTrader beta for EURUSD and GBPUSD H1 and it worked fine.

But there is an issue with your code, what if the symbol doesn't have that number of bars? then you will end up with an infinite loop which will crash your cTrader.

You don't know how many bars are available, so if you use a fixed number and symbol doesn't had that number of bars then it will crash your platform.

 


@jani

PanagiotisCharalampous
11 Jan 2022, 14:24

Hi Jani,

May we have the symbol, timeframe and broker on which this issue appears?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

jani
13 Jan 2022, 13:00

RE:

Hi Panagiotis,

Symbol: EURUSD, TF: 1H  Broker: IC Markets. Also used other symbols like XAUUSD with same results

Br,

Jani

 

 


@jani

PanagiotisCharalampous
13 Jan 2022, 13:16

Hi Jani,

No luck by me either. Any chance you can record this in a video so that we can see the steps you follow and the issue you experience?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

jani
21 Jan 2022, 11:30 ( Updated at: 21 Jan 2022, 12:08 )

RE:

Hi Panagiotis,

 

I think one of the  problems was that the code was printing on every index into the log file and that  took a long time to run.

I changed the code so that print would just activate at the end and used BarsToLoad = 70 000

 

     while (Bars.Count < BarsToLoad)
            {
                var loadedCount = Bars.LoadMoreHistory();
             
                if (loadedCount == 0)
                    break;
            }
    if (Bars.Count >= BarsToLoad)Print("  ||  Bar count: ", Bars.Count, "  ||  Index: ", index);

I'm still getting the same increase in CPU usage. I uploaded a video about the code running on Pepperstone , link below:

Also cannot figure out what is the purpose of "loadedCount" as it seems to always return 0?


@jani