Looping OHLC sample

The source for Looping OHLC

Looping OHLC

In this example we show how to build lists that can be used to construct values for backtesting.

In backtesting we want to loop through several parameter combinations so using fixed values is not feasible. We use standard list type and fill it with values of interest.

For daily values we use last three.


List _ohlcDailyValues = new List {};
for(int i=0; i<3; i++)
{
	_ohlcValues.Add(_dailyFreq.Open.LookBack(i));
	_ohlcValues.Add(_dailyFreq.High.LookBack(i));
	_ohlcValues.Add(_dailyFreq.Low.LookBack(i));
	_ohlcValues.Add(_dailyFreq.Close.LookBack(i));
}
double _ohlcDailyAverage = _ohlcDailyValues.Average();

For hourly values we use last six.


List _ohlcHourlyValues = new List {};
for(int i=0; i<6; i++)
{
	_ohlcValues.Add(_hourlyFreq.Open.LookBack(i));
	_ohlcValues.Add(_hourlyFreq.High.LookBack(i));
	_ohlcValues.Add(_hourlyFreq.Low.LookBack(i));
	_ohlcValues.Add(_hourlyFreq.Close.LookBack(i));
}
double _ohlcHourlyAverage = _ohlcHourlyValues.Average();

For fifteen minute values we use last four.


List _ohlcFifteenMinuteValues = new List {};
for(int i=0; i<4; i++)
{
	_ohlcValues.Add(_fifteenMinuteFreq.Open.LookBack(i));
	_ohlcValues.Add(_fifteenMinuteFreq.High.LookBack(i));
	_ohlcValues.Add(_fifteenMinuteFreq.Low.LookBack(i));
	_ohlcValues.Add(_fifteenMinuteFreq.Close.LookBack(i));
}
double _ohlcFifteenMinuteAverage = _ohlcFifteenMinuteValues.Average();

Now values are available for standard list operations as seen in average operation example.