NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 01-14-2009, 05:35 PM   #1
rt-trader
Senior Member
 
Join Date: Jan 2007
Location: , ,
Posts: 250
Thanks: 1
Thanked 2 times in 1 post
Default OnMarketData vs OnBarUpdate

Hi,

I have noticed during some testing that OMD last price when used within OnBarUpdate lags Close[0] by 1 tick. I would have expected them to be identical at all times.

The code I used to identify the situation is below - stripped down posting purposes (after testing it of course). In theory there should be no printing to the Output window, however, at every price change the print test is true.

When compared against the Time & Sales window Close[0] is always correct.

Any suggestions or comments?

Hopefully I am wrong somewhere in my understanding or implementation - otherwise.....

Thanks

#region Variables

private double lastprice = 0;
private string ttime;

#endregion

protected override void Initialize() {
CalculateOnBarClose = false;
Overlay = true;
PriceTypeSupported = false;
}


protected override void OnMarketData(MarketDataEventArgs e) {

if (e.MarketDataType == MarketDataType.Last) {
lastprice = e.Price;
ttime = e.Time.ToLongTimeString();
}
}

protected override void OnBarUpdate() {

if(!Historical) {
if(Close[0] != lastprice) Print(Close[0] + " " + lastprice + " " + ttime); }
}
rt-trader is offline  
Reply With Quote
Old 01-15-2009, 07:09 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

There is no guarantee OnMarketData will trigger before OnBarUpdate. You can't compare it like that.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-18-2009, 03:07 PM   #3
rt-trader
Senior Member
 
Join Date: Jan 2007
Location: , ,
Posts: 250
Thanks: 1
Thanked 2 times in 1 post
Default

A belated reply Josh - I will do some more testing around this...

Thanks...
rt-trader 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
OnMarketData and OnBarUpdate svrz Indicator Development 6 12-23-2008 09:17 AM
OnBarUpdate() / OnMarketData() Priority mrlogik General Programming 11 09-28-2008 05:00 PM
OnMarketData() vs. OnBarUpdate() Tight Face General Programming 6 09-10-2008 02:20 PM
OnMarketData SystemTrading General Programming 2 09-09-2008 04:51 PM
OnBarUpdate and OnMarketData used in one indicator? RedDuke General Programming 9 12-14-2007 06:54 PM


All times are GMT -6. The time now is 09:30 AM.