Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Indicators not painting on last bar
Collapse
X
-
Indicators not painting on last bar
Version 7.1000.6, WinXP Pro. I am coding a custom indicator and found that OnBarUpdate() was not being called for the last bar on the chart. I removed my indicator and added an EMA14 indicator and saw the same problem. Downloaded V6.5 and have the same problem. Fresh install on a different machine and applied an EMA14 and same problem. Have tried this with CL & ES contracts, historical and live, all have the same problem. -
Well that did fix the problem, thank you. Didn't even think of trying that since my code sets this propery to true during Init() and I was only using historical data so I only get called at the end of a bar anyway.
That does actually prompt another question I have been meaning to ask - when using historical data why do I not get an OnBarUpdate() for each tick since the DB has an entry for each tick in chronological order?
Paul
Comment
-
Thanks Bertrand,
I understand what I currently have available using historical data, the question was - since the DB contains every tick in chronological order, what is preventing NT from callling OnBarUpdate() on every tick when using historical data?
TIA
Comment
-
Hi Paul, limiting is the granularity of the series used, if you run a 1 tick series, the OnBarUpdate() is called for each tick - if you like to see the intrabar action / signals for your indicators you could for example use Market Replay for the historical chart portion.BertrandNinjaTrader Customer Service
Comment
-
Originally posted by paulca View PostThanks Bertrand,
I understand what I currently have available using historical data, the question was - since the DB contains every tick in chronological order, what is preventing NT from callling OnBarUpdate() on every tick when using historical data?
TIA
Comment
-
I have the same problem with OnBarUpdate() not being called on the last bar. Yes, setting CalculateOnBarClose = false works, but I don't need/want my indicator to be calculated on every tick. When CalculateOnBarClose is set to true, why doesn't OnBarUpdate() get called?
What I want to do is save Close[0] to my DB on the last bar. Is there another way to do this?
Comment
-
Originally posted by Klaorman View PostI have the same problem with OnBarUpdate() not being called on the last bar. Yes, setting CalculateOnBarClose = false works, but I don't need/want my indicator to be calculated on every tick. When CalculateOnBarClose is set to true, why doesn't OnBarUpdate() get called?
What I want to do is save Close[0] to my DB on the last bar. Is there another way to do this?Last edited by koganam; 12-06-2011, 01:15 AM.
Comment
-
Originally posted by koganam View PostThe bar has to be updated at some point, either when the next bar opens (COBC = false), or when the bar is building (COBC = true). If you want to update at a different frequency intrabar, then you are going to have to create a time filter to update as you want.
Perhaps there's another way to get the closing price of the day?
Here's a workaround: Write another indicator that just looks for the last bar of the day and saves the closing price. This would be very light and can be run on every tick. This seems kludgey though, but I'll try it out.
Comment
-
Ryan M.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_RyanM View PostHi Klaorman,
These are correct observations. With C# being event based, the bar closing and next bar opening events are the same. You may consider using GetBar() to get the bar closing price at a specific time each day. This sample can help use GetBar()
http://www.ninjatrader.com/support/f...ad.php?t=19176
But when would I call GetBar(), during the next trading session? Since OnBarUpdate() doesn't get called for the last bar when COBC = true, I'll have to get the day's closing price during the next trading session, correct?
I wrote the mini-indicator that I mentioned above to look for the last bar of the day with COBC = false. It worked when I put the indicator in a chart, so I added it to a Market Analyzer as a column looking at 2m bars and waited all day to see if it would work. Unfortunately, it didn't. I didn't put any Print() statements in the code to see its execution path because it had worked in the chart; the Print()s are in there for today's session! The only code I have in OnBarUpdate() is the following:
// if last bar of the day, save closing price
if ( ToTime( Time[0] ) == ToTime( 13, 00, 00 ) )
{
// Save closing price to DB
...
}
I'm checking that a bar's timestamp is 1pm PST. No problems there, correct? In Market Analyzer COBC = false; I did, however, set the # of bars to look back to 2 because I didn't think it needed the default of 50, but I've reset it back to 50 for today. This code worked on a chart after the last bar had closed, but it didn't work in real-time in a Market Analyzer. Do you have any clues about why?
I have another question related to COBC: It's set to false for my main indicator in Market Analyzer, but initially I still occasionally got multiple alerts for the same signals (the alerts were identical to each other) intrabar when I called Alert(). I solved this by setting the rearm time to a bar's duration, but why does this happen even after I set the indicator to only calculate on bar close?
Thanks,
Klaorman
Comment
-
Yes, GetBar() would be used to check prior bars. If the bar you want a value for hasn't yet closed, then it's a good opportunity to use CalculateOnBarClose = false. Anytime you need values for the "not yet closed" bar, then COBC = false is the only way.
With market analyzer, you don't have the convenience of chart visuals. Print statements are very useful for confirming values and following code flow so hopefully should tell you more about what your indicator is doing the next time you run it.
This doesn't have to be the type of thing where you wait until 1:00 PM every day to verify functionality and then you're out of luck until tomorrow once it passes. Confirm script behavior by setting the alert time a couple minutes ahead of the current time. Get things working on a simplified level and then customize it once it works as you expect.
Please be aware that bar stamps can vary based on the interval, and you may not have a time stamp exactly at 13:00. Print(Time[0]); will allow you to see each bar stamp.
Alerts are raised each time the condition is true. If you have alerts applied to a column, then it can be true for each row (instrument) in the market analyzer. Adding instrument name to any alert text may help you identify what specific row is calling it and why it may be triggered multiple times.Ryan M.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_RyanM View PostThis doesn't have to be the type of thing where you wait until 1:00 PM every day to verify functionality and then you're out of luck until tomorrow once it passes. Confirm script behavior by setting the alert time a couple minutes ahead of the current time. Get things working on a simplified level and then customize it once it works as you expect.
Originally posted by NinjaTrader_RyanM View PostAlerts are raised each time the condition is true. If you have alerts applied to a column, then it can be true for each row (instrument) in the market analyzer. Adding instrument name to any alert text may help you identify what specific row is calling it and why it may be triggered multiple times.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Stanfillirenfro, Today, 07:23 AM
|
1 response
3 views
0 likes
|
Last Post Today, 07:37 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
2 responses
21 views
0 likes
|
Last Post Today, 07:24 AM | ||
Started by olisav57, Yesterday, 07:39 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:23 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
7 responses
944 views
0 likes
|
Last Post
by Jquiroz1975
Today, 07:21 AM
|
||
Started by oviejo, Today, 12:28 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:20 AM |
Comment