How to specify MarketSeries date range?

Created at 08 Aug 2018, 03:44
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!
rohingosling's avatar

rohingosling

Joined 02.08.2018

How to specify MarketSeries date range?
08 Aug 2018, 03:44


Is there a way to specify the date range of a MarketSeries in a cBot?

For instance, I would like to return the open, high, low, and close prices, for the 1 minute bars, between two dates.

As an example, I would like to loop through all the minutes between say, the 1st Jan 2014, and the 1st Jan 2017, in order to get the open, high, low, and close price for each minute in that date range.

This would 'probably' run in the OnStart method, and the code could look like something along the following lines.

protected override void OnStart()
{
	// Specify date range.

	DateTime date_start = new DateTime(2014, 1, 1, 0, 0, 0);    // 1st Jan 2014, midnight.
	DateTime date_end   = new DateTime(2017, 1, 1, 0, 0, 0);    // 1st Jan 2017, midnight.

	MarketSeries = ...    // Set date range, somehow.

	// Loop through all 'bars' in MarketSeries.

	bar_count = MarketSeries.Close.Count;

	for ( int index = 0; index < bar_count ; index++ )
	{
		double open  = MarketSeries.Open  [ index ]
		double high  = MarketSeries.High  [ index ]
		double low   = MarketSeries.Low   [ index ]
		double close = MarketSeries.Close [ index ]

		// Do stuff with OHLC price data here.
	}
}

 


@rohingosling
Replies

rohingosling
08 Aug 2018, 15:45

Additional question.

How is the range of MerketSeries set in the first place? 

Without specifying a date range, MerketSeries always seems to have a small default range of historical data available.

1. Aside from a way to specify a custom date range, what is the default amount of historical data available in MerketSeries?

2. But most importantly, referring to the question in my original post. How can one specify a custom range for MerketSeries, for instance, all minutes from 1st Jan 2014 to 1st Jan 2017?


@rohingosling