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 > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 05-07-2008, 01:53 AM   #1
michaelbb
Member
 
Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 times in 0 posts
Default BarsSinceEntry() real-time vs. Historical

I get different result from BarSinceEntry() in real-time vs. historical data. In real-time I get the entrybar with BarSinceEntry() == 1 / on historical data with BarSinceEntry() == 0 ( CalculateOnBarClose is true).

My goal is to set profit target to BE +/- 1 if entry bar is not moving (close equal or below/above close of signal bar).

My test code for illustration (OnBarUpdate Method):

...
int barSinceEntryLimit = 0;
if (!Historical)
barSinceEntryLimit = 1;
if (isLongTrade && BarsSinceEntry() == barSinceEntryLimit && ( Close[0] <= Close[1] ))
beExitLong = true;
if (isShortTrade && BarsSinceEntry() == barSinceEntryLimit && ( Close[0] >= Close[1] ))
beExitShort = true;
...

Can someone please explain why BarsSinceEntry() works different on historical / real-time data?
michaelbb is offline  
Reply With Quote
Old 05-07-2008, 02:45 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

It depends on when your entry order was actually submitted/filled. Please see this article about the discrepancies between real-time and historical: http://www.ninjatrader-support.com/H...sBacktest.html
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-07-2008, 04:09 AM   #3
michaelbb
Member
 
Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 times in 0 posts
Default

Dont understand your answer. Link to does not help at all.

Did some debugging to understand what is going on.

From my point of view BarsSinceEntry() is not working correct.

Example:

Signal bar is the bar ending 10:34 (EntryLong is called on barclose of this bar).

In backtest order if filled at 10:34:00 / in market replay order is filled at 10:34:00 / in real time order is filled at 10:34:01.

So entry bar is 10:38 bar in my understanding?

On bar close of 10:38 bar next OnBarUpdate is executed. At this time in backtest BarsSinceEntry() is 0 / in market replay and in real-time BarsSinceEntry() is 1 (real-time not tested / debugged but it would explain error I got yesterday) .

In my opinion BarsSinceEntry() should be 0 on 10:38 bar. But I understand that at processing of OnBarUpdate the 10:42 bar has already started (OnBarUpdate is fired on first tick of 10:42 bar?). So its ok as well if you think that it should be 1. But then it should also be 1 in backtest!!
michaelbb is offline  
Reply With Quote
Old 05-07-2008, 07:18 AM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

BarsSinceEntry historical and realtime is the same value: the numbers of bars between when an execution occurred and "CurrentBar". Please make sure you have CalculateOnBarClose=True on your real time tests.

Sample: Is the execution sits on the 10:34 bar of your 1 minute series (you could check on chart) and OnBarUpdate is processing the 10:37 bar, then BarsSinceEntry will be 3 real time and historical.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 05-07-2008, 07:59 AM   #5
michaelbb
Member
 
Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 times in 0 posts
Default

As I told you from my tests it is not the same!

Do you expect the same value or did you test it?

In your example at processing the 10:37 bar BarsSinceEntry() will return 3 on historical data and 4 on market replay or real-time. I assume that "processing the 10:37 bar" means the bar with Time[0] is 10:37 (CalculateOnBarClose=True).

That is result of my tests/debugging.
michaelbb is offline  
Reply With Quote
Old 05-07-2008, 09:01 AM   #6
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Please double check that the execution on chart in all cases is on the 10:34 bar.
NinjaTrader_Dierk 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
Tick Filter Failed (Real Time & Historical) wayneFH Strategy Development 8 11-02-2011 09:22 AM
How real real-time DOM and TS ? maxima General Programming 5 05-01-2008 02:54 PM
Strategy Fails to Transition from Historical to Real Time wayneFH Strategy Development 5 04-07-2008 12:45 PM
Mixing real-time and historical data daven Connecting 1 12-07-2007 01:09 PM
Backfilling Forex Real-Time Charts with Historical Data JohnL Connecting 4 05-24-2007 11:42 AM


All times are GMT -6. The time now is 11:50 PM.