NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 05-21-2010, 08:35 AM   #1
Turtle Trader
Senior Member
 
Join Date: May 2009
Posts: 343
Thanks: 0
Thanked 0 times in 0 posts
Default BarsAgo appears to be lagging

Hello,

As soon (i.e. immediately) as a new bar opens, I am needing to start scanning the prior bars.

I must have something wrong because it looks to me like on the first tick of a new bar that the [0] bar pointer has not yet been moved to the new bar.

Below is the code to indicate what is happening, if you put it in an indicator, on a new bar [0] is still pointing to what I would have thought would now be [1].

(If you run it on a tick chart it will move fast enough to see what is happening.)

Is this so?

If possible, how can I reliably start processing backwards on the first tick of a new bar?

Do I need to treat [0] as [1]?

If so at what point does [0] move to the current bar, making that process invalid?

Thank you.

================================================


// This method is used to configure the indicator and is called once before any bar data is loaded.
protected override void Initialize()
{
CalculateOnBarClose = true;
Overlay = true;
AutoScale = false;
}

/// Called on each bar update event (incoming tick)
protected override void OnBarUpdate()
{

Print ("--------------------------------------------");
Print ("New Bar");

Print("Bar 0 Open = "+Open[0].ToString());
DrawArrowDown("tag1", true, 0, Open[0] + TickSize, Color.Red);

if (CurrentBar < 1)
return;

Print("Bar 1 Open = "+Open[1].ToString());
DrawArrowDown("tag2", true, 1, Open[1] + TickSize, Color.Blue);

}
Turtle Trader is offline  
Reply With Quote
Old 05-21-2010, 10:01 AM   #2
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

Hi Turtle Trader,

This is the nature of how CalculateOnBarClose = true; behaves.
More info at - http://www.ninjatrader-support.com/H...ateOnBarClose1

If you want the logic to calculate [0] as the current bar, use CalculateOnBarClose = false;

Alternatively, you can separate logic to calculate partially with COBC = false, and another part to only calculate once per bar.
See this sample - http://www.ninjatrader.com/support/f...ad.php?t=19387
NinjaTrader_Tim is offline  
Reply With Quote
Old 05-21-2010, 10:35 AM   #3
Turtle Trader
Senior Member
 
Join Date: May 2009
Posts: 343
Thanks: 0
Thanked 0 times in 0 posts
Default reply

Thank you.

It looks like what I need to do is set COBC = false and use the boolean FirstTickofBar.
Turtle Trader is offline  
Reply With Quote
Old 05-21-2010, 10:37 AM   #4
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

Hi Turtle Trader,

Great, glad to hear you are up and running.
NinjaTrader_Tim is offline  
Reply With Quote
Old 05-21-2010, 11:08 AM   #5
Turtle Trader
Senior Member
 
Join Date: May 2009
Posts: 343
Thanks: 0
Thanked 0 times in 0 posts
Default reply

Yes, it is working perfectly now.

Thanks again.
Turtle Trader 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
Strategy Analyzer: Performance only appears in Instruments grid, not in Summary adamus Version 7 Beta General Questions & Bug Reports 6 05-18-2010 11:11 AM
NT lagging Lost Trader Miscellaneous Support 1 05-07-2009 12:51 PM
I found a bug that appears every so often... VagyokC4 Strategy Development 8 09-28-2007 08:22 AM
New User Needs Help -- No data appears in chart ninja.man Charting 1 08-31-2007 03:23 PM
Ninja Lagging guy Miscellaneous Support 2 03-28-2006 11:09 AM


All times are GMT -6. The time now is 08:46 PM.