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 > Application Technical Support > Charting

Charting Support for NinjaTrader Advanced Charting.

Reply
 
Thread Tools Display Modes
Old 06-23-2012, 02:01 PM   #1
Trader_55
Member
 
Join Date: Jan 2012
Posts: 73
Thanks: 19
Thanked 1 time in 1 post
Default CaclOnBarClose=false, and Plot method CPU usage

I have a very specific question that I think the developers may be able to answer.

Imagine that you have 3 indicators on a particular chart, called A, B, and C. Indicators A and B are set to CalcOnBarClose=True, and Indicator C is set to CalcOnBarClose=False, which means it updates on every tick.

When a new tick comes in, obviously the OnBarUpdate call will execute on Indicator C, which I would think would also trigger the Plot method of that same indicator, to be able to visually show the new value on the chart.

The question is, does executing the Plot method of Indicator C also indirectly trigger the Plot methods of indicators A and B? If the whole window is repainting as a result of a change in C, I would think that A and B also need to be repainted. This scenario means that if there is CPU-intensive code in the Plot routines of A and B, it will still get triggered on every tick, even though CalcOnBarClose is set to True for those indicators.

Is this the case, or am I missing something? Thanks!
Trader_55 is offline  
Reply With Quote
Old 06-23-2012, 06:23 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Trader,

In this case, there would be no calling of the other indicators methods like OnBarUpdate except for whatever is internally done for the graphics code. Plot methods wouldn't be accessible to you in supported code, and typically they do not need to be changed.
NinjaTrader_AdamP is offline  
Reply With Quote
The following user says thank you to NinjaTrader_AdamP for this post:
Old 06-23-2012, 06:59 PM   #3
Trader_55
Member
 
Join Date: Jan 2012
Posts: 73
Thanks: 19
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_AdamP View Post
Trader,

In this case, there would be no calling of the other indicators methods like OnBarUpdate except for whatever is internally done for the graphics code. Plot methods wouldn't be accessible to you in supported code, and typically they do not need to be changed.
Actually, you can override the Plot method like this:

public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)

There is an indicator in the support forum indicators section called dValueArea7 which does this, along with a number of others. So I know that the OnBarUpdate call of the other indicators is not triggered, but is the Plot method triggered? Sometimes there is quite a bit of code in there, which can be even more intensive than what is in the OnBarUpdate call...
Trader_55 is offline  
Reply With Quote
Old 06-24-2012, 11:35 AM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Trader,

Yes, the plot method can be overridden as its part of the inheritance of the Indicator class. Its just that we don't have a reference sample on doing this currently, nor do we cover it in the help guide. This basically means "unsupported" but not "impossible".

I am actually not sure here when the plot method would be called in relation to OnBarUpdate(), I suspect it would be after but I am not positive in the scenario you mentioned. I'll check with some other members of our NS team on Monday to see if they have any idea and get back to you.
NinjaTrader_AdamP is offline  
Reply With Quote
The following user says thank you to NinjaTrader_AdamP for this post:
Old 06-24-2012, 11:54 AM   #5
Trader_55
Member
 
Join Date: Jan 2012
Posts: 73
Thanks: 19
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_AdamP View Post
Trader,

Yes, the plot method can be overridden as its part of the inheritance of the Indicator class. Its just that we don't have a reference sample on doing this currently, nor do we cover it in the help guide. This basically means "unsupported" but not "impossible".

I am actually not sure here when the plot method would be called in relation to OnBarUpdate(), I suspect it would be after but I am not positive in the scenario you mentioned. I'll check with some other members of our NS team on Monday to see if they have any idea and get back to you.
Thanks, much appreciated... I would think that it would get triggered every time the window is refreshed, which probably needs to happen when a "CalcOnBarClose=false" is updated on the same chart... but I could be wrong. You can let me know what the other team members think... thanks!
Trader_55 is offline  
Reply With Quote
Old 06-25-2012, 07:11 AM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Trader,

After talking with my colleagues, it looks like Plot() is called after each OnBarUpdate() and is responsible for drawing that indicator on the chart. Unfortunately this is a "under the hood" method, and though it can be overridden, it is not recommended. We removed this after NT 6.5 due to some unexpected behavior when people override it, or used it improperly.

Unfortunately I can't really comment much further on this, apologies for any inconvenience.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-26-2012, 06:51 AM   #7
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 1,829
Thanks: 12
Thanked 83 times in 67 posts
Default Plot Override

Just two remarks:

There is a number of NinjaTrader system indicators which override the plot method. This includes the Pivots, RegressionChannel, VolumeProfile, VolumeZones, ZigZag. You can use them as a reference.

The plot is not updated each time OnBarUpdate() has been called. In a fast market you will only get an update after the display update interval, which I have set to 0.5 seconds for my purposes. If you use a display update interval, which is too small, NinjaTrader may freeze in a fast market depending on what is done in the custom plots.
Harry is offline  
Reply With Quote
The following user says thank you to Harry for this post:
Old 06-26-2012, 11:30 AM   #8
Trader_55
Member
 
Join Date: Jan 2012
Posts: 73
Thanks: 19
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by Harry View Post
Just two remarks:

There is a number of NinjaTrader system indicators which override the plot method. This includes the Pivots, RegressionChannel, VolumeProfile, VolumeZones, ZigZag. You can use them as a reference.

The plot is not updated each time OnBarUpdate() has been called. In a fast market you will only get an update after the display update interval, which I have set to 0.5 seconds for my purposes. If you use a display update interval, which is too small, NinjaTrader may freeze in a fast market depending on what is done in the custom plots.
Thanks Harry... so what you are saying is that the refresh rate of the chart will always call the Plot method of each indicator on that chart no matter what, correct? That seems to be the "clock" that drives the refresh rate of the entire chart, according to my understanding of your statement. So to go back to my original question then, it would stand to reason that if you have a CalcOnBarClose=false indicator on the chart, then it must by definition refresh the entire chart on every tick, not on every X refresh seconds, correct? Otherwise the indicator would not be seen updating on every tick. This must mean that all Plot methods are called on every tick. Is my understanding correct?
Trader_55 is offline  
Reply With Quote
Old 06-26-2012, 01:41 PM   #9
Harry
Senior Member
 
Join Date: Oct 2007
Posts: 1,829
Thanks: 12
Thanked 83 times in 67 posts
Default

Quote:
Originally Posted by Trader_55 View Post
Thanks Harry... so what you are saying is that the refresh rate of the chart will always call the Plot method of each indicator on that chart no matter what, correct? That seems to be the "clock" that drives the refresh rate of the entire chart, according to my understanding of your statement. So to go back to my original question then, it would stand to reason that if you have a CalcOnBarClose=false indicator on the chart, then it must by definition refresh the entire chart on every tick, not on every X refresh seconds, correct? Otherwise the indicator would not be seen updating on every tick. This must mean that all Plot methods are called on every tick. Is my understanding correct?
I do not know the internals of NinjaTrader, so whatever I am responding here, would need to be confirmed by somebody who knows it. I am more or less relying on deduction.

When the chart is refreshed all indicators are plotted, as far as I know this does not depend on whether CalculateOnBarClose has been set to true or false. The chart is refreshed earliest when the display update interval has elapsed and a new tick was registered during that interval or afterwards.

As far as I have understood this means that the code of the Plot Override() method may be executed every 0.5 seconds, if the display update interval for the chart is set to that value. This would apply to indicators with both CalculateOnBarClose set to true or false.

For the CPU load this would mean

-> CalculateOnBarClose = true -> OnBarUpdate() is triggered once at the bar close
-> CalculateOnBarClose = false -> OnBarUpdate() is triggered with every incoming tick
-> display update interval = 100 msec -> code contained within Plot Override() is executed up to 10 times per second for all indicators, depending on incoming ticks

But again, it would be better to have this explanation confirmed by somebody else.
Harry is offline  
Reply With Quote
Old 06-26-2012, 02:08 PM   #10
Trader_55
Member
 
Join Date: Jan 2012
Posts: 73
Thanks: 19
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by Harry View Post
I do not know the internals of NinjaTrader, so whatever I am responding here, would need to be confirmed by somebody who knows it. I am more or less relying on deduction.

When the chart is refreshed all indicators are plotted, as far as I know this does not depend on whether CalculateOnBarClose has been set to true or false. The chart is refreshed earliest when the display update interval has elapsed and a new tick was registered during that interval or afterwards.

As far as I have understood this means that the code of the Plot Override() method may be executed every 0.5 seconds, if the display update interval for the chart is set to that value. This would apply to indicators with both CalculateOnBarClose set to true or false.

For the CPU load this would mean

-> CalculateOnBarClose = true -> OnBarUpdate() is triggered once at the bar close
-> CalculateOnBarClose = false -> OnBarUpdate() is triggered with every incoming tick
-> display update interval = 100 msec -> code contained within Plot Override() is executed up to 10 times per second for all indicators, depending on incoming ticks

But again, it would be better to have this explanation confirmed by somebody else.
One way to test this would be to set the display update interval to something like 10 seconds, and then add an indicator on the chart that refreshes with every tick. If you see the indicator updating more than once every 10 seconds, that means that the indicator is overriding the refresh rate of the chart. Otherwise, the refresh rate of the chart must be the driving factor regardless of the indicator settings. In either case, all the Plot() calls must be happening whenever anything is changed on the chart... I don't think that you could refresh the chart without Plot() being called for everything that is on that particular window. If you disagree let me know... I may try testing this to see what happens - if I do I'll report the results.
Trader_55 is offline  
Reply With Quote
Old 06-26-2012, 02:17 PM   #11
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Thanks for your help here Harry.

There are internal mechanisms for plotting the currently forming price bar, outside of any script that is applied. OnBarUpdate() drives chart plotting for indicators and frequency of calls are raised according to CalculateOnBarClose setting defined for the indicator. It's either every tick (false) or on bar close(true).

While OnBarUpdate() will drive plot charting, the chart display is updated only as often as the refresh setting you define in properties. This doesn't affect calculations. It's the smallest time in-between chart display updates. Unless you are overriding plot you still need ticks (OBU calls) as the main driver for indicator plotting. If you override plot, then you could manually control when your chart is drawn, through custom events like timers.
NinjaTrader_RyanM 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
CPU Usage still too high Sergio66 Version 7 Beta General Questions & Bug Reports 12 10-25-2010 03:04 PM
CPU Usage hegh2000 Version 7 Beta General Questions & Bug Reports 8 07-01-2010 03:17 PM
CPU Usage Alfred Miscellaneous Support 10 03-10-2009 04:52 AM
cpu usage ckait Miscellaneous Support 18 11-12-2008 02:19 AM
CPU usage magicboiz Connecting 1 10-15-2008 07:35 AM


All times are GMT -6. The time now is 07:37 PM.