As we know, chart aggregation is a type of displaying aggregated values. These values are price, volume and time. The main idea of each aggregation is to help traders analyze the state of the market in history and in real time.
At this moment, Quantower API supports 9aggregation types. All of them you can use in your scripts easily. But before we continue, please read the article by using Quantower API.
To download aggregated history we need use method which takes instanse of class as input parameter. This class contains the necessary properties such as FromTime, ToTime, HistoryType, etc. with which we can flexibly customize our request. But today we are interested in the property. This property contains instance of class which is base class for all available aggregation types. All we need to get the aggregated history is to set to this property instance of required aggregation type.
Listed below are all available aggregation classes with examples of history requests.
Available aggregation classes
Tick aggregation
The class is used to buid simple Tick chart.
new HistoryAggregationTick(int ticksCount);
ticksCount - the number of ticks for aggregation.
var tickhistoricalData = this.Symbol.GetHistory(new HistoryRequestParameters(){ Symbol = this.Symbol, FromTime = DateTime.Now.AddHours(-3), ToTime = DateTime.Now, HistoryType = this.Symbol.VolumeType == SymbolVolumeType.Volume ? HistoryType.Last : HistoryType.BidAsk, Period = Period.TICK1, Aggregation = new HistoryAggregationTick(1),});
Time aggregation
The class is used to build the chart.
new HistoryAggregationTime(Period period);
var timeBarHistoricalData = this.Symbol.GetHistory(new HistoryRequestParameters(){ Symbol = this.Symbol, FromTime = DateTime.Now.AddDays(-3), ToTime = DateTime.Now, HistoryType = this.Symbol.HistoryType, Period = Period.MIN15, Aggregation = new HistoryAggregationTime(Period.MIN15),});
Heiken-Ashi aggregation
new HistoryAggregationHeikenAshi(HeikenAshiSource source, int value);
source - enum, base period of time (Tick, Seconds. Minutes etc).
value - the amount of 'source' time.
var heikenAshiHistoricalData = this.Symbol.GetHistory(new HistoryRequestParameters(){ Symbol = this.Symbol, FromTime = DateTime.Now.AddDays(-3), ToTime = DateTime.Now, HistoryType = this.Symbol.HistoryType, Aggregation = new HistoryAggregationHeikenAshi(HeikenAshiSource.Minute, 1),});
Range Bars aggregation
new HistoryAggregationRangeBars(int rangeBars);
rangeBars - the height (in ticks) of each bar.
var rangeBarHistoricalData = this.Symbol.GetHistory(new HistoryRequestParameters(){ Symbol = this.Symbol, FromTime = DateTime.Now.AddHours(-3), ToTime = DateTime.Now, HistoryType = this.Symbol.HistoryType, Aggregation = new HistoryAggregationRangeBars(10),});
Renko aggregation
new HistoryAggregationRenko(Period period, int brickSize, RenkoStyle renkoStyle, int extension = 100, int inversion = 100, bool showWicks = false, bool buildCurrentBar = true)
var pointFiguresHistoricalData = this.Symbol.GetHistory(new HistoryRequestParameters(){ Symbol = this.Symbol, FromTime = DateTime.Now.AddDays(-1), ToTime = DateTime.Now, HistoryType = this.Symbol.HistoryType, Aggregation = new HistoryAggregationPointsAndFigures(Period.TICK1, 100, 50, PointsAndFiguresStyle.HighLow),});
Volume Bars aggregation
new HistoryAggregationVolume(int volumeValue);
volumeValue - base volume value of bar
var volumeBarsHistoricalData = this.Symbol.GetHistory(new HistoryRequestParameters(){ Symbol = this.Symbol, FromTime = DateTime.Now.AddHours(-4), ToTime = DateTime.Now, Period = Period.TICK1, HistoryType = this.Symbol.HistoryType, Aggregation = new HistoryAggregationVolume(1000),});
Practice
In this part of the article, we will create a simple strategy script in which we will try to apply the knowledge. Let's describe our actions step by step:
Create HistoricalData instance by loading 6 hours of Renko history.
Create Fast SMA and Slow SMA indicators and then attach them to our HistoricalData.
Display metrics:
Fast SMA value
Slow SMA value
Current brick high price
Current brick low price
Log high and low prices of each new brick.
Input parameters
First, let’s define input parameters. In this section, we want to be able to change the aggregation parameters and indicator base settings.
[InputParameter("Symbol", 10)]public Symbol Symbol;[InputParameter("Renko period", 20)]public Period RenkoPeriod = Period.MIN1;[InputParameter("Brick size", 30)]public int BrickSize = 10;[InputParameter("Renko style", 40, variants: new object[]{ "Classic", RenkoStyle.Classic, "High/Low", RenkoStyle.HighLow, "Adv. Classic", RenkoStyle.AdvancedClassic, "Adv. High/Low", RenkoStyle.AdvancedHighLow,})]public RenkoStyle RenkoStyle = RenkoStyle.Classic;[InputParameter("Fast SMA period", 50, 1, 9999, 1, 0)]public int FastSmaPeriod = 10;[InputParameter("Slow SMA period", 50, 1, 9999, 1, 0)]public int SlowSmaPeriod = 30;private HistoricalData renkoHistoricalData;private Indicator fastSmaIndicator;private Indicator slowSmaIndicator;
OnRun method
In this section, we will carry out the first, second and fourth points.
Pay attention to line 30. Here we subscribe 'NewHistoryItem' event. In other words, our 'RenkoHistoricalData_NewHistoryItem' handler will trigger on each new brick item.