![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Member
Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 times in 0 posts
|
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!! |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Please double check that the execution on chart in all cases is on the 10:34 bar.
Dierk
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |