NexusFi: Find Your Edge


Home Menu

 





Arraylist in Ninjatrader


Discussion in NinjaTrader

Updated
    1. trending_up 3,280 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?
Iran Lebanon Problem Kills Switzerland Talks, Brent at $ …
Prediction Markets & Event Contracts
No book, only a stair: journaling fills where price move …
Cryptocurrency
Netherlands & Germany Surge as World Cup Field Narro …
Prediction Markets & Event Contracts
Datafeed for Atas
Platforms and Indicators
Would a node-based workflow for automated trading be useful?
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Want your NinjaTrader indicator created, free?
5 thanks
Afternoon-close session
1 thanks
Franks Trading Journey
1 thanks
Denied 20K payouts: Alpha Futures
1 thanks
FootPrintV2 Chart for NT8
1 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