NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 06-25-2012, 08:28 AM   #1
jbesada
Member
 
Join Date: May 2012
Posts: 73
Thanks: 3
Thanked 0 times in 0 posts
Default Time on MarketDataEventArgs

Hello,

What is the value of Time property on MarketDataEventArgs?
In a first glance it should be the DateTime of every change, (Bid, Ask or prices) but it seems to be the DateTime of last trade. Is that right?
Maybe there is not much difference in liquidity instruments but definitively there are a lot of differences in non-liquidity instruments.

Regards
jbesada is offline  
Reply With Quote
Old 06-25-2012, 09:01 AM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

jbesada,

It should be the time of that particular OnMarketData call. Are you noticing something different?
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-25-2012, 09:13 AM   #3
jbesada
Member
 
Join Date: May 2012
Posts: 73
Thanks: 3
Thanked 0 times in 0 posts
Default

Unfortunately yes, I have noticed that always change whit MarketDataType=Last, but not with Bid and Ask (it keeps previous value).
So, at the end, when you analyze a file data you can see always a change on Time if a Trade occurs:
1303 0 1303 1303.75 22 69 49345
1303 0 1303 1303.75 22 47 49345
1303 0 1303.25 1303.75 22 47 49345
1303 0 1303.25 1303.75 22 45 49345
1303 0 1303.25 1304 22 69 49345
1303 0 1303 1304 24 69 49345
1303 0 1303.25 1304 22 69 49345
1304 2 1303.25 1304 22 69 49760
As you can see, there is a big jump on last column (seconds from midnight). My guest, e.Time is not updated with ‘Bid’ and ‘Ask’ events, just with ‘Last’ event. Can you confirm it?
I have reviewed my code deeply and I cannot find another explanation…


Regards
jbesada is offline  
Reply With Quote
Old 06-25-2012, 09:24 AM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

jbesada,

There would only be second resolution here, so no milliseconds. Could you show me your code?
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-25-2012, 09:29 AM   #5
jbesada
Member
 
Join Date: May 2012
Posts: 73
Thanks: 3
Thanked 0 times in 0 posts
Default

Here is my code. As you can see, every change is recorded creating a new line but Time changes with 'Last' type only:

protected override void OnMarketData(MarketDataEventArgs e)
{
string strMD="", strML="";
string strDate ="";
long lLastVolume=0;
bool bUpdate=false;
try
{
lock(oLock)
{
switch(e.MarketDataType)
{
case MarketDataType.Bid:
dBid=e.Price;
lBidSize=e.Volume;
bUpdate=true;
break;
case MarketDataType.Ask:
dAsk=e.Price;
lAskSize=e.Volume;
bUpdate=true;
break;
case MarketDataType.Last:
dLast=e.Price;
lLastVolume=e.Volume;
bUpdate=true;
break;
}
if (bUpdate && dLast>0 && dBid>0 && dAsk>0)
{
TimeSpan ts = e.Time.ToUniversalTime() - DateTime.Now.Date;
strDate= ts.TotalSeconds.ToString();
strMD = dLast.ToString().Replace(',', '.') +"\t" + lLastVolume + "\t" + dBid.ToString().Replace(',', '.') + "\t" + dAsk.ToString().Replace(',', '.') + "\t" + lBidSize + "\t" + lAskSize + "\t" + strDate;
twMD.WriteLine(strMD);
}
}
}catch(System.Exception ex)
{
Print("Something was wrong on OnMarketData! : " + ex.Message);
}
}
jbesada is offline  
Reply With Quote
Old 06-25-2012, 09:58 AM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

jbesada,

Here is example output for me :

Code:
ASK : 6/25/2012 9:53:13 AM
ASK : 6/25/2012 9:53:13 AM
ASK : 6/25/2012 9:53:13 AM
BID : 6/25/2012 9:53:13 AM
ASK : 6/25/2012 9:53:13 AM
ASK : 6/25/2012 9:53:13 AM
ASK : 6/25/2012 9:53:13 AM
LAST : 6/25/2012 9:53:14 AM
BID : 6/25/2012 9:53:14 AM
LAST : 6/25/2012 9:53:14 AM
BID : 6/25/2012 9:53:14 AM
BID : 6/25/2012 9:53:14 AM
ASK : 6/25/2012 9:53:14 AM
ASK : 6/25/2012 9:53:14 AM
This is expected output, because we are not seeing the times at millisecond resolution. Time stamps do not have these milliseconds displayed. I am noticing that last occurs before subsequent bid/asks, but these subsequent bid/asks are happening after the last quote, you just aren't able to get their time stamps at millisecond resolution. If you could you would see they are happening at different times.

Here is an example of my code :

Code:
                protected override void OnMarketData(MarketDataEventArgs e)
		{
			if ( e.MarketDataType == MarketDataType.Ask)
			{
				Print("ASK : "+e.Time.ToString());
			}
			else if ( e.MarketDataType == MarketDataType.Bid)
			{
				Print("BID : "+e.Time.ToString());
			}
			else if ( e.MarketDataType == MarketDataType.Last)
			{
				Print("LAST : "+e.Time.ToString());
			}
		}
You could try keeping track of your own time stamps for these that include millisecond resolution, but it wouldn't work on historical data.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-25-2012, 10:11 AM   #7
jbesada
Member
 
Join Date: May 2012
Posts: 73
Thanks: 3
Thanked 0 times in 0 posts
Default

Hi Adam,


I know time have only resolution of seconds. I think I haven’t asked about milliseconds. My question is not related with it.
My question is why always time changes (resolution of seconds) always with Last quote and NEVER with Bid/Ask quotes.

Regards
jbesada is offline  
Reply With Quote
Old 06-27-2012, 07:13 AM   #8
jbesada
Member
 
Join Date: May 2012
Posts: 73
Thanks: 3
Thanked 0 times in 0 posts
Default

Hi Adam,

Any update of this issue?

Regards

Hi Adam,
--------

I know time have only resolution of seconds. I think I haven’t asked about milliseconds. My question is not related with it.
My question is why always time changes (resolution of seconds) always with Last quote and NEVER with Bid/Ask quotes.

Regards
jbesada is offline  
Reply With Quote
Old 06-27-2012, 08:01 AM   #9
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Bid ask data may not be natively time stamped from the provider. Something the provider will need to follow up on. If its time stamped from the exchange then NT will order it in the format received. Last data is most likely time stamped from the server however bid and ask data is not guaranteed to be time stamped and I know with a lot of providers it is not.

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use weekly, monthly, yearly time frames in real time charting using 6.5 versi qwert12 Charting 2 10-05-2010 04:35 PM
MarketDataEventArgs pdwebb General Programming 1 10-21-2009 01:52 PM
Question regarding MarketDataEventArgs davewolfs General Programming 1 08-26-2009 08:45 AM
MarketDataEventArgs - TimeStamp davewolfs General Programming 3 08-25-2009 07:07 AM
Multi-time frame strategy - Longer-term real-time calculations Shansen Strategy Development 1 04-19-2009 06:36 AM


All times are GMT -6. The time now is 01:08 AM.