Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Max Down Day
Collapse
X
-
I've read over that many times before, this is good if you only have like 3 or 4 instruments but I was attempting to set this up with the for loop with the expectation to be running a whole index which could be 100 or 200 instruments. This example in the manual would require that I have a massive amount of code, I would have to have 100+ bip lines or paragraphs of code. The foor loop was intended to automate this and have it use the same line/paragraph of code and just switch the series each run.
-
Hello,
Not at all. We are happy to help. However I am unsure as to what your current question is.
Could you please clarify what it is I can assist with?
The choice to use a loop or not is up to you. However, doing so in this case will likely cause performance issues.
Additionally be aware that not all data providers will support the loading of hundreds of instruments at a given time.LanceNinjaTrader Customer Service
Comment
-
I'm not quite understanding how the loop is a logical error or how it will cause performance issues. Also I'm not looking to run 100 instruments live its just for backtesting purposes.
If I have this piece of code below, what is the best way to plugin into "series", in the several locations it is, if the for loop is not logical? Or the best way to use this same piece of code repeatedly but with running different instruments through it.
for (int series = 0; series < 3; series++)
if ((BarsInProgress == series + 3) && Positions[series].MarketPosition == MarketPosition.Long && (SMA(BarsArray[series],Fast)[1] < SMA(BarsArray[series],Slow)[1] && SMA(BarsArray[series],Fast)[2] > SMA(BarsArray[series],Slow)[2] && Closes[series + 3][0] < Lows[series][1] - exitdistance)
Comment
-
It's not a logical error, but think of it like this.
Each time on bar update is called, one bar series will be processed.
Let's say you have 100 series added. If the current BIP is 5 and it reaches an if statement such as if(BIP == 5) it will process its code and ignore the remainder of the script
if you place this in a for loop, every single bar update it will have to loop through 100 different checks instead of just the first 5.
I realize this is more time consuming to manually write this out, so it will be up to you as to which method to choose. If you're only backtesting with this you may find it works better for you to do the loop as you have it (in terms of coding time)LanceNinjaTrader Customer Service
Comment
-
What do you mean by it will ignore the rest of the script? Did you mean once it processes a BIP or certain instrument it will stop the loop and ignore the rest of the BIP's or instruments?
Or did you mean it will ignore the rest of the script as in ignore something further down in the script such as a stoploss or target? Because the latter can't be the case as I can see it's managing to stop out positions.
If it is the first case is there any way to make it go through every BIP before it stops the loop? If say I have series < 100, make it go through all 100 before its ends.
Comment
-
I know you're not using an else if but I provided this as an example to show you how to prevent un-needed checks.
If you have 100 instruments only 1 of them processes OnBarUpdate at a time. If more than one call OBU() at a time it will process them in the order they were added, 1 and a time.
You do not need to check 100 different instruments each time because you know it can only be one of them. You can, but I'm just saying it's not needed.
By counter I'm referring to the for loop counterLanceNinjaTrader Customer Service
Comment
-
I think that's what the problem is here, maybe I didn't make it clear on what I'm trying to do. I'm not looking for anything in just 1 particular instrument, I'm looking for it to trigger a trade in as many instruments as possible that meet the sma crossover signal condition. For instance run SPY through the conditions, if it meets them trigger the trade. Then Run DIA through if it meets conditions then also trigger a trade on that instrument if it doesn't meet them then move to the next instrument and so on until its gone through the whole series of instruments.
Comment
-
Regardless of what is in OnBarUpdate() every added series will always call OnBarUpdate each time it has an update event
Only one will be processed at a time.
If 10 of the series have a bar that closes at the same time (whether they have the same bar increment or the bar closes at the same time with different increment) OBU() will be called 10 times at that moment. It will only process one of those at a time until it has processed all 10
If you're trying to only calculate once every X minutes then I can understand why you would use this loop and I apologize for the misunderstanding.
If that is what you are doing consider returning if the primary series is not the one calling OBU()
you could place this at the start
if(BarsInProgress != 0)
return;
That way it will only call OBU once but if all your instruments have the same closing time you'd be able to get the correct values cross instrument.LanceNinjaTrader Customer Service
Comment
-
Yep, every time there is a bar update event (which means any time any of the added series has a bar close in backtesting, or receives a tick if COBC = false in real time) a series will make a call to OBU()
the True Event Driven OnBarUpdate() Method section here more thoroughly covers this: http://www.ninjatrader.com/support/h...nstruments.htmLanceNinjaTrader Customer Service
Comment
-
But the thing is I have "if (BarsInProgress ==0)", and on all the SMA's I have it is using say [3]. So isn't it just going to keep using series/instrument 0 & 3 over and over? or does 0 move to 1, and 3 moves to 4. Then 1 moves to 2 and 4 moves to 5 automatically?Last edited by zachj; 07-10-2013, 01:13 PM.
Comment
-
if you did something like
SMA(BarsArray[BarsInProgress], 20)[0]
this would get the current 20 period sma value for the Current BIP that was calling OBU()
Please see Using Bars Objects as Input to Indicator Methods for more details: http://www.ninjatrader.com/support/h...nstruments.htmLanceNinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
578 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment