How do you create a List to store variables? - NinjaTrader Programming | futures io social day trading
futures io futures trading


How do you create a List to store variables?
Updated: Views / Replies:5,838 / 15
Created: by forrestang Attachments:2

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 2  
 
Thread Tools Search this Thread
 

How do you create a List to store variables?

  #1 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received

How do you create a List to store variables?

I need to create a list, that will capture values as the session develops. Each day there will be a different number of values I need to store. I am mainly wanting to do this so that I can print the values out at the end of each session in a specific format.

I really have no idea what a list is, how it works, or anything like that, so I am needing a pretty basic, SIMPLE explanation or example of such a method in practice.

Any help would be appreciated.

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,602 received
Forum Reputation: Legendary


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

Reply With Quote
The following 7 users say Thank You to Fat Tails for this post:
 
  #4 (permalink)
Market Wizard
virginia
 
Futures Experience: Intermediate
Platform: ninja
Favorite Futures: ES
 
cory's Avatar
 
Posts: 5,220 since Jun 2009
Thanks: 628 given, 6,318 received
Forum Reputation: Legendary

here is code to computer average of 10 day true ranges but using Queue
 
Code
	#region Variables
		private int			period		= 10;
	
		private double SumOfDaily = 0; // Average by day
		private double[] Dailyarray;
		private Queue Dailyqueue;

		
		#endregion
	
		/// <summary>
		/// This method is used to configure the indicator and is called once before any bar data is loaded.
		/// </summary>
		protected override void Initialize()
		{
	
			Dailyqueue = new Queue(Period);
			Dailyarray = new double[100];
			Overlay				= true;
		}

		/// <summary>
		/// Called on each bar update event (incoming tick)
		/// </summary>

		protected override void OnBarUpdate()
		{
			if (CurrentBar < Period+1) 
        	return;
			if (Bars.SessionBreak)
        	// Reset or store some values here 
			{
if ((PriorDayOHLC().PriorHigh[0] - PriorDayOHLC().PriorOpen[0]) < 
	Math.Abs(PriorDayOHLC().PriorOpen[0] - PriorDayOHLC().PriorLow[0]))
	Dailyqueue.Enqueue(PriorDayOHLC().PriorHigh[0] - PriorDayOHLC().PriorOpen[0]);
else
	Dailyqueue.Enqueue(Math.Abs(PriorDayOHLC().PriorOpen[0] - PriorDayOHLC().PriorLow[0]));

				if (Dailyqueue.Count > Period + 1)
				{
					Dailyqueue.Dequeue();
				}
				
				Dailyqueue.CopyTo(Dailyarray,0);
				SumOfDaily = 0;
				for (int x = 1; x < Period + 1; x++) 
					{ 
						SumOfDaily = SumOfDaily + Dailyarray[x];
					}
					
			}


Last edited by cory; February 13th, 2012 at 09:27 AM.
Reply With Quote
The following 3 users say Thank You to cory for this post:
 
  #5 (permalink)
Elite Member
Chicago IL
 
Futures Experience: Beginner
Platform: Sierra Chart
Favorite Futures: Futures
 
Posts: 117 since Feb 2012
Thanks: 22 given, 110 received

Going off what Fat Tails said, there is also the List<T> type. It allows you to give a type to your List so if you only want doubles you can do List<double> myDoubleList = new List<double>()

I like the list if you are planning on looping through and want a strong statically typed object. If you need to access it by index then ArrayList is probably better.

Reply With Quote
The following 4 users say Thank You to drw112 for this post:
 
  #6 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received


drw112 View Post
Going off what Fat Tails said, there is also the List<T> type. It allows you to give a type to your List so if you only want doubles you can do List<double> myDoubleList = new List<double>()

I like the list if you are planning on looping through and want a strong statically typed object. If you need to access it by index then ArrayList is probably better.

Do you know of an example of this implemented in NT somewhere?

Reply With Quote
 
  #7 (permalink)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received


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 will give this a try. But thanks,as this was pretty much the level of explanation I was looking for.

Reply With Quote
 
  #8 (permalink)
Elite Member
Chicago IL
 
Futures Experience: Beginner
Platform: Sierra Chart
Favorite Futures: Futures
 
Posts: 117 since Feb 2012
Thanks: 22 given, 110 received


forrestang View Post
Do you know of an example of this implemented in NT somewhere?

Generic Multi-dimensional List - NinjaTrader Support Forum

This thread pretty much explains it. This user is building a List within a List but the idea is the same just slightly more complicated.

Reply With Quote
The following user says Thank You to drw112 for this post:
 
  #9 (permalink)
Elite Member
Paris
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 1,177 since Oct 2009
Thanks: 228 given, 4,097 received


drw112 View Post
Going off what Fat Tails said, there is also the List<T> type. It allows you to give a type to your List so if you only want doubles you can do List<double> myDoubleList = new List<double>()

I like the list if you are planning on looping through and want a strong statically typed object. If you need to access it by index then ArrayList is probably better.

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);     
}

Reply With Quote
The following 6 users say Thank You to gomi for this post:
 
  #10 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,602 received
Forum Reputation: Legendary



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);     
}

@gomi: Thank you for the hint.

I suppose that you are right, so I will make use of it in future.


Last edited by Fat Tails; February 14th, 2012 at 02:26 PM.
Reply With Quote
The following user says Thank You to Fat Tails for this post:

Reply



futures io > > > > > How do you create a List to store variables?

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for Software to store Price data in MySQL caliph Matlab, R project and Python 4 January 7th, 2013 03:11 PM
Store real time data from NT in mysql bascher NinjaTrader 23 November 4th, 2011 06:53 AM
Exposing variables kaywai NinjaTrader Programming 4 April 14th, 2011 12:58 PM
How can I store the first order limit price as a variable to use for calculating... richw NinjaTrader Programming 2 February 22nd, 2011 03:58 PM
PLT_NTDataCollect store bid ask tick data to its local database? rcabri Trading Reviews and Vendors 3 December 27th, 2010 11:00 AM


All times are GMT -4. The time now is 12:28 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-16 in 0.15 seconds with 20 queries on phoenix via your IP 54.226.113.250