Access to advanced aggregations

Using the available aggregation types in your code

Theory

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 9 aggregation types. All of them you can use in your scripts easily. But before we continue, please read the article how to download historyarrow-up-right by using Quantower API.

To download aggregated history we need use GetHistory arrow-up-rightmethod which takes instanse of HistoryRequestParameters arrow-up-rightclass 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 Aggregation arrow-up-rightproperty. This property contains instance of HistoryAggregation arrow-up-rightclass 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 HistoryAggregationTick arrow-up-rightclass 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 HistoryAggregationTime arrow-up-rightclass is used to build the Time arrow-up-rightchart.

Heiken-Ashi aggregation

The HistoryAggregationHeikenAshi arrow-up-rightclass is used to build the Heiken-Ashiarrow-up-right chart.

  • source - enum, base period of time (Tick, Seconds. Minutes etc).

  • value - the amount of 'source' time.

Range Bars aggregation

The HistoryAggregationRangeBars arrow-up-rightclass is used to build the Range Barsarrow-up-right chart.

  • rangeBars - the height (in ticks) of each bar.

Renko aggregation

The HistoryAggregationRenko arrow-up-rightclass is used to build the Renko arrow-up-rightchart.

  • period - base period of time. Instance of Period arrow-up-rightstructure.

  • brickSize - required size of renko brick

  • renkoStyle - enum, calculation methods (Classic, HighLow, AdvancedClassic, AdvancedHighLow)

Line break aggregation

The HistoryAggregationLineBreakarrow-up-right class is used to build the Line breakarrow-up-right chart.

Kagi aggregation

The HistoryAggregationKagi arrow-up-rightclass is used to build the Kagiarrow-up-right chart.

  • period - base period of time. Instance of Period arrow-up-rightstructure.

  • reversal - the amount of price movement that required for the Kagi line to reverse direction.

Points & Figures aggregation

The HistoryAggregationPointsAndFiguresarrow-up-right class is used to build the Points & Figuresarrow-up-right chart.

  • period - base period of time. Instance of Period arrow-up-rightstructure.

  • boxSize - price range (the number of ticks) for X-Columns or O-Columns

  • reversal - a parameter that indicates the number of Box Sizes that the price should go in the opposite direction to begin a new column.

  • style - enum, calculation methods (Classic, HighLow)

Volume Bars aggregation

The HistoryAggregationVolume class is used to build the Volume bars arrow-up-rightchart.

  • volumeValue - base volume value of bar

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:

  1. Create HistoricalData instance by loading 6 hours of Renko history.

  2. Create Fast SMA and Slow SMA indicators and then attach them to our HistoricalData.

  3. Display metrics:

    1. Fast SMA value

    2. Slow SMA value

    3. Current brick high price

    4. Current brick low price

  4. 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 settigns.

OnRun method

In this section, we will carry out the first, second and fourth points.

circle-info

Pay attention to line 24. Here we create instance of HistoryAggregationRenkoarrow-up-right class and pass required parameters.

Pay attention to line 30. Here we subscribe 'NewHistoryItem' event. Another words, our 'RenkoHistoricalData_NewHistoryItem' handler will trigger on each new brick item.

OnGetMetrics method

Here we create required metrics.

circle-info

Pay attention to line 10. Here we use 'FormatPrice' method to format indicator value to symbol tick size.

OnStop method

Never forget to remove unused objects and unsubscribe form unused events.

Last updated