I've put a Print statement inside each method and onBarUpdate is executed the first every time I reload the ninjascript in a chart using tick replay.
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
The OnMarketData() method is guaranteed to always be called before OnBarUpdate()
Collapse
X
-
The OnMarketData() method is guaranteed to always be called before OnBarUpdate()
Is this really true?
I've put a Print statement inside each method and onBarUpdate is executed the first every time I reload the ninjascript in a chart using tick replay.Tags: None
-
Hello johnrocargas, and thank you for your question.
While incoming market data is reacted to before bars complete, for historical data processing, if you would like to guarantee an exact sequence of stored events are replayed for both the OnBarUpdate and OnMarketData events, you will need the Tick Replay feature enabled. You can learn more about this feature here,
If any tick replay or Ninja questions come up please don't hesitate to reach out.Jessica P.NinjaTrader Customer Service
-
It's not that I want to guarantee the order. I've just done a simple test.
1. I've created and empty Indicator script with Calculate on each tick enabled.
2. I've put a Print statement inside the onBarUpdate and another Print statement inside the onMarketData 3. I've cleared the Ninjascript Output window.
4. I've attached the indicator to a chart with some bars.
The very first line of the Ninjascript Output is the one coming from the Print statement inside the onBarUpdate, not from the onMarketData Print statement.
Comment
-
Thank you for this additional information. Without Tick Replay enabled for historical data, to answer your question, there is no guaranteed ordering.
If you filter out non-live data the necessity for Tick Replay to getting OnMarketData events to precede OnBarUpdate will make itself apparent. You can do so with code such as the following at the beginning of OnBarUpdate or OnMarketData :
Code:[FONT=Courier New]if (State < State.Realtime) { return; }[/FONT]
Jessica P.NinjaTrader Customer Service
Comment
-
Tick Replay is always enabled. I have Tick Replay enabled in the chart I'm doing the test. I don't want to have Tick Replay disabled. I'm just trying to understand the execution flow of the two methods while the Tick Replay mode is on and Calculate is on each tick. It's not clear from the docs how they are supposed to be used together. In addition, if NT8 is multithreaded and those methods are executed in different threads (which again is not clear from the docs) that can cause other problems that are not addressed in the docs.Last edited by joanrocagas; 01-04-2017, 12:40 PM.
Comment
-
I've done another test.
For every new T & S line I see in the Ninjascript Output
onBarUpdate
onMarketData
so, Why am I seeing the Print statement from the onBarUpdate BEFORE the Print from the onMarketData?
Comment
-
Thank you for helping clear this up, I believe I understand a little better what is occurring. Just to make sure I am completely on the same page, when you say OnBarUpdate is executing before OnMarketData - which should not be occurring - are you referring to the order that Print statements show up in the Output Window? If so, NinjaTrader is a multithreaded, asynchronous, event driven application, and as such Output Window ordering is not a guarantee of execution order.
I would like to recommend the following :
- Replace your Print("message") calls by Log("message", LogLevel.Information)
- If the message you are printing does not include the timestamp, I also recommend adding Time[0].ToString("HH:mm:ss.fff") to any messages you send out
If the ordering in your Log (your logs are in (My) Documents\NinjaTrader 8\logs) still does not match the ordering on the charts here,
Please let us know so we can investigate further. OnMarketData calls should precede OnBarUpdate.Jessica P.NinjaTrader Customer Service
Comment
-
Comment
-
I appreciate your patience. It looks like your copy of NinjaTrader and the ones available to me on the machines available to me are behaving differently. We must therefore discover what is occurring local to your system.
Could you run the script I have attached on your system, and let me know if the output you receive is different from the output I have attached in terms of OBU / OMD order?
If you get the same order I do, could you modify my script so it produces OBU events before OMD events, and send it my way? Please attach any returned code sample as a text document.
When you run this test, please ensure all the following. These are likely steps you already took and once again I appreciate your patience, but please work through this checklist as it will ensure our systems have the same configuration :
- Tools -> Options -> Market Data -> Show Tick Replay is checked
- Right-click on your chart -> Data Series -> Tick Replay is checked
- You are using a 2 second chart
Thank you once again, if we can discover what is happening on your system it may benefit other customers.Attached FilesJessica P.NinjaTrader Customer Service
Comment
-
I've done the tests.
The first OBUPrinter - the file you sent me - is calculated on each bar close. I've attached the output. It is exactly like yours.
After that, I've modified the OBUPrinter to calculate OnEachTick. See the attached .cs file.
I've attached also the output. You can see there that the OBU method is always called before the OMD method.Last edited by joanrocagas; 01-04-2017, 03:20 PM.
Comment
-
What?
So are you saying that NT8 calls OMD before OBU except on Calculate.OnEachTick? This behaviour is not consistent.
If I'm adding up buy/sell volume at ask like in the BuySellVolume indicator
Code:protected override void OnMarketData(MarketDataEventArgs e) { if(e.MarketDataType == MarketDataType.Last) { if(e.Price >= e.Ask) { buys += e.Volume; } else if (e.Price <= e.Bid) { sells += e.Volume; } } } protected override void OnBarUpdate() { if (CurrentBar < activeBar || CurrentBar <= BarsRequiredToPlot) return; // New Bar has been formed // - Assign last volume counted to the prior bar // - Reset volume count for new bar if (CurrentBar != activeBar) { Sells[1] = sells; Buys[1] = buys + sells; buys = 0; sells = 0; activeBar = CurrentBar; } Sells[0] = sells; Buys[0] = buys + sells; }
Also why do say in the docs
The OnMarketData() method is guaranteed to always be called before OnBarUpdate()
Can you guys check why this is implemented this way, please?Last edited by joanrocagas; 01-04-2017, 03:51 PM.
Comment
-
in this old thread seem to be talking about the same problem
onBarUpdate lags 1 trade tick because is called BEFORE onMarketData!! it should be the other way!
Could some NinjaTrader dev share some light into this, please?
Comment
-
I have more carefully reviewed the documentation, and while NinjaScript is truly event driven and asynchronous, I was mistaken earlier in saying this is the correct behavior. You are correct, there are strong guarantees in the documentation against this. For reference I am providing a quote from OnMarketData.
Originally posted by http://ninjatrader.com/support/helpGuides/nt8/en-us/onmarketdata.htmThe OnMarketData() method is guaranteed to always be called before OnBarUpdate()
This behavior was confirmed on our end. We will be investigating this further. Please keep an eye on the NinjaTrader 8 Release Notes page for updates and bugfixes.
Tracking ID: NTEIGHT-10990
A link to this forums post has been included in the bug report, and the developers will be aware of any posts in this thread.Jessica P.NinjaTrader Customer Service
Comment
-
Thanks Jessica.
Is there a public bug tracking site or similar to follow the progress on open bugs and such things?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Aviram Y, Today, 05:29 AM
|
0 responses
2 views
0 likes
|
Last Post
by Aviram Y
Today, 05:29 AM
|
||
Started by quantismo, 04-17-2024, 05:13 PM
|
3 responses
25 views
0 likes
|
Last Post Today, 05:23 AM | ||
Started by ScottWalsh, 04-16-2024, 04:29 PM
|
7 responses
34 views
0 likes
|
Last Post Today, 05:15 AM | ||
Started by cls71, Today, 04:45 AM
|
0 responses
6 views
0 likes
|
Last Post
by cls71
Today, 04:45 AM
|
||
Started by mjairg, 07-20-2023, 11:57 PM
|
3 responses
217 views
1 like
|
Last Post
by PaulMohn
Today, 04:22 AM
|
Comment