Getting current tick DateTime for 5 minute charts  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
User avatar
jwebster503
Posts: 24
Joined: 13 Mar 2014
Has thanked: 9 times
Been thanked: 14 times

Getting current tick DateTime for 5 minute charts

Postby jwebster503 » 15 Oct 2014

When a chart is set to a resolution of 1 tick, I can access the tick timestamp with Bars.Time[0] (and probably Bars.TimeValue). However, when the resolution is not a tick, the current bar time is always the start of the bar. Said differently, if 10 ticks come in every 6 seconds during the 8:31am 1 minute bar, each access to Bars.Time[0] will show 8:31. How can I access the timestamp for the tick itself, where each of the 10 ticks will have an increasing timestamp?

Thanks!

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Getting current tick DateTime for 5 minute charts

Postby JoshM » 16 Oct 2014

I thought that

Code: Select all

Bars.StatusLine.Time
..returned the time of the last trade as displayed in the Status Line.

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

Re: Getting current tick DateTime for 5 minute charts  [SOLVED]

Postby Henry MultiСharts » 16 Oct 2014

Hello jwebster503,

There is no dedicated reserved word for getting the realtime tick’s time inside a bar.
An alternative to using Bars.StatusLine.Time suggested by JoshM is adding 1 tick data series to your chart and accessing it's values from the code.

User avatar
jwebster503
Posts: 24
Joined: 13 Mar 2014
Has thanked: 9 times
Been thanked: 14 times

Re: Getting current tick DateTime for 5 minute charts

Postby jwebster503 » 17 Oct 2014

Hello jwebster503,

There is no dedicated reserved word for getting the realtime tick’s time inside a bar.
An alternative to using Bars.StatusLine.Time suggested by JoshM is adding 1 tick data series to your chart and accessing it's values from the code (viewtopic.php?f=19&t=45848#p100792).
Thanks to JoshM for his suggestion, even though it wasn't quite what I was looking for -- good to keep this option in the back of my mind for another problem. :) In my case, whether data was historical or real-time, I needed to see the very precise time each tick happened, which is a problem when the chart shows bars instead of tick line. This is where the DataLoader came in. Based on Henry's suggestion, for posterity, here is the rough draft code which gave me what I needed:

Code: Select all

namespace PowerLanguage.Indicator
{
public class TestTick : IndicatorObject
{
private IDataLoaderResult _result;


public TestTick( object ctx ) : base( ctx ) {}


protected override void Create() {}


protected override void StartCalc()
{
_result = null;
Output.Clear();
}


protected override void CalcBar()
{
// fire on first bar only
if ( Bars.CurrentBar == 1 )
{
// we'll take current chart data request and force resolution to be 1 tick and
// to subscribe to RT data
var request = Bars.Request;
request.Resolution = new Resolution {Size = 1, Type = EResolution.Tick};
request.Subscribe2RT = true;
_result = DataLoader.BeginLoadData( request, ResultCallback, null );
Output.WriteLine( "Subscribed!" );
}
}


private void ResultCallback( IDataLoaderResult result )
{
// show historical data
if ( result.Event == DataLoadedEvent.History )
{
Output.WriteLine(
"Received {0} historical bars... processing now...", result.Data.Length );
foreach ( var bar in result.Data )
Output.WriteLine(
"Bar: c={0}, t={1}", bar.Close, bar.Time.ToString( "HH:mm:ss.fffffff" ) );
}

// show real-time data
if ( result.Event == DataLoadedEvent.RTNewBar && result.RTData != null )
{
var rt = result.RTData.Value;
Output.WriteLine(
"RT Bar: c={0}, t={1}", rt.Close, rt.Time.ToString( "HH:mm:ss.fffffff" ) );
}
}


protected override void StopCalc()
{
// shut down data listener if it's turned on
if ( _result != null )
{
Output.WriteLine( "Unsubscribe" );
DataLoader.EndLoadData( _result );
}
base.StopCalc();
}
}
}


Return to “MultiCharts .NET”