Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Indicators not showing on last bar
Collapse
X
-
Hello YD777,
These events are data driven. If no ticks come in, there is nothing to trigger OnBarUpdate or OnMarketData. NinjaTrader can't know for sure that the bar is closed until a tick with a time stamp of the new bar comes in.
For example lets say 10 ticks come in at the end of the bar all with the exact same time stamp. NinjaTrader could capture the first and ignore the other 9 since the first has a timestamp of the last millisecond of the bar. But then the volume for that bar would be incorrect and those last 9 ticks would be lost.
So, by waiting until the first tick of the next bar, we can be certain that the ticks for the most recently built bar are correct.
Leave a comment:
-
I'm not sure if MrSmartGuy ever got this issue resolved, but I understand what he is saying. And I'm looking for the same kind of answers he is looking for. Maybe let me try to rephrase the question. ChelseaB says:
What I want to know, and what I think MrSmartGuy wanted to know, is why can't Ninjatrader simply close out a bar at the end time for that bar? Why does it have to wait for another tick OUTSIDE that bar to occur? E.g. if you're building a day bar, once that day is over ALL the information needed for that bar is available. So what's the point of waiting for the next tick, especially if that next tick might not come for hours (or days if weekend starts). If his bars closed at the time he expected them, then his indicator would run when he expected it to, and his issue would be solved.Originally posted by NinjaTrader_ChelseaB View PostAs I mentioned in post #6, the bar is closed when the new bar opens. That means that a bar will not be closed until there is a new building bar on the chart.
Do you understand what I mean? And if you do, the question becomes: is there a way to have a bar close out once it's time span has ended, without waiting for an unnecessary tick to occur in the next bar?Last edited by YD777; 08-03-2016, 02:10 PM.
Leave a comment:
-
Hi MrSmartGuy,
NinjaScript is event driven. Meaning there has to be received ticks to drive things like closing bars and opening new bars, or placing orders, triggering OnMarketData and the other NinjaScript event methods, etc.
Try placing an order to the Sim101 after the session has closed or when you are disconnected. This will result in an error that there is no market data to drive the simulation engine.
Code in a script is able to process in real time when Calculate on bar close is set to false or when a timer is used. What we are trying to highlight is how c# and NinjaTrader works internally and how you can write the proper code to work accordingly.
A tick is needed to drive the event that closes the bar that opens the new bar. If no new bar is opened, the current bar is still the current bar.
If you need information from a bar before the bar closes, then your script will have to run the calculation and set the plot before the bar closes. So you can check this on every tick in between bars, or you can use a timer and check when ever you would like and set the plot.
In other words, if you need your script to behave in this way, the script needs to be coded to behave in this way. You will code to run before information stops being received or you will need to have a timer. Both will work fine, and your script with the proper logic will be able to have a plot that plots for the current day.
Try setting the script to Calculate on bar close false so that it runs in real time. This may give you a better idea of why this will plot for the current day on a daily chart.
Leave a comment:
-
Chelsea,
I'm just not seeing how you can divorce the fundamental element of time from your definition of synchronization. Imagine two military units synchronizing their efforts, and then showing up on different days, which is what is happening here between the price bar and the indicators. Do we only record the landing of plane at an airport at the moment when the plane next takes off?
Your statement in your last post that "The bar is not closed after the end of the session" is exactly the issue I'm concerned about. I don't know any traders who perceive the "end of the session" to mean anything other than the "close of the session." To claim that the opening of the next session is the same as the closing of the prior session begs the question then of why we need both an opening price and a closing price for a bar.
I think the mystery may have some resolution in what looks to be a high ratio of day traders using NT. In this case, with one bar instantly following another with no delay, the notion of updating the last bar when the current one starts is genuinely equivalent. But a swing trader, such as myself, uses the time between sessions to analyze swing movements, and the presence of timely indicator data, synchronized with session closure, is critical. I suspect the original system designers had mostly intraday trading in mind.
While I have now developed a scheme to work around the situation, I encourage NT to develop an indicator update option which supports the needs of those not trading intraday. A good way to think of this is that any instrument which has a session close with significant time up until the next session open would need support. Although even 24/7 instruments take brakes on the weekends (maybe they are 24/5?), I'm sure that I am not the only trader who looks at charts on the weekend. And it sure would be nice if the indicators on those charts were synchronized with the bars closing on Friday.
Like I said, I now have a work-around solution to meet my own needs, so I will leave you be on this subject. I will soon be activating a live account after using the NT no-cost developmental option. It has taken me some time to learn the NT software structures, and I am happy to report that I am able to typically code up strategies and indicators with only one quarter the number of lines of code that it takes in some other languages.
I do appreciate your responding to my questions, and wish you the best.
MSG
Leave a comment:
-
To what data feed are you connected? I would surmise that it is the free Kinetick EOD?Originally posted by MrSmartGuy View PostChelsea, koganam:
Yes, koganam, today's bar is not on the chart, per your observation, as a new bar only appears at the end of the day after trading for SPY closes. Each evening, I get a new price bar reflecting the day's price action. The indicators also advance by one day, but they are always lagging by one day, as shown in the chart I provided. As the price bar closes at this time, then why would the indicators not update, also. That bar is set in concrete, and will never change again.
Chelsea -- please recognize that there are two issues here. The first issue is when things are updated, and right now the price bar is updated shortly after trading closes for SPY each evening, with the indicators coming along 24 hours later.
The second issue is whether or not the price bar and indicators are synchronized, regardless of when they appear. To me, a full one day lag between the price bar and its companion indicators does not represent synchronization between the printing of the price bar and the indicators. If NT also delayed the printing of the price bar for 24 hours then, while I would still not like the answer, at least the claim could be made that they are synchronized.
Sometimes an old-fashioned telephone call can more quickly resolve such things. Please private message me when a good time is to talk and where to call, and I will call you.
MSGLast edited by koganam; 11-19-2015, 02:10 PM.
Leave a comment:
-
Hello MrSmartGuy,
As I mentioned in post #6, the bar is closed when the new bar opens. That means that a bar will not be closed until there is a new building bar on the chart.
The bar is not closed after the end of the session.
The bar is closed after the first tick of the new session is received opening the new bar.
The indicator on the chart is using the Open, High, Low, and Close of the bar on the chart. If the open, high, low, and close of the chart is accurate then its the exact same information that is supplied to the indicator.
Unless you are supplying a secondary data series with some other instrument or time frame, there is not away for the indicator to be out of sync with the bar it is plotted on when it is using the information from that bar after the bar closes for its input source for its calculations.
So, yes, the bars on the chart and the indicators using those bars for their input source are synchronized.
In the screenshot, the bar for the 19th has not opened. Thus, the bar on the 18th has not closed. If the bar for the 18th has not closed, then OnBarUpdate has not run yet for that bar and the plot has not yet been set.
You are not seeing the indicator on the current bar because the current bar has not closed. When the current bar closes, there will be a new bar on the chart and the indicator will plot for the current bar that has just closed.
If you would like a call, you will need to send an email to platformsupport [at] ninjatrader [dot] com.Last edited by NinjaTrader_ChelseaB; 11-19-2015, 01:30 PM.
Leave a comment:
-
Chelsea, koganam:
Yes, koganam, today's bar is not on the chart, per your observation, as a new bar only appears at the end of the day after trading for SPY closes. Each evening, I get a new price bar reflecting the day's price action. The indicators also advance by one day, but they are always lagging by one day, as shown in the chart I provided. As the price bar closes at this time, then why would the indicators not update, also. That bar is set in concrete, and will never change again.
Chelsea -- please recognize that there are two issues here. The first issue is when things are updated, and right now the price bar is updated shortly after trading closes for SPY each evening, with the indicators coming along 24 hours later.
The second issue is whether or not the price bar and indicators are synchronized, regardless of when they appear. To me, a full one day lag between the price bar and its companion indicators does not represent synchronization between the printing of the price bar and the indicators. If NT also delayed the printing of the price bar for 24 hours then, while I would still not like the answer, at least the claim could be made that they are synchronized.
Sometimes an old-fashioned telephone call can more quickly resolve such things. Please private message me when a good time is to talk and where to call, and I will call you.
MSG
Leave a comment:
-
Thanks koganam,
MrSmartGuy, is your question 'why isn't there a bar on the SPY daily chart for today?'?
Are you currently connected to a real-time data feed?
Can you show the Chart Trader area so that we may see you have ask and bid prices receiving?
Leave a comment:
-
Look at the date. Today's bar is not on the chart.Originally posted by MrSmartGuy View PostHi Chelsea,
I have attached a screen shot of a simple SPY daily chart with an SMA indicator added to it. This clearly shows the lack of synchronization that I am referring to. The screen just, just taken today, Thursday, at 1100 central time, shows the price bar with its Wednesday close, but the SMA is only calculated through to the Tuesday bar.
So, in the middle of the trading day, when there is absolutely no question that another price bar has started, there is no updated indicator from the prior day. Bottom line is that the price bar has updated correctly, but not the companion indicators, i.e. they are not properly synchronized.
Thank you for your efforts in considering this.
MSG
Leave a comment:
-
Hi MrSmartGuy,
I am still not understanding how these are not synchronized.
The indicator does not show on the last bar on the chart because the last bar on the chart has not closed (triggering the plot to be set) because calculate on bar close is set to false.
This is as I have explained in post #6.
"Each bar is closed as the new bar opens. Without a new tick to open the new bar, the current bar does not close. Until the bar closes, the code to the set the value for that bar is not run."
However, the value for the second to last bar on the chart (the most recently fully closed bar) should have an accurate value. Are you finding the SMA value on the second to last bar is incorrect?
Leave a comment:
-
Hi Chelsea,
I have attached a screen shot of a simple SPY daily chart with an SMA indicator added to it. This clearly shows the lack of synchronization that I am referring to. The screen just, just taken today, Thursday, at 1100 central time, shows the price bar with its Wednesday close, but the SMA is only calculated through to the Tuesday bar.
So, in the middle of the trading day, when there is absolutely no question that another price bar has started, there is no updated indicator from the prior day. Bottom line is that the price bar has updated correctly, but not the companion indicators, i.e. they are not properly synchronized.
Thank you for your efforts in considering this.
MSG
Leave a comment:
-
Hello MrSmartGuy,
When you mention "Could you share with us why things are not synced with the open and close of the exchanges trading the instrument?", I am not understanding what you are referring to by this.
When the first bar closes, the open of the first bar of the session will match the open of the session.
Are you comparing a minute chart on NinjaTrader with a minute chart on the exchange's website?
Do you have a screenshot to show that these are showing different prices?
Regarding internet usage, NinjaTrader is already receiving every real-time tick and every market data event in real time for every instrument you have in a window like a chart or superdom. Indicators added to that chart, are allowed to call and process that already received real-time data. Once a chart is opened to an instrument, it is fully connected to a live stream of that instrument. Adding or subtracting indicators does not use any more or less of this live stream.
Regarding NinjaTrader servers, any script that is running on your machine, is only running on your machine. If you add too many indicators, this can overload your local computer's CPU and will slow down performance for you but this will not happen for any NinjaTrader server or any other users computers.
Setting a script to run in Calculate on bar close will cause the CPU usage of your local computer to increase. However, if you want your indicator to continuously update in real time, that would be necessary to do.
It would be possible to edit the code of each indicator separately and add code that prevents the script from working in real time unless the time is close to the end of the session. This logic would have to be custom coded by you or by a consultant and added to the code of each indicator.
There is no global option for Calculate on bar close.
When you mention "If I switched the flag off at night to see the indicators, would I find myself waiting of the download of all the tick data for the day?", I am not understanding what you are asking. Are you asking if you set Calculate on bar close to false that new tick data would not be received the next day? No, with COBC set to false, new data will still come in the next day.
Yes, you can add a check to the code of a script to prevent the script from running in real time until a certain time.
For example if you write at the top of OnBarUpdate():
if (!FirstTickOfBar || (ToTime(Time[0]) > 140000 && ToTime(Time[0]) < 80000))
{
return;
}
This would stop processing unless it was either the first tick of the bar or the time is after 2 PM and before 8 AM.
Yes, all bar types process on every tick when COBC is false.
Leave a comment:
-
Thank you for the details, Chelsea. If I could please get your thoughts on implementation options, please.
OK, I understand that with the COBC parameter set to true, then the actual calculation, and therefore usefulness of the calculation, will not occur until the next bar opens. Could you share with us why things are not synced with the open and close of the exchanges trading the instrument?
Moving forward, most of my decisions are made in the evening, after the market closes, so, if I hear you right, I can set the COBO param to false to see the indicators, and that does seem to work on my charts. That's workable, although the processing of each tick could be a significant processing load, as well as internet data traffic. Considering all of these concerns, what do you recommend for someone like me processing daily data after the market close each day, in preparation for the next day? That's a lot of data to move, when only the final result is desired, and would seem to only add to the load of the NT servers, which I'm sure is significant.
-- I've only come across individual COBC flags for each indicator. Is there a global option?
-- If I switched the flag off at night to see the indicators, would I find myself waiting of the download of all the tick data for the day?
-- Perhaps there are time checks to put in the "on bar update" processes code to minimize processing load?
-- I currently have separate code for daily, weekly, and monthly "on bar update" calls. Will all three processes see each tick arriving?
Surely I am not the first person to deal with us. What guidance can you provide? Thanks!
Leave a comment:
-
Hello MrSmartGuy,
When Calculate on bar close (COBC) is set to True, the indicator would never plot on the current bar.
Each bar is closed as the new bar opens. Without a new tick to open the new bar, the current bar does not close. Until the bar closes, the code to the set the value for that bar is not run.
This means that Friday's bar will close after the first tick that starts Monday's session is received.
As the new tick is received, this makes a new building bar for Monday and the plot for Friday will appear.
The SPY uses the US Equities RTH session template by default. The hours of this are from 9:30 AM to 4:00 PM EST Monday through Friday.
This means that Friday's bar should appear closed Monday morning at 9:30 AM EST.
When COBC is set to false, the Plot can be set on every received tick using 0 for 0 bars ago.
When the plot appears all depends on when the .Set() is called.If it is only triggered when the bar closes, then it doesn't appear until there is a new bar on the chart. Because of this you would never see the indicator plot on the current bar, no matter what session template is used when COBC is true.
Leave a comment:
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by kinfxhk, 07-14-2026, 09:39 AM
|
0 responses
93 views
0 likes
|
Last Post
by kinfxhk
07-14-2026, 09:39 AM
|
||
|
Started by kinfxhk, 07-13-2026, 10:18 AM
|
0 responses
93 views
0 likes
|
Last Post
by kinfxhk
07-13-2026, 10:18 AM
|
||
|
Started by kinfxhk, 07-13-2026, 09:50 AM
|
0 responses
71 views
0 likes
|
Last Post
by kinfxhk
07-13-2026, 09:50 AM
|
||
|
Started by kinfxhk, 07-13-2026, 07:21 AM
|
0 responses
88 views
0 likes
|
Last Post
by kinfxhk
07-13-2026, 07:21 AM
|
||
|
Started by kinfxhk, 07-11-2026, 02:11 AM
|
0 responses
67 views
0 likes
|
Last Post
by kinfxhk
07-11-2026, 02:11 AM
|

Leave a comment: