NexusFi: Find Your Edge


Home Menu

 





How do you create a List to store variables?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one forrestang with 7 posts (0 thanks)
    2. looks_two drw112 with 3 posts (5 thanks)
    3. looks_3 Fat Tails with 2 posts (8 thanks)
    4. looks_4 cory with 1 posts (3 thanks)
      Best Posters
    1. looks_one gomi with 6 thanks per post
    2. looks_two Fat Tails with 4 thanks per post
    3. looks_3 cory with 3 thanks per post
    4. looks_4 drw112 with 1.7 thanks per post
    1. trending_up 12,081 views
    2. thumb_up 25 thanks given
    3. group 6 followers
    1. forum 15 posts
    2. attach_file 2 attachments




 
Search this Thread

How do you create a List to store variables?

  #11 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047

I got done what I wanted. Initially I was wanting to create a List so that I could print things out in a specific order via Print() command for later use in excel.

But I figured out how to set up a DDE with NT and excel, so I am able to directly populate a spreadsheet the way I want.

Thanks.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
How to apply profiles
Traders Hideout
What broker to use for trading palladium futures
Commodities
About a successful futures trader who didnt know anythin …
Psychology and Money Management
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #12 (permalink)
 drw112 
Chicago IL
 
Experience: Beginner
Platform: Sierra Chart
Trading: Futures
Posts: 117 since Feb 2012
Thanks Given: 22
Thanks Received: 120


gomi View Post
You can access a List<T> by index.

List<double> will have a better performance than ArrayList because doubles won't be casted to objects when inserting, and objects won't be casted to doubles when accessing. List<double> will also be safer because you will always be sure your list only contains valid doubles, not random objects.

So IMO you'd better use List<double>. ArrayLists are legacy objects used before generic collections appeared in .NET 2.0

Usage is easy, here is an example I found on C# List Examples

 
Code
    
List<int> list = new List<int>();

list.Add(2);     
list.Add(3);     
list.Add(7);     

foreach (int prime in list) // Loop through List with foreach     
{         
Console.WriteLine(prime);     
}

Oops you are definitely right. Momentary brainfart there.

Visit my NexusFi Trade Journal Reply With Quote
  #13 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047



Fat Tails View Post
You can use an ArrayList object. It is basically an array with a variable size, which allows you to add elements of various data types.

Step 1: create the array list:

 
Code
private ArrayList  myArray = new ArrayList();
You have now an empty ArrayList.


Step 2: Add elements to your array list:

 
Code
myArray.Add((double)(Input[0]));
It is important to specify the data type that you add.


Step 3: Retrieve the stored value.

 
Code
value =  (double) myArray[5];
This will retrieve the 6th value that you have added.

Tip
When adding or retrieving a value, you need to specify the data type which is stored in the array list. Without adding (double) in front of the array element, neither adding nor retrieving a value will work.


Of course you can use other data types, for example you can add (string) values.


Further information on array lists is here:

ArrayList Class (System.Collections)

C# ArrayList Tips

I'm working off this one as it is the simplest presented in this thread. But it doesn't seem to work in NT? I get this error.

Attached Thumbnails
Click image for larger version

Name:	2012-03-27_131122.png
Views:	210
Size:	8.1 KB
ID:	67927  
Started this thread Reply With Quote
  #14 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047

Basically the structure would be like the attached picture, where as certain conditions occur or are met, I can just throw the value in whatever index the next empty slot is.

Then be able to access the values later, or reset the container.

Attached Thumbnails
Click image for larger version

Name:	3-27-2012 1-42-34 PM.png
Views:	193
Size:	13.0 KB
ID:	67940  
Started this thread Reply With Quote
  #15 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,395


forrestang View Post
I'm working off this one as it is the simplest presented in this thread. But it doesn't seem to work in NT? I get this error.

You probably need to add something like this to the top of the code (in the declarations section):

 
Code
using System.Collections

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #16 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


NJAMC View Post
You probably need to add something like this to the top of the code (in the declarations section):

 
Code
using System.Collections

Oh wow, thanks, at least it compiles now! I'm so bad at writing ninjaScripts.

Will try it again in a bit.

Started this thread Reply With Quote




Last Updated on March 27, 2012


© 2024 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 - Privacy Policy - Downloads - Top
no new posts