Go Back   NinjaTrader Support Forum > NinjaTrader 7 > General Development

General Development General NinjaScript development questions.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 11-09-2011, 03:50 AM   #1
FREEN
Senior Member
 
Join Date: Mar 2010
Location: Sweden
Posts: 171
Thanks: 17
Thanked 8 times in 7 posts
Default Last Historical Bar?

Any suggestion on how to trigger OnBarUpdate on last historical bar only?

Bars.LastHistorical or Bars.Loaded properties would be handy properties for this purpose.

The indicator I´m working with uses Infinite lookback and performs all historical calculations (0 -> CurrentBar looping) on each bar - hence last historical/current bar update only would make loading faster.

Kindly, Fredrik
Last edited by FREEN; 11-09-2011 at 04:25 AM.
FREEN is offline  
Reply With Quote
The following user says thank you to FREEN for this post:
Old 11-09-2011, 04:28 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 26,245
Thanks: 496
Thanked 1,866 times in 1,796 posts
Default

Hi Frederik, try doing your calcs then in a condition like this :

if (Bars.Count - 2 == CurrentBar && Historical)
{
do calcs on last historical bar
}
NinjaTrader_Bertrand is offline  
Reply With Quote
The following 2 users say thank you to NinjaTrader_Bertrand for this post:
Old 02-03-2015, 10:40 PM   #3
marty087
Senior Member
 
Join Date: Apr 2012
Location: Sydney, Australia
Posts: 168
Thanks: 73
Thanked 36 times in 29 posts
Default

HI Guys,

I would like to do exactly what Freen has requested here.

Bertrand, I tried your solution.... am I missing something here because your suggested code still only allows the indicator to load if it is the last bar on the chart. "Bars.Count" returns the same value as "Count" for me. So therfore your code will skip every bar until we are at Count - 2 which is when all historical bars are already loaded. What if we want the indicators code to only initiate once the CurrrentBar has arrived at the current scroll point of the chart?
marty087 is offline  
Reply With Quote
Old 02-03-2015, 11:29 PM   #4
ninZa
Senior Member
 
ninZa's Avatar
 
Join Date: May 2014
Posts: 307
Thanks: 819
Thanked 108 times in 85 posts
Default

Can you clarify the meaning of "scroll point"? A screenshot with your notes on it will easily explain.
ninZa
NinjaTrader Ecosystem Vendor - Ninza
ninZa is offline  
Reply With Quote
Old 02-03-2015, 11:33 PM   #5
sledge
Senior Member
 
Join Date: Aug 2010
Location: Washington, D.C.
Posts: 4,500
Thanks: 1,690
Thanked 1,099 times in 942 posts
Default

Quote:
Originally Posted by marty087 View Post
HI Guys,

I would like to do exactly what Freen has requested here.
Then you are not doing exactly what Freen is doing.
sledge is offline  
Reply With Quote
The following user says thank you to sledge for this post:
Old 02-04-2015, 01:49 AM   #6
FREEN
Senior Member
 
Join Date: Mar 2010
Location: Sweden
Posts: 171
Thanks: 17
Thanked 8 times in 7 posts
Default

Quote:
Originally Posted by ninZa View Post
Can you clarify the meaning of "scroll point"? A screenshot with your notes on it will easily explain.
Scroll point in the sense last bar on screen, that might not be bars.count.
FREEN is offline  
Reply With Quote
Old 02-04-2015, 02:11 AM   #7
marty087
Senior Member
 
Join Date: Apr 2012
Location: Sydney, Australia
Posts: 168
Thanks: 73
Thanked 36 times in 29 posts
Default

Quote:
Originally Posted by ninZa View Post
Can you clarify the meaning of "scroll point"? A screenshot with your notes on it will easily explain.
See pic for clarification
Attached Images
File Type: jpg ChartPic.jpg (215.5 KB, 23 views)
marty087 is offline  
Reply With Quote
Old 02-04-2015, 02:17 AM   #8
marty087
Senior Member
 
Join Date: Apr 2012
Location: Sydney, Australia
Posts: 168
Thanks: 73
Thanked 36 times in 29 posts
Default

In short....

CurrentBar returns the id of the last bar displyed on the right of the screen irrecpective of whether the chart is scrolled to the end or not.

Count OR Bars.Count returns how many bars are in the chart once fully loaded / scrolled to the right alll the way

So..... if i am in the middle of the chart and want my indicator to only execute once it has arrived at the furtherest scrooled bar, is there any way to do this?

FREEN, is it fair to say that the supplied code below (Bertrand's contribution) didnt provide a solution for you?

Cheers Guys.
marty087 is offline  
Reply With Quote
Old 02-04-2015, 02:19 AM   #9
ninZa
Senior Member
 
ninZa's Avatar
 
Join Date: May 2014
Posts: 307
Thanks: 819
Thanked 108 times in 85 posts
Default

marty087, please try LastBarIndexPainted. I'm not sure this works in your case. This will give you the last bar painted on chart after the bars are loaded. In your case, you want to get the value in advance, so I'm not sure. Please test it, if it doesn't work, we will have to take another approach.

Thanks.
ninZa
NinjaTrader Ecosystem Vendor - Ninza
Last edited by ninZa; 02-04-2015 at 02:22 AM.
ninZa is offline  
Reply With Quote
The following user says thank you to ninZa for this post:
Old 02-04-2015, 03:02 AM   #10
ninZa
Senior Member
 
ninZa's Avatar
 
Join Date: May 2014
Posts: 307
Thanks: 819
Thanked 108 times in 85 posts
Default

Quote:
Originally Posted by marty087 View Post
In short....

CurrentBar returns the id of the last bar displyed on the right of the screen irrecpective of whether the chart is scrolled to the end or not.

Count OR Bars.Count returns how many bars are in the chart once fully loaded / scrolled to the right alll the way

So..... if i am in the middle of the chart and want my indicator to only execute once it has arrived at the furtherest scrooled bar, is there any way to do this?

FREEN, is it fair to say that the supplied code below (Bertrand's contribution) didnt provide a solution for you?

Cheers Guys.
marty087, when you are in the middle of the chart, the indicator will only execute until the last bar printed on your chart and then it will temporarily stop there, until a LIVE tick comes in. If there are no live data coming in, the indicator will not reach the actual last bar (whose index is Bars.Count - 1). You have to manually scroll your chart back to the actual last bar. This is my 30-minute inspection on the issue, need a confirmation from NT staff.

However, if in a live market with fast coming data, you can execute the following unsupported codes to ignore all bars until the last painted bar:

Quote:

if (ChartControl.GetXByBarIdx(BarsArray[0], CurrentBar) < ChartControl.CanvasRight) return;
Cheers.
Pi
ninZa
NinjaTrader Ecosystem Vendor - Ninza
Last edited by ninZa; 02-04-2015 at 03:08 AM.
ninZa is offline  
Reply With Quote
The following 2 users say thank you to ninZa for this post:
Old 02-04-2015, 03:04 AM   #11
marty087
Senior Member
 
Join Date: Apr 2012
Location: Sydney, Australia
Posts: 168
Thanks: 73
Thanked 36 times in 29 posts
Default

Quote:
Originally Posted by ninZa View Post
marty087, please try LastBarIndexPainted. I'm not sure this works in your case. This will give you the last bar painted on chart after the bars are loaded. In your case, you want to get the value in advance, so I'm not sure. Please test it, if it doesn't work, we will have to take another approach.

Thanks.
BOOM! Worked a charm. Where did you pull that one from?

Thanks.
Attached Images
File Type: jpg LastIndexPainted.jpg (121.2 KB, 12 views)
marty087 is offline  
Reply With Quote
The following user says thank you to marty087 for this post:
Old 02-04-2015, 03:18 AM   #12
ninZa
Senior Member
 
ninZa's Avatar
 
Join Date: May 2014
Posts: 307
Thanks: 819
Thanked 108 times in 85 posts
Default

Quote:
Originally Posted by marty087 View Post
BOOM! Worked a charm. Where did you pull that one from?

Thanks.
It works actually? I'm not sure, so I gave you another solution above.

I don't remember where I got the info of LastBarIndexPainted. Perhaps searched something on Google and found it.

Regards.
Pi
ninZa
NinjaTrader Ecosystem Vendor - Ninza
ninZa is offline  
Reply With Quote
Old 02-04-2015, 03:56 AM   #13
marty087
Senior Member
 
Join Date: Apr 2012
Location: Sydney, Australia
Posts: 168
Thanks: 73
Thanked 36 times in 29 posts
Default

Quote:
Originally Posted by ninZa View Post
It works actually? I'm not sure, so I gave you another solution above.

I don't remember where I got the info of LastBarIndexPainted. Perhaps searched something on Google and found it.

Regards.
Pi
Great stuff. Thanks again
marty087 is offline  
Reply With Quote
The following user says thank you to marty087 for this post:
Old 02-04-2015, 11:30 AM   #14
koganam
Senior Member
 
Join Date: Feb 2008
Location: omegasigmaindicators.com
Posts: 7,226
Thanks: 56
Thanked 3,008 times in 2,433 posts
Default

Quote:
Originally Posted by marty087 View Post
BOOM! Worked a charm. Where did you pull that one from?

Thanks.
Probably from here: http://www.ninjatrader.com/support/f...d.php?p=261631

Though, given his skills, Ninza may have come upon that independently.
koganam is offline  
Reply With Quote
The following user says thank you to koganam for this post:
Old 02-04-2015, 05:22 PM   #15
ninZa
Senior Member
 
ninZa's Avatar
 
Join Date: May 2014
Posts: 307
Thanks: 819
Thanked 108 times in 85 posts
Default

Quote:
Originally Posted by koganam View Post
Probably from here: http://www.ninjatrader.com/support/f...d.php?p=261631

Though, given his skills, Ninza may have come upon that independently.
My skill is googling Koganam lol.

Regarding your comment about the dependence on COBC, should we reverse the order? I mean the 1st one (ChartControl) should be absolute, and the 2nd one is dependent on COBC?
ninZa
NinjaTrader Ecosystem Vendor - Ninza
Last edited by ninZa; 02-04-2015 at 06:21 PM.
ninZa 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
Last Historical Bar blar58 Indicator Development 2 01-04-2011 02:11 PM
OnBarUpdate not sent for last historical bar in chart pkatta Indicator Development 1 01-13-2010 07:56 AM
Range Bar Historical DATA yoramva Platform Technical Support 5 12-01-2009 06:01 AM
Historical and first bar of current session palinuro General Development 3 07-02-2008 11:55 AM
Historical tick bar calculations??? higler General Development 1 06-19-2007 10:27 AM


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

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.