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()
{
Dictionary<int, StockEntry> stocks = new Dictionary<int, StockEntry>();
//5min bars
stocks.Add(1, new StockEntry { Name = "ABC", Period = PeriodType.Minute, Value = 5, Count = 0 } );
stocks.Add(2, new StockEntry { Name = "ACE", Period = PeriodType.Minute, Value = 5, Count = 0 } );
}
protected override void OnBarUpdate()
{
for (int series = 0; series < 3; series++)
if (BarsInProgress == series)
//Condtions for entry here..
var stockEntry = stocks[series];
EnterLong(200);
{
if(stocks.ContainsKey(series))
{
stockEntry.Count++;
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Relation between key and index using Dictionary and Struct
Collapse
X
-
Relation between key and index using Dictionary and Struct
I'm a bit mixed up on the relation between the Key in a Dictionary and the Index#. When I am adding stocks to the dictionary as below, does the first stock added get an Index of 1 and also a Key of 1? Are they one in the same. Does it look like I have done this correctly?
Code:Tags: None
-
Hello zachj,
Thank you for your post.
The BarsInProgress is referenced in starting with 0. 0 (zero) applies to the bar series the indicator or strategy is applied to on the chart or Strategies tab of the NinjaTrader Control Center. Any additional bar series added in your code is added with 1, 2, 3, etc. consecutively.
For information on multiple bar series in your code please visit the following link: http://www.ninjatrader.com/support/h..._threading.htm
Using a Dictionary collection is not directly supported in NinjaScript, this is a general C# programming item. Count will begin with 1 and continue from there. For information on Count in C# please visit the following link: http://msdn.microsoft.com/en-us/library/27b47ht3.aspx
Please let me know if I may be of further assistance.
-
I'm not exactly sure what you are getting at. I'm just using Count to count the # of trades that have been entered I don't believe that will interfere with the indexing at all or the addition of stocks. If there have been 0 trades Count = 0, if 1 trade Count = 1. Am I missing something?
Comment
-
Hello zachj,
Thank you for your response.
Unfortunately I am not aware of what the index will be when adding item to the Dictionary Collection. This is a general C# item and I recommend reviewing the information available on the MSDN site: http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
571 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
330 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
548 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
549 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment