NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 11-03-2008, 07:57 AM   #1
cassb
Senior Member
 
Join Date: Nov 2007
Location: Victor, NY
Posts: 577
Thanks: 5
Thanked 4 times in 4 posts
Send a message via Yahoo to cassb Send a message via Skype™ to cassb
Default How to: Mixed-type, multidimensional array?

Sorry to ask a basic programming question, but C# is not my native language.

I want an array that looks like this:

Array[1,534.2]="Some string value". So I have Array[number,number]=string.

How do you do this in C#?

I tried this:

private double[,] = new Array[6,6];

But it seems that the array cannot have a string as a value.
Price-Dynamics.com
A NinjaTrader Official Partner

Visit http://www.price-dynamics.com to learn more about the Rhythm Relay trading system. Yes, you can discretionary or auto-trade with 75%+ accuracy!

Use our Contact Us page to request free access to our daily Trader's Lounge where you can see the system in action in a live account!
Last edited by cassb; 11-03-2008 at 08:00 AM.
cassb is offline  
Reply With Quote
Old 11-03-2008, 08:09 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Please try
private string[,] myArray = new string[6,6];
NinjaTrader_Dierk is offline  
Reply With Quote
Old 11-03-2008, 08:38 AM   #3
cassb
Senior Member
 
Join Date: Nov 2007
Location: Victor, NY
Posts: 577
Thanks: 5
Thanked 4 times in 4 posts
Send a message via Yahoo to cassb Send a message via Skype™ to cassb
Default

Quote:
Originally Posted by NinjaTrader_Dierk View Post
Please try
private string[,] = new string[6,6];
Tried that:

Array = new string[6,6];
Array[0,534.2]="Test";

Compiling this causes this:
Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
Price-Dynamics.com
A NinjaTrader Official Partner

Visit http://www.price-dynamics.com to learn more about the Rhythm Relay trading system. Yes, you can discretionary or auto-trade with 75%+ accuracy!

Use our Contact Us page to request free access to our daily Trader's Lounge where you can see the system in action in a live account!
cassb is offline  
Reply With Quote
Old 11-03-2008, 08:40 AM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

My apologies, edited post below.

Also array indexes needed to be int not double.

Note: these are basic C# programming question. Unfortunately we can't provide support level down to that level.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 11-03-2008, 08:45 AM   #5
cassb
Senior Member
 
Join Date: Nov 2007
Location: Victor, NY
Posts: 577
Thanks: 5
Thanked 4 times in 4 posts
Send a message via Yahoo to cassb Send a message via Skype™ to cassb
Default

Quote:
Originally Posted by NinjaTrader_Dierk View Post
My apologies, edited post below.
It wants integers for the array subscripts. I can't use a double value for a subscript. Maybe I need an array within an array? I don't understand why this concept is so complex in C#.

Think of what I'm trying to do as:

Array[Bar Number,Price] = "Text"
Price-Dynamics.com
A NinjaTrader Official Partner

Visit http://www.price-dynamics.com to learn more about the Rhythm Relay trading system. Yes, you can discretionary or auto-trade with 75%+ accuracy!

Use our Contact Us page to request free access to our daily Trader's Lounge where you can see the system in action in a live account!
cassb is offline  
Reply With Quote
Old 11-03-2008, 09:44 AM   #6
cassb
Senior Member
 
Join Date: Nov 2007
Location: Victor, NY
Posts: 577
Thanks: 5
Thanked 4 times in 4 posts
Send a message via Yahoo to cassb Send a message via Skype™ to cassb
Default

Quote:
Originally Posted by cassb View Post
It wants integers for the array subscripts. I can't use a double value for a subscript. Maybe I need an array within an array? I don't understand why this concept is so complex in C#.

Think of what I'm trying to do as:

Array[Bar Number,Price] = "Text"

Just a note in case someone is looking at this thread in the future -- I decided to just convert the price to an integer and convert it back to double when needed. To convert to integer, where pricedecimals is the number of decimals in TickSize:

x = Convert.ToInt16(price*(10^pricedecimals))
Array[0,x]="text"

To reconvert back to price:

price = Convert.ToDouble(x/(10^pricedecimals))
Price-Dynamics.com
A NinjaTrader Official Partner

Visit http://www.price-dynamics.com to learn more about the Rhythm Relay trading system. Yes, you can discretionary or auto-trade with 75%+ accuracy!

Use our Contact Us page to request free access to our daily Trader's Lounge where you can see the system in action in a live account!
cassb is offline  
Reply With Quote
Old 10-27-2012, 04:16 AM   #7
gym.prathap
Junior Member
 
Join Date: Oct 2012
Location: chennai
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
Default

The mixed arrays type is removed from .NET 4.0. I have not really seen any use of mixed arrays.


.Net Training in chennai
gym.prathap is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mixed minute/daily time frames? monpere Strategy Development 12 06-08-2011 04:10 PM
Array question... funk101 Indicator Development 14 01-21-2009 07:37 AM
Array pipsheker General Programming 1 05-24-2008 03:45 AM
Mixed time frames cherriman Strategy Development 23 03-10-2008 07:03 AM
Indicator using mixed colors kgillis23 Strategy Development 5 05-23-2007 02:07 PM


All times are GMT -6. The time now is 01:35 AM.