Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
BarsInProgress
Collapse
X
-
Correct, in BarsInProgress 0 you act if your primary series / instrument / stock updates. With reference to Closes[1] at that point you query the secondary instruments close price into the condition.
-
Sorry, I just hurried. I mean to setOriginally posted by NinjaTrader_Bertrand View PostNot exactly, you point to the specific data you wish to use, but you do not tell the code when to do it. If the primary series gets an update, if the secondary gets an update etc, that's what BarsInProgress is used for.
Well I did all this only to avoid editing many [0] to [0][0].Code:protected override void Initialize() ....... BarsRequired = userValueFromVariables; Add("MyStock", PeriodType.Day, 1); ........... protected override void OnBarUpdate() if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired) return; [B][COLOR="Green"]//Here I enter LONG, than SHORT, so add BarsInProgress here for both LONG and SHORT[/COLOR] if (BarInProgress==0) {[/B] if (Closes[1][0]>myS && conditions for long) { there are only main stock values in use: Close[0] etc. and nothing from added instrument } if (Closes[1][0]<myS && conditions for Short) { there are only main stock values in use: Close[0] etc. and nothing from added instrument } [B]}[/B][COLOR="green"] //and here we close if()[/COLOR] if (conditions for trails) {there are only main stock values in use} protected override void OnExecution(IExecution execution) {there is EntryOrder and trails operating.}
Leave a comment:
-
Not exactly, you point to the specific data you wish to use, but you do not tell the code when to do it. If the primary series gets an update, if the secondary gets an update etc, that's what BarsInProgress is used for.
Leave a comment:
-
Well in my case this would be ok, isn't it? Because for added instrument I use [1][0].Originally posted by NinjaTrader_Bertrand View PostIt will depend actually what you want to do here Alex, when you want something to calculate, BarsInProgress gives you just feedback what bars object is calling OnBarUpdate(), so the event.
Only OnBarUpdate() would have those calls, OnPosition / OnExecution is tied to their own events and not the bar updates at all.
Leave a comment:
-
Theoretically yes, however my suggestion would be always included a check for all instruments to avoid running into race conditions.
Leave a comment:
-
So, in this case I can set only CurrentBar[0]>=BarsRequired without same for added instrument?Originally posted by NinjaTrader_Bertrand View PostThen you already have determined your BarsRequired, it's dictated by your main series. Calcs would start then after those 100 bars after your both series would have data, so the 2005 date.
Leave a comment:
-
Then you already have determined your BarsRequired, it's dictated by your main series. Calcs would start then after those 100 bars after your both series would have data, so the 2005 date.
Leave a comment:
-
I forgot to explain one thing. The problem is main bars need 100 bars for calculation and second bars don't need it (just to calculate from first bar appeared). This because of different beginning in history. Is it clear? For example, main bars start from 01/01/2003 and added bars start from 01/01/2005.Originally posted by NinjaTrader_Bertrand View PostPer default BarsRequired is 20. You can compare to an int variable of course as well.
What you can advice?
Leave a comment:
-
It will depend actually what you want to do here Alex, when you want something to calculate, BarsInProgress gives you just feedback what bars object is calling OnBarUpdate(), so the event.
Only OnBarUpdate() would have those calls, OnPosition / OnExecution is tied to their own events and not the bar updates at all.
Leave a comment:
-
Dear Bertrand, so I need to set BarsInProgress==0 in the beginning of OnBarUpdate()? What about other methods? Position(), Execution() etc.?
Leave a comment:
-
Per default BarsRequired is 20. You can compare to an int variable of course as well.
Leave a comment:
-
What BarsRequired equal by default? Can I leave it by default? (don't assign any value for it) And write something like thisOriginally posted by NinjaTrader_Bertrand View PostAlex, you can compare to a custom BarsRequired value of course as well.
For the BarsInProgress, it would need implementation in your code then....
Code:if (CurrentBars[0] <= valueFromVariable || CurrentBars[1] <= BarsRequired) return;
Leave a comment:
-
Alex, you can compare to a custom BarsRequired value of course as well.
For the BarsInProgress, it would need implementation in your code then....
Leave a comment:
-
Thanks. I've read this few times.Originally posted by NinjaTrader_Bertrand View PostYou do not have any filter for BarsInProgress here? That would be the first thing that needs implementation, as otherwise all bars objects are calling OnBarUpdate() and you would see all the calls in all your conditions.
Ok. But what should I do, if I set BarsRequired=userValueFromVariables and this value differs from what I need for added instrument?Originally posted by NinjaTrader_Bertrand View PostThe BarsRequired / CurrentBars check for all bars objects is valid and recommended.
Leave a comment:
-
You do not have any filter for BarsInProgress here? That would be the first thing that needs implementation, as otherwise all bars objects are calling OnBarUpdate() and you would see all the calls in all your conditions.
The BarsRequired / CurrentBars check for all bars objects is valid and recommended.
Leave a comment:
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
152 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
89 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
133 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
127 views
1 like
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
107 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Leave a comment: