Dataloader ticks do not align with bars  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Dataloader ticks do not align with bars

Postby davewolfs » 15 Mar 2013

Very simple example for testing purposes.

I am using the dataloader to load all ticks for the bar that I am currently evaluating. Additionally, I am converting this to a lambda series so that it can be referenced through indicators who take iseries. Nice undocumented feature of the API.

There is a problem here. If you load the volume indicator which operates off of the bars stored volume and compute against the tick volume they do not match. The reason for this is that the bars in this case (range bars) could overlap in ticks. i.e. The end time of the previous bar and start time of the current bar could share ticks that happen in the same second.

Internally MC makes use of TickID to distinguish ticks that happen on the same second. This should somehow be used here. Perhaps a property of Bars.TickIdStart[barsAgo] and Bars.TickIdEnd[barsAgo] needs to be added? Otherwise it appears to be impossible to get your tick data to match your bar data. This is a big issue for tick precise indicators.

Code: Select all

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator{
public class _Test : IndicatorObject {
public _Test(object _ctx):base(_ctx){}
private IPlotObject plot1;
private ISeries<float> barVolume;
private ManualResetEventSlim _waitHandler = new ManualResetEventSlim(false);
private List<Bar[]> tickBuckets = new List<Bar[]>();

protected override void Create() {
// create variable objects, function objects, plot objects etc.
plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red));
}

protected override void StartCalc() {
barVolume = new Lambda<float>(barsBack =>
{
int index = tickBuckets.Count - 1 - barsBack;
return index < 0 ? 0 : tickBuckets[index].Sum(tick => tick.TotalVolume);
});
}
protected override void CalcBar() {
Bar[] bars = null;

if (Bars.CurrentBar > 1)
{
InstrumentDataRequest req = Bars.Request;
req.Resolution.Size = 1;
req.Resolution.Type = EResolution.Tick;
req.From = Bars.Time[1];
req.To = Bars.TimeValue;
_waitHandler.Reset();
IDataLoaderResult result = DataLoader.BeginLoadData(req, r => { if (r.IsCompleted) _waitHandler.Set(); }, null);
_waitHandler.Wait();
tickBuckets.Add(result.Data);
DataLoader.EndLoadData(result);
}
plot1.Set(barVolume.Value);
}
}
}

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars

Postby Henry MultiСharts » 18 Mar 2013

Hello davewolfs,

Which data provider do you use?

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Dataloader ticks do not align with bars

Postby davewolfs » 18 Mar 2013

Hello davewolfs,

Which data provider do you use?
IQFeed. If it means anything too, performance with multiple calls to the dataloader seems horrible. As though it is meant to only be called once and used. Please confirm.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars

Postby Henry MultiСharts » 19 Mar 2013

DataLoader returns ticks that fall into [ Time Start, Time End ] interval, but the bars are built on [Time Start, Time End) interval.
For example:
If you request data for a minute bar closing at 02:00:00 i.e. (Time Start = 01:59:00, Time End = 02:00:00) - DataLoader will return all data for this period, but minute bar will not include ticks with time > 1:59:59. These odd ticks returned by DataLoader give the difference.
That means you need to filter the ticks during summation into a bar according to the resolution you are using.

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Dataloader ticks do not align with bars

Postby davewolfs » 19 Mar 2013

DataLoader returns ticks that fall into [ Time Start, Time End ] interval, but the bars are built on [Time Start, Time End) interval.
For example:
If you request data for a minute bar closing at 02:00:00 i.e. (Time Start = 01:59:00, Time End = 02:00:00) - DataLoader will return all data for this period, but minute bar will not include ticks with time > 1:59:59. These odd ticks returned by DataLoader give the difference.
That means you need to filter the ticks during summation into a bar according to the resolution you are using.
Yes and that is not possible. For example. Please attempt doing this on a tick chart. You will not be able to.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars

Postby Henry MultiСharts » 20 Mar 2013

You need to get the data provided by DataLoader and sum up in a cycle only the ticks(bars) that lay in the specified (by time) interval.

If you are still unable to achieve your goal please provide a sample code you are using and exact description of what you are trying to achieve and what does not work exactly.

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Dataloader ticks do not align with bars

Postby davewolfs » 20 Mar 2013

Ok, so basically one has to do some processing in order to get ticks to align.

If the precision on the bars time was increased than this wouldn't be an issue. I do believe that the data loader should be able to give a user the ticks that correspond to the bar they are looking at.

Should the bars back function work in this case? I realize that it is broken in the current release but probably something to look out for on the next.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars

Postby Henry MultiСharts » 20 Mar 2013

I don't see how the bars back function can be helpful in this case. Just specify the Time End -1 sec for data loader, you will have the appropriate result, instead of 02:00:00 you will have 01:59:00 right away.

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Dataloader ticks do not align with bars

Postby davewolfs » 20 Mar 2013

That approach will work on time based bars. It will not work on tick based or volume bars.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars

Postby Henry MultiСharts » 21 Mar 2013

That is correct, it will not work on tick or volume based bars. They are built on bar amount/volume, not time range.

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Dataloader ticks do not align with bars

Postby davewolfs » 22 Mar 2013

That is correct, it will not work on tick or volume based bars. They are built on bar amount/volume, not time range.
Right so, wouldn't it make sense for the dataloader to be capable of produce a range out of the box that aligns with the bars on the chart?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars

Postby Henry MultiСharts » 25 Mar 2013

Right so, wouldn't it make sense for the dataloader to be capable of produce a range out of the box that aligns with the bars on the chart?
IDataLoader result should be controlled by the user as you can have different data series with different data range.

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Dataloader ticks do not align with bars

Postby davewolfs » 25 Mar 2013

Right so, wouldn't it make sense for the dataloader to be capable of produce a range out of the box that aligns with the bars on the chart?
IDataLoader result should be controlled by the user as you can have different data series with different data range.
I don't see how that applies. Please try to load a volume or tick chart on multiple instruments and let me know if you can align your charts properly. That is not a user issue.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars

Postby Henry MultiСharts » 26 Mar 2013

if you can align your charts properly.
What do you mean exactly? It does not look like the initial topic question.
Please provide a screenshot of the behavior you are referring to.

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Dataloader ticks do not align with bars

Postby davewolfs » 26 Mar 2013

if you can align your charts properly.
What do you mean exactly? It does not look like the initial topic question.
Please provide a screenshot of the behavior you are referring to.
What I mean is that if you were to plot the volume that you loaded via data loader based on ticks.

Where your primary bar type was tick or volume based. And you were using the dataloader you would not be able to contruct tick/volume based bars that corresponded correctly to the bars on your chart. No different than my first post.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars

Postby Henry MultiСharts » 27 Mar 2013

All chart resolutions are built from the beginning of the session.
Each resolution is based on its own rules. If you want to manually build a resolution you need to load all ticks for the session, then based on the applied rules build the resolution you need.

For example the resolution you need is 500 volume bars (contracts).
Load all ticks for the current session.
Start building bars by summing up the tick volume until the result=500.
Do it multiple times until the loaded data ends.

You can also specify the resolution for the data loader request:

Code: Select all

req.Resolution.Type = EResolution.Volume;
Please refer to EResolution Enumeration in the help file for complete list of resolutions.

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Dataloader ticks do not align with bars

Postby davewolfs » 27 Mar 2013

All chart resolutions are built from the beginning of the session.
Each resolution is based on its own rules. If you want to manually build a resolution you need to load all ticks for the session, then based on the applied rules build the resolution you need.

For example the resolution you need is 500 volume bars (contracts).
Load all ticks for the current session.
Start building bars by summing up the tick volume until the result=500.
Do it multiple times until the loaded data ends.

You can also specify the resolution for the data loader request:

Code: Select all

req.Resolution.Type = EResolution.Volume;
Please refer to EResolution Enumeration in the help file for complete list of resolutions.
API should handle this for you.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars

Postby Henry MultiСharts » 27 Mar 2013

API should handle this for you.
It already does that for you.
You can also specify the resolution for the data loader request:

Code: Select all

req.Resolution.Type = EResolution.Volume;
Please refer to EResolution Enumeration in the help file for complete list of resolutions.

davewolfs
Posts: 89
Joined: 06 Feb 2013
Has thanked: 2 times
Been thanked: 11 times

Re: Dataloader ticks do not align with bars

Postby davewolfs » 27 Mar 2013

Yes, but that is not at the tick level. So if one needs to do tick by tick calculation. They cannot obtain them.

Anyhow. I don't have time or patience to go back and forth on this forum.

But the bottom line is, there is not an intuitive way to take a tick sequence and align it with all higher level bars on the session if those higher level bars are not time based because the higher level bars have second precision.

I higher precision of time, or something associated with tick id would resolve this. Otherwise the user has no choice but to build the bars from ticks at the beginning of the session and process the bars themselves.

Thanks!

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dataloader ticks do not align with bars  [SOLVED]

Postby Henry MultiСharts » 07 Aug 2014

MULTICHARTS .NET 9.0 BETA 1 – WHAT’S NEW:
New class added: CustomInstrument. It allows accessing the data series loaded by the DataLoader with the help of IInstrument interface. The bars of such data series are tied to the bars of the main data series based on time.


Return to “MultiCharts .NET”