if I set BarsRequiredToTrade = 0; in OnStateChange() within (State == State.SetDefaults), will (CurrentBar == 0) in OnBarUpdate() gives me the very first bar of the session when running Strategy Analyzer back test? I seems to be getting the second bar instead of the first bar of the session, and am wondering how to access the very first bar when the session starts?
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
(CurrentBar == 0) is Bars.IsFirstBarOfSession?
Collapse
X
-
(CurrentBar == 0) is Bars.IsFirstBarOfSession?
Hello,
if I set BarsRequiredToTrade = 0; in OnStateChange() within (State == State.SetDefaults), will (CurrentBar == 0) in OnBarUpdate() gives me the very first bar of the session when running Strategy Analyzer back test? I seems to be getting the second bar instead of the first bar of the session, and am wondering how to access the very first bar when the session starts?Tags: None
-
Hello billythekid72,
BarsRequiredToTrade is a property that causes NinjaTrader to ignore orders until the number of bars necessary have been processed in OnBarUpdate.
This is not related to a session, but instead counts forward from wherever the data starts.
Try printing:
Print(string.Format("{0} | CurrentBar: {1}", Time[0], CurrentBar));
This should tell you what bar is the first bar processed.Chelsea B.NinjaTrader Customer Service
-
Hello,
OK, I just found out that, in fact I do get the first bar in a session by testing (CurrentBar == 0) in OnBarUpdate() , however this ONLY happened to the FIRST day in a multi-days back tests in Strategy Analyzer (I am running strategy analyzer for multi days). After the first day, in subsequent days, only SECOND BAR of the day show up with (CurrentBar == 0) in OnBarUpdate(). Any idea why is this happening?
Comment
-
Hello billythekid72,
CurrentBar does not reset to 0 after a new session. It just keeps counting forward from the first historical bar that loads, which is not always the first bar of the session. CurrentBar is the current bar that is being processed in OnBarUpdate(). This is not related to the session at all.
Are you saying that CurrentBar has skipped a bar?
Is the print in a condition?
Can you provide the output saved in a text file?
If you want to know when the first bar of the session is, use Bars.IsFirstBarOfSession.
Chelsea B.NinjaTrader Customer Service
Comment
-
Thank you Chelsea, you answered my question, I now know exactly what went wrong (it's my code). Thanks again.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by realblubb, Today, 09:28 AM
|
0 responses
2 views
0 likes
|
Last Post
by realblubb
Today, 09:28 AM
|
||
Started by AaronKoRn, Yesterday, 09:49 PM
|
1 response
18 views
0 likes
|
Last Post
by Rikazkhan007
Today, 09:24 AM
|
||
Started by ageeholdings, Today, 07:43 AM
|
0 responses
12 views
0 likes
|
Last Post
by ageeholdings
Today, 07:43 AM
|
||
Started by pibrew, Today, 06:37 AM
|
0 responses
4 views
0 likes
|
Last Post
by pibrew
Today, 06:37 AM
|
||
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
14 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
Comment