here is a example where its obviously not working as i am not seeing any data on my output window
#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.Gui.Tools; #endregion //This namespace holds Add ons in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.AddOns { /* Example of subscribing/unsubscribing to bars data events from an Add On as well as making bars requests. The concept can be carried over to any NinjaScript object you may be working on. */ public class AddonAlertsTab : NinjaTrader.NinjaScript.AddOnBase { private int daysBack = 5; private bool barsRequestSubscribed = false; private BarsRequest barsRequest; protected override void OnStateChange() { try { if (State == State.SetDefaults) { PrintTo = PrintTo.OutputTab2; Description = @"Enter the description for your new custom Add on here."; Name = "AddonAlertsTab"; barsRequest = new BarsRequest(Cbi.Instrument.GetInstrument("EUR/USD"), 8); } else if (State == State.Configure) { } else if (State == State.DataLoaded) { // Parametrize your request. barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 30 }; barsRequest.TradingHours = TradingHours.Get("Default 24 x 7"); // Attach event handler for real-time events if you want to process real-time data barsRequest.Update += OnBarUpdate; } else if (State == State.Terminated) { // Unsubscribe to events try { barsRequest.Update -= OnBarUpdate; barsRequest.Dispose(); barsRequest = null; } catch (Exception e) { Print(e.StackTrace); } } } catch (Exception e) { Print(e.StackTrace); } } // This method is fired on real-time bar events private void OnBarUpdate(object sender, BarsUpdateEventArgs e) { /* Depending on the BarsPeriod type of your barsRequest you can have situations where more than one bar is updated by a single tick. Be sure to process the full range of updated bars to ensure you did not miss a bar. */ // Output bar information on each tick for (int i = e.MinIndex; i <= e.MaxIndex; i++) { // Processing every single tick NinjaTrader.Code.Output.Process(string.Format("Tim e: {0} Open: {1} High: {2} Low: {3} Close: {4}", e.BarsSeries.GetTime(i), e.BarsSeries.GetOpen(i), e.BarsSeries.GetHigh(i), e.BarsSeries.GetLow(i), e.BarsSeries.GetClose(i)), PrintTo.OutputTab1); } } } }
Comment