NewsItems
Definition
NewsItems can be used to store news articles.
Properties
| Property | Description |
|---|---|
| Items | Collection of NewsEventArgs representing news articles |
| NewsToMaintain | An int representing the number of articles to maintain |
| Update() | For storing news articles |
Syntax
NewsItems
Examples
1 /* Example of storing and accessing news items from an Add On. The concept can be carried over 2 to any NinjaScript object you may be working on. */ 3 public class MyAddOnTab : NTTabPage 4 { 5 private NewsSubscription newsSubscription; 6 private NewsItems newsItems; 7 8 public MyAddOnTab() 9 { 10 // Subscribe to news 11 newsSubscription = new NewsSubscription(); 12 newsSubscription.Update += OnNews; 13 newsItems = new NewsItems(10); 14 15 // Print news 16 PrintNews(newsItems); 17 } 18 19 // This method is fired as new News events come in. Old News events are not provided when you subscribe. 20 private void OnNews(object sender, NewsEventArgs e) 21 { 22 // Store the news items 23 newsItems.Update(e); 24 } 25 26 // Loop through the stored news articles and output them 27 private void PrintNews(NewsItems news) 28 { 29 for (int x = 0; x < news.Items.Count; x++) 30 { 31 NinjaTrader.Code.Output.Process(string.Format("ID: {0} News Provider: {1} Headline: {2}", 32 news.Items[x].Id, 33 news.Items[x].NewsProvider, 34 news.Items[x].Headline), PrintTo.OutputTab1); 35 } 36 } 37 38 // Called by TabControl when tab is being removed or window is closed 39 public override void Cleanup() 40 { 41 // Make sure to unsubscribe to the News subscription 42 if (newsSubscription != null) 43 newsSubscription.Update -= OnNews; 44 } 45 46 // Other required NTTabPage members left out for demonstration purposes. Be sure to add them in your own code. 47 }

