Your interactive trading laboratory!
 • 
21 users online

Quantacula Help

How-To
C# API Reference
Extensions
Development Blog
API-Extensions
Indicator Spotlights

QCommunity Extensions
The open-source GitHub repository of source code for the QCommunity Extensions library. Contains indicators and other extensions submitted by the Quantacula Community. Look for QCommunity indicators when you create a Building Block model, mark the "QCommunity" library check box to expose them.

TASC-Extensions
The open-source GitHub repository of source code for the TASCExtensions Quantacula extension. Contains indicators and other extensions adapted from the Traders' Tips articles in Technical Analysis of Stocks & Commodities magazine.
BarHistoryCompressor
Namespace: Quantacula.Core
Parent: none (static)

BarHistoryCompressor is a static utility class containing methods that let you compress a BarHistory instance from one scale down to a more compressed scale. For example, you can call BarHistoryCompressor.ToWeekly to compress a daily BarHistory into a weekly one.

If you want to be able to plot a compressed BarHistory onto the chart, you would need to first expand it back to the original scale. You can use the BarHistorySynchronizer utility class to accomplish this.

Static Methods

ToDaily
public static BarHistory ToDaily(BarHistory source)

Compresses the source BarHistory to a daily scale, returning a new BarHistory instance.


ToHour
public static BarHistory ToHour(BarHistory source, int interval)

Compresses the source BarHistory to an interval-hour hourly scale, returning a new BarHistory instance.


ToMinute
public static BarHistory ToMinute(BarHistory source, int interval)

Compresses the source BarHistory to an interval-minute scale, returning a new BarHistory instance.


ToMonthly
public static BarHistory ToMonthly(BarHistory source)

Compresses the source BarHistory to a monthly scale, returning a new BarHistory instance.


ToQuarterly
public static BarHistory ToQuarterly(BarHistory source)

Compresses the source BarHistory to a quarterly scale, returning a new BarHistory instance.


ToScale
public static BarHistory ToScale(BarHistory source, HistoryScales scale)

Compresses the source BarHistory to the specified scale, returning a new BarHistory instance.


ToWeekly
public static BarHistory ToWeekly(BarHistory source)

Compresses the source BarHistory to a weekly scale, returning a new BarHistory instance.

Example Code
using Quantacula.Backtest;
using Quantacula.Core;
using Quantacula.Indicators;
using System.Drawing;

namespace Quantacula
{
	public class MyModel1 : UserModelBase
	{
		//create indicators and other objects here, this is executed prior to the main trading loop
		public override void Initialize(BarHistory bars)
		{
			//get weekly data
			BarHistory weekly = BarHistoryCompressor.ToWeekly(bars);

			//get 4 week RSI
			RSI rsiWeekly = new RSI(weekly.Close, 4);

			//synchronize it back to the original (daily) scale
			TimeSeries rsiWeeklySynched = TimeSeriesSynhronizer.Synchronize(rsiWeekly, bars);

			//Plot the weekly RSI on the daily chart
			PlotTimeSeries(rsiWeeklySynched, "RSI(Weekly4)", "RSI", Color.Blue);
		}

		//execute the strategy rules here, this is executed once for each bar in the backtest history
		public override void Execute(BarHistory bars, int idx)
		{
		}

		//declare private variables below

	}
}

ToYearly
public static BarHistory ToYearly(BarHistory source)

Compresses the source BarHistory to a yearly scale, returning a new BarHistory instance.