PDA

View Full Version : OnBarUpdate() / OnMarketData() Priority


mrlogik
09-15-2008, 10:10 PM
Hey Guys,

My question has to do with the effects of an incoming tick on a Range Bar chart.

Lets say a new tick completes the current bar. In this event, which Function Event will get fired first?

The OnBarUpdate() event since the bar was just closed
-or-
The OnMarketData() event since new MarketData just came in.

This is for a strategy with CalculateOnBarClose = true.

Thanks

NinjaTrader_Josh
09-16-2008, 08:35 AM
mrlogik,

There is no guaranteed sequence. One or the other can come first.

mrlogik
09-16-2008, 09:04 AM
Thank you Josh.

My inquiry was to avoid a race condition within my own code. I will code based on your answer.

mrLogik

anachronist
09-21-2008, 11:29 AM
I'm wondering if one couldn't just have OnMarketData() call OnBarUpdate() when CalculateOnBarClose=true.
-Alex

NinjaTrader_Josh
09-22-2008, 08:17 AM
Alex,

I am not sure what you mean. CalculateOnBarClose does not affect OnMarketData() so you can still do whatever you want in there even with CalculateOnBarClose = true.

anachronist
09-22-2008, 03:39 PM
I am not sure what you mean. CalculateOnBarClose does not affect OnMarketData() so you can still do whatever you want in there even with CalculateOnBarClose = true.
I was referring to your comment that there is no guaranteed sequence regarding which executes first, OnBarUpdate() or OnMarketData().

I suggested a way toward guaranteeing a sequence, although I wasn't clear about it.

Basically, if you want to guarantee the order of execution, you need to have OnBarUpdate() do nothing if OnMarketData() hasn't set a certain flag. OnMarketData() would set this flag and call OnBarUpdate() when needed. OnBarUpdate() would un-set the flag when finished.

You would still need CalculateOnBarClose=true for efficiency, so that a do-nothing OnBarUpdate() doesn't get called multiple times per bar.

Does that sound correct?

-Alex

NinjaTrader_Josh
09-23-2008, 08:20 AM
Alex,

Not having a guaranteed sequence is the way multi-threaded programming works. Unfortunately this change will not be possible for various internal reasons. This is why the new methods are recommended for advanced programmers only.

anachronist
09-26-2008, 05:31 PM
Josh, I don't understand why you seem to think I am suggesting a change. I'm well aware of how multithreading works; been doing that since before MS Windows ever existed.

All I suggested was a way for a NinjaTrader user to guarantee the sequence, if that is what's desired. The coding method I suggested above should do it.

-Alex

NinjaTrader_Ray
09-27-2008, 09:59 AM
Thanks for the suggestion, we will take it under consideration.

anachronist
09-28-2008, 04:49 PM
Um, what...? Take what under consideration? Where did I suggest a change to NinjaTrader? I suggested a way that a user can get around the unpredicatbility inherent in multithreading.
-Alex

mrlogik
09-28-2008, 04:55 PM
I was referring to your comment that there is no guaranteed sequence regarding which executes first, OnBarUpdate() or OnMarketData().

I suggested a way toward guaranteeing a sequence, although I wasn't clear about it.

Basically, if you want to guarantee the order of execution, you need to have OnBarUpdate() do nothing if OnMarketData() hasn't set a certain flag. OnMarketData() would set this flag and call OnBarUpdate() when needed. OnBarUpdate() would un-set the flag when finished.

You would still need CalculateOnBarClose=true for efficiency, so that a do-nothing OnBarUpdate() doesn't get called multiple times per bar.

-Alex

I believe this is what Ray is talking about.

anachronist
09-28-2008, 05:00 PM
I thought so too, but that was really more a suggestion for you and other users, not for an internal change to NT. I thought that was clear.
-Alex