Exemplo n.º 1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (Bars == null)
            {
                return;
            }

            if (!Bars.BarsType.IsIntraday)
            {
                DrawTextFixed("error msg", "ZZPriorDayOHLCAlerts only works on intraday intervals", TextPosition.BottomRight);
                return;
            }

            // If the current data is not the same date as the current bar then its a new session
            if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == 0)
            {
                // The current day OHLC values are now the prior days value so set
                // them to their respect indicator series for plotting
                if (currentOpen != 0)
                {
                    twodayagoHigh = priordayHigh;
                    twodayagoLow  = priordayLow;
                    priordayOpen  = currentOpen;
                    priordayHigh  = currentHigh;
                    priordayLow   = currentLow;
                    priordayClose = currentClose;

                    if (ShowOpen)
                    {
                        PriorOpen.Set(priordayOpen);
                    }
                    if (ShowHigh)
                    {
                        PriorHigh.Set(priordayHigh);
                    }
                    if (ShowLow)
                    {
                        PriorLow.Set(priordayLow);
                    }
                    if (ShowClose)
                    {
                        PriorClose.Set(priordayClose);
                    }
                }

                // Initilize the current day settings to the new days data
                currentOpen  = Open[0];
                currentHigh  = High[0];
                currentLow   = Low[0];
                currentClose = Close[0];

                currentDate = Bars.GetTradingDayFromLocal(Time[0]);
            }
            else             // The current day is the same day
            {
                // Set the current day OHLC values
                currentHigh  = Math.Max(currentHigh, High[0]);
                currentLow   = Math.Min(currentLow, Low[0]);
                currentClose = Close[0];

                // Alert if near HLC
                //Print("priordayHigh = " + priordayHigh + " range = " + (priordayHigh+priordayHigh*0.001) + "  " + (priordayHigh-priordayHigh*0.001) );
                //Print("priordayLow = " + priordayLow + " range = " + (priordayLow-priordayLow*0.001) + " " +(priordayLow+priordayLow*0.001) );
                if (currentClose > (priordayHigh - priordayHigh * 0.001) && currentClose < (priordayHigh + priordayHigh * 0.001))
                {
                    Alert("NearPriorHigh", NinjaTrader.Cbi.Priority.High, "Near prior high", "Alert2.wav", 10, Color.Black, Color.Yellow);
                }
                if (currentClose > (priordayLow - priordayLow * 0.001) && currentClose < (priordayLow + priordayLow * 0.001))
                {
                    Alert("NearPriorLow", NinjaTrader.Cbi.Priority.High, "Near prior low", "Alert2.wav", 10, Color.Black, Color.Yellow);
                }

                // Alert if near two days ago high or low
                if (currentClose > (twodayagoHigh - twodayagoHigh * 0.001) && currentClose < (twodayagoHigh + twodayagoHigh * 0.001))
                {
                    Alert("NearTwoDayAgoHigh", NinjaTrader.Cbi.Priority.High, "Near 2-day Ago high", "Alert2.wav", 10, Color.Black, Color.Yellow);
                }
                if (currentClose > (twodayagoLow - twodayagoLow * 0.001) && currentClose < (twodayagoLow + twodayagoLow * 0.001))
                {
                    Alert("NearTwoDayAgoLow", NinjaTrader.Cbi.Priority.High, "Near 2-day Ago low", "Alert2.wav", 10, Color.Black, Color.Yellow);
                }

                if (ShowOpen)
                {
                    PriorOpen.Set(priordayOpen);
                }
                if (ShowHigh)
                {
                    PriorHigh.Set(priordayHigh);
                }
                if (ShowLow)
                {
                    PriorLow.Set(priordayLow);
                }
                if (ShowClose)
                {
                    PriorClose.Set(priordayClose);
                }
            }
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (Bars == null)
            {
                return;
            }

            if (!Bars.BarsType.IsIntraday)
            {
                DrawTextFixed("error msg", "PriorDayOHLC only works on intraday intervals", TextPosition.BottomRight);
                return;
            }

            //MY PIECE OF CODE TO ONLY INCLUDE THE LINES FOR THE 5MIN CHART
            if (!((BarsPeriod.Id == PeriodType.Minute) && (BarsPeriod.Value == 5)))
            {
                return;
            }

            // If the current data is not the same date as the current bar then its a new session
            if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == 0)
            {
                // The current day OHLC values are now the prior days value so set
                // them to their respect indicator series for plotting
                if (currentOpen != 0)
                {
                    priordayOpen  = currentOpen;
                    priordayHigh  = currentHigh;
                    priordayLow   = currentLow;
                    priordayClose = currentClose;

                    if (ShowOpen)
                    {
                        PriorOpen.Set(priordayOpen);
                    }
                    if (ShowHigh)
                    {
                        PriorHigh.Set(priordayHigh);
                    }
                    if (ShowLow)
                    {
                        PriorLow.Set(priordayLow);
                    }
                    if (ShowClose)
                    {
                        PriorClose.Set(priordayClose);
                    }
                }

                // Initilize the current day settings to the new days data
                currentOpen  = Open[0];
                currentHigh  = High[0];
                currentLow   = Low[0];
                currentClose = Close[0];

                currentDate = Bars.GetTradingDayFromLocal(Time[0]);
            }
            else             // The current day is the same day
            {
                // Set the current day OHLC values
                currentHigh  = Math.Max(currentHigh, High[0]);
                currentLow   = Math.Min(currentLow, Low[0]);
                currentClose = Close[0];

                if (ShowOpen)
                {
                    PriorOpen.Set(priordayOpen);
                }
                if (ShowHigh)
                {
                    PriorHigh.Set(priordayHigh);
                }
                if (ShowLow)
                {
                    PriorLow.Set(priordayLow);
                }
                if (ShowClose)
                {
                    PriorClose.Set(priordayClose);
                }
            }
        }