What is the best way to access OHLC data for a compressed bar history?
Example:
The base interval is 5 minutes. I have a compressed daily bar history. What is the most efficient way to index the daily bar history to get the high from 5 days ago?
Example:
The base interval is 5 minutes. I have a compressed daily bar history. What is the most efficient way to index the daily bar history to get the high from 5 days ago?
Rename
The 5-day (Highest) High?
Or really the High from 5 days ago?
Or really the High from 5 days ago?
The daily high from 5 days ago assuming that the strategy is running on 5 minute data with a variable:
CODE:
BarHistory daily = BarHistoryCompressor.ToDaily(bars);
This should work -
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript3 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { BarHistory daily = BarHistoryCompressor.ToDaily(bars); // synchronize it with the [intraday] bars daily = BarHistorySynchronizer.Synchronize(daily, bars); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { // access the high 5 days ago double value = DaysAgo(idx, bars, daily.High, 5); } double DaysAgo(int bar, BarHistory bh, TimeSeries ts, int daysAgo) { double result = Double.NaN; int count = 1; while (count <= daysAgo && bar > 0) { bar -= bh.IntradayBarNumber(bar); bar -= 1; count++; } if (bar < 0) return ts[0]; return ts[bar]; } //declare private variables below BarHistory daily; } }
Thanks Cone.
I wasn't sure if I should synchronize the compressed history or access the compressed history using some index method.
Thanks again.
I wasn't sure if I should synchronize the compressed history or access the compressed history using some index method.
Thanks again.
There's a way to do that, but this is more straightforward, imho.
The same question but a bit different. Is there a built-in method to get the daily bar index that corresponds to intraday one?
BarHistorySynchronizer.Synchronize make things complicated is some cases, for example when I need to iterate over last 3 bars of daily data
Update: I was able to solve with a loop comparing by the .Date attribute. It works with stocks but i guess it won't work with futures
BarHistorySynchronizer.Synchronize make things complicated is some cases, for example when I need to iterate over last 3 bars of daily data
Update: I was able to solve with a loop comparing by the .Date attribute. It works with stocks but i guess it won't work with futures
Your Response
Post
Edit Post
Login is required