NexusFi: Find Your Edge


Home Menu

 





Arraylist in Ninjatrader


Discussion in NinjaTrader

Updated
    1. trending_up 3,220 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?
Peace Deal Forward Curve: May 22%, June 51%, December 81 …
Prediction Markets & Event Contracts
Iran Forward Curve: June 30 at 56% vs June 15 at 28% -- …
Prediction Markets & Event Contracts
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
Rubios Good News Within Hours and the 30-Day Math: Why H …
Prediction Markets & Event Contracts
Iran Airspace Collapses 18 Points to 15.5% While Hormuz …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
3 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Legendary 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,117



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