mjj38
- ago
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?
0
444
Solved
6 Replies

Reply

Bookmark

Sort
Cone8
 ( 3.17% )
- ago
#1
The 5-day (Highest) High?
Or really the High from 5 days ago?
0
mjj38
- ago
#2
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);
0
Cone8
 ( 3.17% )
- ago
#3
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;    } }
1
Best Answer
mjj38
- ago
#4
Thanks Cone.

I wasn't sure if I should synchronize the compressed history or access the compressed history using some index method.

Thanks again.
0
Cone8
 ( 3.17% )
- ago
#5
There's a way to do that, but this is more straightforward, imho.
1
ww58
- ago
#6
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
0

Reply

Bookmark

Sort