Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
BarsInProgress
Collapse
X
-
BarsInProgress
Hello. I've wrote script only for main instrument. Now after debugging I'd like to add some instruments to script. So, should I change Clolse[0] to Closes[0][0] etc. or I can leave everything as is for main instrument and only use Closes[1][0] for second instrument?Tags: None
-
Code structure is usual:
As you can see, I just add only 2 short conditions as filter on Entries. That's it. But after I did that, strategy went wrong.Code:protected override void Initialize() ....... BarsRequired = userValueFromVariables; Add("MyStock", PeriodType.Day, 1); ........... protected override void OnBarUpdate() if (CurrentBars[0] <= BarsRequired || [COLOR="Red"]CurrentBars[1] <= BarsRequired[/COLOR]) [COLOR="Magenta"]//should I add BarsRequired for added instrument if BarsRequired = userValueFromVariables and is for main instrument? Can I just miss this condition?[/COLOR] return; if (Closes[1][0]>myS && [COLOR="Red"]conditions for long[/COLOR]) [COLOR="Magenta"]//conditions for long use main instrument values: Close[0] etc. Maybe problem is here? And I should write here if (Closes[1][0]>myS && conditions with Close[0][0]???[/COLOR] { 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 } if (conditions for trails) {there are only main stock values in use} protected override void OnExecution(IExecution execution) {there is EntryOrder and trails operating.}
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.
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.
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;
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.
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?
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.
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.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
637 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
366 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
569 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
571 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment