protected override void Initialize()
{
Dictionary<int, int> _stockCounts = new Dictionary<int, int>();
#region Primary 5min
//Primary 5min
_stockCounts.Add("ACE",PeriodType.Minute, 5);
_stockCounts.Add("ACN",PeriodType.Minute, 5);
_stockCounts.Add("ADT",PeriodType.Minute, 5);
CalculateOnBarClose = true;
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Dictionary
Collapse
X
-
Dictionary
In my initialize section I'm trying to use Dictionary. I'm getting compile errors..type or namespace Dictionary not found and _stockCounts does not exist. Something basic I'm doing incorrectly?
Code:Tags: None
-
Have you specified the correct namespace?Originally posted by zachj View PostIn my initialize section I'm trying to use Dictionary. I'm getting compile errors..type or namespace Dictionary not found and _stockCounts does not exist. Something basic I'm doing incorrectly?
Code:protected override void Initialize() { Dictionary<int, int> _stockCounts = new Dictionary<int, int>(); #region Primary 5min //Primary 5min _stockCounts.Add("ACE",PeriodType.Minute, 5); _stockCounts.Add("ACN",PeriodType.Minute, 5); _stockCounts.Add("ADT",PeriodType.Minute, 5); CalculateOnBarClose = true; }
Code:[COLOR=Blue]using[/COLOR] System.Collections.Generic;
-
zachj, since more general C# not an area we could fully support, can you check into koganams's thought - that at minimum would need to be present.
Further you could check into the Spearman indicator offered in the sharing section, it uses a SortedDictionary - http://www.ninjatrader.com/support/f...d=4&linkid=442
Comment
-
I would expect an issue with a dictionary with 3 parameters, you have a key and a value always as pair here - http://www.dotnetperls.com/dictionary
Comment
-
You defined your Dictionary thus:Originally posted by zachj View PostOk so if I have as below, is that by chance giving me a 5min or what would the 5 represent here?
_stockCounts.Add("ACE", 5);
That means that the terms must both be integers. Your code, with a string, is not kosher.Code:Dictionary<int, int> _stockCounts = new Dictionary<int, int>();
Comment
-
No. A Dictionary takes exactly 2 parameters. If you want 3 parameters, you are looking for a different kind of code entity. What you need depends on what you are trying to do. Your code does not show your intent, so there is little that I can say.Originally posted by zachj View PostDictionary<string, int> _stockCounts = new Dictionary<string, int>();
either way if I fix the first argument to be a string, I still only have two arguments to work with and need 3. I don't think Dictionary will take 3. I can't define the PeriodType.
Comment
-
-
Would I have something like this...Originally posted by koganam View PostYou might want to use a List<> of structs, where the struct contains the information that you want to track.
List<Indexes> IndexItems = new List<Indexes>();
list.Add("ACE", PeriodType.Minute, 5);
list.Add("ACN", PeriodType.Minute, 5);
list.Add("ADT", PeriodType.Minute, 5);
Then in the OnBarUpdate section have something like..
public struct Indexes
{
public string ACE { get; set; }
public string ACN { get; set; }
public string ADT { get; set; }
}
Comment
-
Ok giving this another shot koganam, how about this?...Originally posted by koganam View PostYou might want to use a List<> of structs, where the struct contains the information that you want to track.
public struct StockEntry
{
public string Name { get; set; }
public PeriodType Period { get; set; }
public int Value { get; set; }
public int Count { get; set; }
}
protected override void Initialize()
{
List<StockEntry> _stocks = new List<StockEntry>();
//Primary 5min
_stocks.Add(new StockEntry { Name = "ABC", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACE", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACN", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ADT", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "SCTY", Period = PeriodType.Minute, Value = 5, Count = 0 } );
//Secondary 1min
_stocks.Add(new StockEntry { Name = "ABC", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACE", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACN", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ADT", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "SCTY", Period = PeriodType.Minute, Value = 1, Count = 0 } );
}
Comment
-
The pristine way to define a struct would be as follows:Originally posted by zachj View PostOk giving this another shot koganam, how about this?...
public struct StockEntry
{
public string Name { get; set; }
public PeriodType Period { get; set; }
public int Value { get; set; }
public int Count { get; set; }
}
protected override void Initialize()
{
List<StockEntry> _stocks = new List<StockEntry>();
//Primary 5min
_stocks.Add(new StockEntry { Name = "ABC", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACE", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACN", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ADT", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "SCTY", Period = PeriodType.Minute, Value = 5, Count = 0 } );
//Secondary 1min
_stocks.Add(new StockEntry { Name = "ABC", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACE", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACN", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ADT", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "SCTY", Period = PeriodType.Minute, Value = 1, Count = 0 } );
}
ref: http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspxCode:public struct StockEntry { //declare the members public string Name; public PeriodType Period; public int Value; public int Count; //declare the constructor public StockEntry(string strName, PeriodType ptPeriod, int intValue, int intCount) { Name = strName; Period = ptPeriod; Value = intValue; Count = intCount; } }
You use brackets, not braces, when you declare and initialize a struct.
Like so:
The keyword new is not mandatory.Code:StockEntry ("ABC", PeriodType.Minute, 1, 0)Last edited by koganam; 09-22-2013, 06:22 PM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment