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
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
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 WHICKED, 03-27-2024, 12:33 PM
|
4 responses
41 views
0 likes
|
Last Post Today, 12:28 AM | ||
Started by f.saeidi, Today, 12:12 AM
|
0 responses
3 views
0 likes
|
Last Post
by f.saeidi
Today, 12:12 AM
|
||
Started by Conall, Today, 12:06 AM
|
0 responses
5 views
0 likes
|
Last Post
by Conall
Today, 12:06 AM
|
||
Started by proptradingshop, 03-21-2024, 09:50 AM
|
6 responses
27 views
0 likes
|
Last Post Today, 12:02 AM | ||
Started by mly916, Yesterday, 09:48 PM
|
1 response
12 views
0 likes
|
Last Post Yesterday, 11:54 PM |
Comment