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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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
-
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=442BertrandNinjaTrader Customer Service
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/dictionaryBertrandNinjaTrader Customer Service
Comment
-
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);
Code:Dictionary<int, int> _stockCounts = new Dictionary<int, int>();
Comment
-
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
-
-
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
-
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
-
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 } );
}
Code: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:
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 algospoke, Yesterday, 06:40 PM
|
2 responses
19 views
0 likes
|
Last Post
by algospoke
Today, 07:04 PM
|
||
Started by ghoul, Today, 06:02 PM
|
3 responses
14 views
0 likes
|
Last Post Today, 06:43 PM | ||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
45 views
0 likes
|
Last Post
by jeronymite
Yesterday, 10:10 PM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
7 responses
21 views
0 likes
|
Last Post Today, 06:16 PM | ||
Started by AttiM, 02-14-2024, 05:20 PM
|
10 responses
181 views
0 likes
|
Last Post
by jeronymite
Today, 06:11 PM
|
Comment