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
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
-
Hi Alex, that would depend mainly on code structure, as the Close would be sensitive to called context, so tied to the BarsInProgress you're in. If you want to access other bars array data in another BarsInProgress then you would need to specifically point to that via Closes[x] / BarsArray[x]BertrandNinjaTrader Customer Service
-
Code structure is usual:
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.BertrandNinjaTrader Customer Service
Comment
-
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.
Originally posted by NinjaTrader_Bertrand View PostThe BarsRequired / CurrentBars check for all bars objects is valid and recommended.
Comment
-
Originally 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.BertrandNinjaTrader Customer Service
Comment
-
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
-
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
-
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 benmarkal, Yesterday, 12:52 PM
|
3 responses
22 views
0 likes
|
Last Post Today, 05:22 AM | ||
Started by helpwanted, Today, 03:06 AM
|
1 response
18 views
0 likes
|
Last Post Today, 03:35 AM | ||
Started by Brevo, Today, 01:45 AM
|
0 responses
11 views
0 likes
|
Last Post
by Brevo
Today, 01:45 AM
|
||
Started by aussugardefender, Today, 01:07 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 01:07 AM | ||
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
244 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
Comment