/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (!Bars.BarsType.IsIntraday) { DrawTextFixed("error msg", "CurrentDayOHL only works on intraday intervals", TextPosition.BottomRight); return; } bool sameDay = true; if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == double.MinValue) { currentOpen = Open[0]; currentHigh = High[0]; currentLow = Low[0]; sameDay = false; } currentHigh = Math.Max(currentHigh, High[0]); currentLow = Math.Min(currentLow, Low[0]); if (ShowOpen) { if (!PlotCurrentValue || !sameDay) { CurrentOpen.Set(currentOpen); } else { for (int idx = 0; idx < CurrentOpen.Count; idx++) { CurrentOpen.Set(idx, currentOpen); } } } if (ShowHigh) { if (!PlotCurrentValue || currentHigh != High[0]) { CurrentHigh.Set(currentHigh); } else { for (int idx = 0; idx < CurrentHigh.Count; idx++) { CurrentHigh.Set(idx, currentHigh); } } } if (ShowLow) { if (!PlotCurrentValue || currentLow != Low[0]) { CurrentLow.Set(currentLow); } else { for (int idx = 0; idx < CurrentLow.Count; idx++) { CurrentLow.Set(idx, currentLow); } } } currentDate = Bars.GetTradingDayFromLocal(Time[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", "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); } } }
/// <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() { //string kObj = "OnBarUpdate"; if (Bars == null) { return; } IBDataSeries ib30; IBDataSeries ib60; IBDataSeries ibEOD; #region IBPrior if (Bars.BarsSinceSession == 0) { recordIB30 = true; recordIBEOD = true; recordIB60 = true; ib30 = new IBDataSeries() { StartBarSinceSession = Bars.BarsSinceSession, TradeDate = Bars.GetTradingDayFromLocal(Time[0]).ToShortDateString(), PriorDayOpen = Bars.GetDayBar(1).Open, PriorDayHigh = Bars.GetDayBar(1).High, PriorDayLow = Bars.GetDayBar(1).Low, PriorDayClose = Bars.GetDayBar(1).Close, PriorVolume = Bars.GetDayBar(1).Volume, CurrDayOpen = Open[0], IBOpen = Open[0] }; ib60 = new IBDataSeries() { StartBarSinceSession = Bars.BarsSinceSession, TradeDate = Bars.GetTradingDayFromLocal(Time[0]).ToShortDateString(), PriorDayOpen = Bars.GetDayBar(1).Open, PriorDayHigh = Bars.GetDayBar(1).High, PriorDayLow = Bars.GetDayBar(1).Low, PriorDayClose = Bars.GetDayBar(1).Close, PriorVolume = Bars.GetDayBar(1).Volume, CurrDayOpen = Open[0], IBOpen = Open[0] }; ibEOD = new IBDataSeries() { StartBarSinceSession = Bars.BarsSinceSession, TradeDate = Bars.GetTradingDayFromLocal(Time[0]).ToShortDateString(), PriorDayOpen = Bars.GetDayBar(1).Open, PriorDayHigh = Bars.GetDayBar(1).High, PriorDayLow = Bars.GetDayBar(1).Low, PriorDayClose = Bars.GetDayBar(1).Close, PriorVolume = Bars.GetDayBar(1).Volume, CurrDayOpen = Open[0], IBOpen = Open[0] }; dIB30.Add(idxIB30, ib30); dIB60.Add(idxIB60, ib60); dIBEOD.Add(idxIBEOD, ibEOD); idxIB30++; idxIB60++; idxIBEOD++; //kLog(kObj, "PRIOR", String.Format(" {0} prior. O {2} H {3} L {4} C {5} V {6} R {7}", // ib.StartBarSinceSession, // ib.TradeDate, // ib.PriorDayOpen.ToString("0.00"), // ib.PriorDayHigh.ToString("0.00"), // ib.PriorDayLow.ToString("0.00"), // ib.PriorDayClose.ToString("0.00"), // ib.PriorVolume.ToString("0"), // (ib.PriorDayClose - ib.PriorDayOpen).ToString("0.00") // )); } #endregion #region IB30 if (ToTime(Time[0]) >= ib30Time && recordIB30 == true) { double ibHigh = 0; double ibLow = 9999; int emaCrossCount = 0; int ibBullCount = 0; int ibBearCount = 0; int ibDojiCount = 0; double ibVolume = 0; string name = "IB30"; for (int i = 0; i < Bars.BarsSinceSession; i++) { ibHigh = Math.Max(ibHigh, High[i]); ibLow = Math.Min(ibLow, Low[i]); ibVolume = ibVolume + Volume[i]; if (Close[i] - Open[i] > 0) { ibBullCount++; } else if (Close[i] - Open[i] < 0) { ibBearCount++; } else if (Close[i] - Open[i] == 0) { ibDojiCount++; } if ((CrossAbove(EMA(emaPrimaryPeriod), EMA(emaReferencePeriod), i)) || (CrossBelow(EMA(emaPrimaryPeriod), EMA(emaReferencePeriod), i))) { emaCrossCount++; } } if (dIB30.Count > 0) { dIB30[dIB30.Count - 1].IBClose = Close[0]; dIB30[dIB30.Count - 1].IBEndBar = Bars.BarsSinceSession; dIB30[dIB30.Count - 1].IBLow = ibLow; dIB30[dIB30.Count - 1].IBVolume = ibVolume; dIB30[dIB30.Count - 1].IBHigh = ibHigh; dIB30[dIB30.Count - 1].IBBullCount = ibBullCount; dIB30[dIB30.Count - 1].IBBearCount = ibBearCount; dIB30[dIB30.Count - 1].IBDojiCount = ibDojiCount; dIB30[dIB30.Count - 1].IBEmaPrimaryAtClose = EMA(emaPrimaryPeriod)[0]; dIB30[dIB30.Count - 1].IBEmaReferenceAtClose = EMA(emaReferencePeriod)[0]; dIB30[dIB30.Count - 1].IBEmaCrossCount = emaCrossCount; string insertIB30 = String.Format("Insert into algoIB values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}')", dIB30[dIB30.Count - 1].TradeDate.ToString() + "-" + name, dIB30[dIB30.Count - 1].TradeDate, name, dIB30[dIB30.Count - 1].IBOpen, dIB30[dIB30.Count - 1].IBHigh, dIB30[dIB30.Count - 1].IBLow, dIB30[dIB30.Count - 1].IBClose, dIB30[dIB30.Count - 1].IBVolume, dIB30[dIB30.Count - 1].StartBarSinceSession, dIB30[dIB30.Count - 1].IBEndBar, dIB30[dIB30.Count - 1].IBBullCount, dIB30[dIB30.Count - 1].IBBearCount, dIB30[dIB30.Count - 1].IBDojiCount, dIB30[dIB30.Count - 1].IBEmaCrossCount, dIB30[dIB30.Count - 1].IBEmaPrimaryAtClose.ToString("0.00"), dIB30[dIB30.Count - 1].IBEmaReferenceAtClose.ToString("0.00") ); Print(insertIB30); MySqlCommand insertIBQuery30 = new MySqlCommand(insertIB30, dbConn); insertIBQuery30.ExecuteNonQuery(); recordIB30 = false; // to prevent double prints } } #endregion #region IB60 if (ToTime(Time[0]) >= ib60Time && recordIB60 == true) { double ibHigh = 0; double ibLow = 9999; int emaCrossCount = 0; int ibBullCount = 0; int ibBearCount = 0; int ibDojiCount = 0; double ibVolume = 0; string name = "IB60"; for (int i = 0; i < Bars.BarsSinceSession; i++) { ibHigh = Math.Max(ibHigh, High[i]); ibLow = Math.Min(ibLow, Low[i]); ibVolume = ibVolume + Volume[i]; if (Close[i] - Open[i] > 0) { ibBullCount++; } else if (Close[i] - Open[i] < 0) { ibBearCount++; } else if (Close[i] - Open[i] == 0) { ibDojiCount++; } if ((CrossAbove(EMA(emaPrimaryPeriod), EMA(emaReferencePeriod), i)) || (CrossBelow(EMA(emaPrimaryPeriod), EMA(emaReferencePeriod), i))) { emaCrossCount++; } } if (dIB60.Count > 0) { dIB60[dIB60.Count - 1].IBClose = Close[0]; dIB60[dIB60.Count - 1].IBEndBar = Bars.BarsSinceSession; dIB60[dIB60.Count - 1].IBLow = ibLow; dIB60[dIB60.Count - 1].IBVolume = ibVolume; dIB60[dIB60.Count - 1].IBHigh = ibHigh; dIB60[dIB60.Count - 1].IBBullCount = ibBullCount; dIB60[dIB60.Count - 1].IBBearCount = ibBearCount; dIB60[dIB60.Count - 1].IBDojiCount = ibDojiCount; dIB60[dIB60.Count - 1].IBEmaPrimaryAtClose = EMA(emaPrimaryPeriod)[0]; dIB60[dIB60.Count - 1].IBEmaReferenceAtClose = EMA(emaReferencePeriod)[0]; dIB60[dIB60.Count - 1].IBEmaCrossCount = emaCrossCount; string insertIB60 = String.Format("Insert into algoIB values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}')", dIB60[dIB60.Count - 1].TradeDate.ToString() + "-" + name, dIB60[dIB60.Count - 1].TradeDate, name, dIB60[dIB60.Count - 1].IBOpen, dIB60[dIB60.Count - 1].IBHigh, dIB60[dIB60.Count - 1].IBLow, dIB60[dIB60.Count - 1].IBClose, dIB60[dIB60.Count - 1].IBVolume, dIB60[dIB60.Count - 1].StartBarSinceSession, dIB60[dIB60.Count - 1].IBEndBar, dIB60[dIB60.Count - 1].IBBullCount, dIB60[dIB60.Count - 1].IBBearCount, dIB60[dIB60.Count - 1].IBDojiCount, dIB60[dIB60.Count - 1].IBEmaCrossCount, dIB60[dIB60.Count - 1].IBEmaPrimaryAtClose.ToString("0.00"), dIB60[dIB60.Count - 1].IBEmaReferenceAtClose.ToString("0.00") ); Print(insertIB60); try { MySqlCommand insertIBQuery60 = new MySqlCommand(insertIB60, dbConn); insertIBQuery60.ExecuteNonQuery(); } catch (Exception ex) { Print(ex.ToString()); } recordIB60 = false; // to prevent double prints } } #endregion #region IBEOD if (ToTime(Time[0]) >= ibEndTime && recordIBEOD == true) { double ibHigh = 0; double ibLow = 9999; int emaCrossCount = 0; int ibBullCount = 0; int ibBearCount = 0; int ibDojiCount = 0; double ibVolume = 0; string name = "IBEOD"; for (int i = 0; i < Bars.BarsSinceSession; i++) { ibHigh = Math.Max(ibHigh, High[i]); ibLow = Math.Min(ibLow, Low[i]); ibVolume = ibVolume + Volume[i]; if (Close[i] - Open[i] > 0) { ibBullCount++; } else if (Close[i] - Open[i] < 0) { ibBearCount++; } else if (Close[i] - Open[i] == 0) { ibDojiCount++; } if ((CrossAbove(EMA(emaPrimaryPeriod), EMA(emaReferencePeriod), i)) || (CrossBelow(EMA(emaPrimaryPeriod), EMA(emaReferencePeriod), i))) { emaCrossCount++; } } if (dIBEOD.Count > 0) { dIBEOD[dIBEOD.Count - 1].IBClose = Close[0]; dIBEOD[dIBEOD.Count - 1].IBEndBar = Bars.BarsSinceSession; dIBEOD[dIBEOD.Count - 1].IBLow = ibLow; dIBEOD[dIBEOD.Count - 1].IBVolume = ibVolume; dIBEOD[dIBEOD.Count - 1].IBHigh = ibHigh; dIBEOD[dIBEOD.Count - 1].IBBullCount = ibBullCount; dIBEOD[dIBEOD.Count - 1].IBBearCount = ibBearCount; dIBEOD[dIBEOD.Count - 1].IBDojiCount = ibDojiCount; dIBEOD[dIBEOD.Count - 1].IBEmaPrimaryAtClose = EMA(emaPrimaryPeriod)[0]; dIBEOD[dIBEOD.Count - 1].IBEmaReferenceAtClose = EMA(emaReferencePeriod)[0]; dIBEOD[dIBEOD.Count - 1].IBEmaCrossCount = emaCrossCount; string insertIBEOD = String.Format("Insert into algoIB values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}')", dIBEOD[dIBEOD.Count - 1].TradeDate.ToString() + "-" + name, dIBEOD[dIBEOD.Count - 1].TradeDate, name, dIBEOD[dIBEOD.Count - 1].IBOpen, dIBEOD[dIBEOD.Count - 1].IBHigh, dIBEOD[dIBEOD.Count - 1].IBLow, dIBEOD[dIBEOD.Count - 1].IBClose, dIBEOD[dIBEOD.Count - 1].IBVolume, dIBEOD[dIBEOD.Count - 1].StartBarSinceSession, dIBEOD[dIBEOD.Count - 1].IBEndBar, dIBEOD[dIBEOD.Count - 1].IBBullCount, dIBEOD[dIBEOD.Count - 1].IBBearCount, dIBEOD[dIBEOD.Count - 1].IBDojiCount, dIBEOD[dIBEOD.Count - 1].IBEmaCrossCount, dIBEOD[dIBEOD.Count - 1].IBEmaPrimaryAtClose.ToString("0.00"), dIBEOD[dIBEOD.Count - 1].IBEmaReferenceAtClose.ToString("0.00") ); Print(insertIBEOD); MySqlCommand insertIBQuery = new MySqlCommand(insertIBEOD, dbConn); insertIBQuery.ExecuteNonQuery(); recordIBEOD = false; // to prevent double prints } } #endregion }