![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |||
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
If you want to incorporate some logic to have your indicator or strategy only run on real-time data, then you should incorporate the following.
Checks if bar data is historical or real-time. Ifhistorical, return out of the method. Quote:
When CalculateOnBarClose == false, then OnBarUpdate() is being called for the last bar on the chart: Quote:
Quote:
Ray
Ray
NinjaTrader Customer Service |
|||
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Jan 2005
Location: , ,
Posts: 109
Thanks: 0
Thanked 0 times in 0 posts
|
Ray,
This is my implementation of this, as a user function in the UserDefinedMethods Indicator? This seems to work OK, but I'm confused about the offset from Bars.Count. The only way I can see it is if Bars.Count starts at 1, and Currentbar starts at 0. If one has an indicator that should be processed on the lastbar displayed on the chart (like one controlling white space), this will return true whether or not connected to a data feed. If one checks for Historical while not connected, I assume that code would not execute. Am I on the right track? public bool LastBarOnChart() { bool LBOC = false; if ( CalculateOnBarClose == false && CurrentBar == Bars.Count - 1) LBOC=true; else if ( CalculateOnBarClose == true && CurrentBar == Bars.Count - 2) LBOC=true; else LBOC=false; return LBOC; } |
|
|
|
|
|
#3 | |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
In C#, indexes of a collection are zero based. CurrentBar is an index and so its zero based and starts with zero. Collection.Count is 1 based. Therefore, Bars.Count will return the total number of bars.
Your code will work but I would writeit as a property that would look something like this: Quote:
Ray
NinjaTrader Customer Service |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|