NexusFi: Find Your Edge


Home Menu

 





Arraylist in Ninjatrader


Discussion in NinjaTrader

Updated
    1. trending_up 3,132 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
no111
NED
 
Posts: 34 since May 2010
Thanks Given: 7
Thanks Received: 8

Dear all,

I've got the following problem. I have a strategy which I can test on a basket of stocks, now I want to have one equity curve therefore I want to add multiple symbols into one strategy.

I've added the symbols (SPY, DIA, SLV)and then want to work with a loop.

 
Code
                            
for (int x 0;   x++) { 

if (
Closes[x][0] > Closes[x][0
) { 
variablex Closes[x][0] } 
When using this, the different symbols will overwrite variablex. So I want to create for each symbol their own variablex.

I understand that this can be done with Arraylist.

So I add this in Variables region.
private ArrayList myArray = new ArrayList();

But how to progress further? Something like this instead of variablex?:
myArray.Add((double)(Closes[x][0]));
But then they will still write eachother over.. right?

Thanks in advance!


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Khamenei Vetoes Uranium Transfer as Peace Odds Surge to …
Prediction Markets & Event Contracts
Irans Answer Due Today: Peace Surges to 33.5%, Invasion …
Prediction Markets & Event Contracts
NinjaTrader Parent Payward Acquires Bitnomial for $550M …
Platforms and Indicators
Q1 2026 Shatters All Derivatives Volume Records -- CME H …
Traders Hideout
SEC Advisory Committee Backs Tokenized Securities Exempt …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,114



no111 View Post
Dear all,

I've got the following problem. I have a strategy which I can test on a basket of stocks, now I want to have one equity curve therefore I want to add multiple symbols into one strategy.

I've added the symbols (SPY, DIA, SLV)and then want to work with a loop.

 
Code
                            
for (int x 0;   x++) { 
if (
Closes[x][0] > Closes[x][0
) { 
variablex Closes[x][0] } 
When using this, the different symbols will overwrite variablex. So I want to create for each symbol their own variablex.

I understand that this can be done with Arraylist.

So I add this in Variables region.
private ArrayList myArray = new ArrayList();

But how to progress further? Something like this instead of variablex?:
myArray.Add((double)(Closes[x][0]));
But then they will still write eachother over.. right?

Thanks in advance!

If I understand correctly, you will only have a limited know number of values for x. In that case a fixed array is more appropriate then an array list of variable dimension.

 
Code
private double[]  variablex = new double [3];


should do the trick. You can then use it as

 
Code
variablex[0] = Closes[0][0];
variablex[1] = Closes[1][0];


etc.


Reply With Quote
Thanked by:




Last Updated on July 16, 2012


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts