1. It will sometimes give me results that are outside the normal range, which is corrected once I reload the data. Do I need to "sync" the two datastreams somehow so that this doesn't happen?
2. I want the audio alerts to fire off just once per bar, but it isn't firing at all. Yes, I am sure that the sound file is appropriately named and resides where it needs to be.
Any help would be appreciated.
#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { [Description("Premium Trading Levels for the ES front month & S&P 500 Spread Difference")] public class Premium : Indicator { #region Variables private double pTBuy = -2.89; // PTBuy Input private double pTSell = -5.69; // PTSell Sell private bool audioalerts = true; private double difference = 0; private string secondInstrument = @"^SP500"; // Default setting for SecondInstrument private bool AlreadyAlertThisBar=false; #endregion protected override void Initialize() { Add(new Plot(new Pen(Color.Green, 2), "Buy Level")); Add(new Plot(new Pen(Color.Red, 2), "Sell Level")); Add(new Plot(new Pen(Color.Orange, 2), "Difference")); Add(secondInstrument, PeriodType.Minute, 1); CalculateOnBarClose = false; Overlay = false; DrawOnPricePanel = false; PriceTypeSupported = false; } protected override void OnBarUpdate() { // Use this method for calculating your indicator values. Assign a value to each // plot below by replacing 'Close[0]' with your own formula. PTBuyLine.Set(PTBuy); PTSellLine.Set(PTSell); difference = Closes[0][0]-Closes[1][0]; DifferenceSeries.Set(difference); if(FirstTickOfBar) AlreadyAlertThisBar=false; if (CrossAbove(DifferenceSeries,PTBuy,1)) { DrawDot("Buy Dot" + CurrentBar, false, 0, PTBuy, Color.Green); if (AlreadyAlertThisBar=false && AudioAlerts) {PlaySound(@"C:\Sounds\Premium Buy.wav"); AlreadyAlertThisBar=true;} } if (CrossBelow(DifferenceSeries,PTSell,1)) { DrawDot("Sell Dot" + CurrentBar, false, 0, PTSell, Color.Maroon); if (AlreadyAlertThisBar=false && AudioAlerts) {PlaySound(@"C:\Sounds\Premium Sell.wav"); AlreadyAlertThisBar=true;} } } #region Properties [Browsable(false)] [XmlIgnore()] public DataSeries PTBuyLine { get { return Values[0]; } } [Browsable(false)] [XmlIgnore()] public DataSeries PTSellLine { get { return Values[1]; } } [Browsable(false)] [XmlIgnore()] public DataSeries DifferenceSeries { get { return Values[2]; } } [Description("Program Trading Buy Level")] [GridCategory("Parameters")] public double PTBuy { get { return pTBuy; } set { pTBuy = Math.Max(-100, value); } } [Description("Program Trading Sell Level")] [GridCategory("Parameters")] public double PTSell { get { return pTSell; } set { pTSell = Math.Max(-100, value); } } [Description("True=play audio alerts, False=don't play audio alerts.")] [Category("Parameters")] public bool AudioAlerts { get { return audioalerts; } set { audioalerts = value; } } #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private Premium[] cachePremium = null; private static Premium checkPremium = new Premium(); /// Premium Trading Levels for the ES front month & S&P 500 Spread Difference /// <returns></returns> public Premium Premium(bool audioAlerts, double pTBuy, double pTSell) { return Premium(Input, audioAlerts, pTBuy, pTSell); } /// Premium Trading Levels for the ES front month & S&P 500 Spread Difference /// <returns></returns> public Premium Premium(Data.IDataSeries input, bool audioAlerts, double pTBuy, double pTSell) { if (cachePremium != null) for (int idx = 0; idx < cachePremium.Length; idx++) if (cachePremium[idx].AudioAlerts == audioAlerts && Math.Abs(cachePremium[idx].PTBuy - pTBuy) <= double.Epsilon && Math.Abs(cachePremium[idx].PTSell - pTSell) <= double.Epsilon && cachePremium[idx].EqualsInput(input)) return cachePremium[idx]; lock (checkPremium) { checkPremium.AudioAlerts = audioAlerts; audioAlerts = checkPremium.AudioAlerts; checkPremium.PTBuy = pTBuy; pTBuy = checkPremium.PTBuy; checkPremium.PTSell = pTSell; pTSell = checkPremium.PTSell; if (cachePremium != null) for (int idx = 0; idx < cachePremium.Length; idx++) if (cachePremium[idx].AudioAlerts == audioAlerts && Math.Abs(cachePremium[idx].PTBuy - pTBuy) <= double.Epsilon && Math.Abs(cachePremium[idx].PTSell - pTSell) <= double.Epsilon && cachePremium[idx].EqualsInput(input)) return cachePremium[idx]; Premium indicator = new Premium(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.AudioAlerts = audioAlerts; indicator.PTBuy = pTBuy; indicator.PTSell = pTSell; Indicators.Add(indicator); indicator.SetUp(); Premium[] tmp = new Premium[cachePremium == null ? 1 : cachePremium.Length + 1]; if (cachePremium != null) cachePremium.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cachePremium = tmp; return indicator; } } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { [Gui.Design.WizardCondition("Indicator")] public Indicator.Premium Premium(bool audioAlerts, double pTBuy, double pTSell) { return _indicator.Premium(Input, audioAlerts, pTBuy, pTSell); } public Indicator.Premium Premium(Data.IDataSeries input, bool audioAlerts, double pTBuy, double pTSell) { return _indicator.Premium(input, audioAlerts, pTBuy, pTSell); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { [Gui.Design.WizardCondition("Indicator")] public Indicator.Premium Premium(bool audioAlerts, double pTBuy, double pTSell) { return _indicator.Premium(Input, audioAlerts, pTBuy, pTSell); } public Indicator.Premium Premium(Data.IDataSeries input, bool audioAlerts, double pTBuy, double pTSell) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.Premium(input, audioAlerts, pTBuy, pTSell); } } } #endregion
Comment