Exemple #1
0
        private DateTime GetLastBarSessionDate(DateTime time, PivotRange pivotRange)
        {
            // Check the time[0] against the previous session end
            if (time > cacheSessionEnd)
            {
                if (Bars.BarsType.IsIntraday)
                {
                    // Make use of the stored session iterator to find the next session...
                    storedSession.GetNextSession(time, true);
                    // Store the actual session's end datetime as the session
                    cacheSessionEnd = storedSession.ActualSessionEnd;
                    // We need to convert that time from the session to the users time zone settings
                    sessionDateTmp = TimeZoneInfo.ConvertTime(cacheSessionEnd.AddSeconds(-1), Globals.GeneralOptions.TimeZoneInfo, Bars.TradingHours.TimeZoneInfo).Date;
                }
                else
                {
                    sessionDateTmp = time.Date;
                }
            }

            if (pivotRange == PivotRange.Daily)
            {
                if (sessionDateTmp != cacheSessionDate)
                {
                    if (newSessionBarIdxArr.Count == 0 || newSessionBarIdxArr.Count > 0 && CurrentBar > newSessionBarIdxArr[newSessionBarIdxArr.Count - 1])
                    {
                        newSessionBarIdxArr.Add(CurrentBar);
                    }
                    cacheSessionDate = sessionDateTmp;
                }
                return(sessionDateTmp);
            }

            DateTime tmpWeeklyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Weekly);

            if (pivotRange == PivotRange.Weekly)
            {
                if (tmpWeeklyEndDate != cacheWeeklyEndDate)
                {
                    if (newSessionBarIdxArr.Count == 0 || newSessionBarIdxArr.Count > 0 && CurrentBar > newSessionBarIdxArr[newSessionBarIdxArr.Count - 1])
                    {
                        newSessionBarIdxArr.Add(CurrentBar);
                    }
                    cacheWeeklyEndDate = tmpWeeklyEndDate;
                }
                return(tmpWeeklyEndDate);
            }

            DateTime tmpMonthlyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Monthly);

            if (tmpMonthlyEndDate != cacheMonthlyEndDate)
            {
                if (newSessionBarIdxArr.Count == 0 || newSessionBarIdxArr.Count > 0 && CurrentBar > newSessionBarIdxArr[newSessionBarIdxArr.Count - 1])
                {
                    newSessionBarIdxArr.Add(CurrentBar);
                }
                cacheMonthlyEndDate = tmpMonthlyEndDate;
            }
            return(tmpMonthlyEndDate);
        }
        private DateTime GetLastBarSessionDate(DateTime time, Data.Bars bars, PivotRange pivotRange)
        {
            if (time > cacheSessionEnd)
            {
                if (Bars.BarsType.IsIntraday)
                {
                    Bars.Session.GetNextBeginEnd(time, out cacheSessionBegin, out cacheSessionEnd);
                    sessionDateTmp = System.TimeZoneInfo.ConvertTime(cacheSessionEnd.AddSeconds(-1), System.TimeZoneInfo.Local, Bars.Session.TimeZoneInfo).Date;
                }
                else
                {
                    sessionDateTmp = time.Date;
                }
            }

            if (pivotRange == PivotRange.Daily)
            {
                if (sessionDateTmp != cacheSessionDate)
                {
                    if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBar > (int)newSessionBarIdxArr[newSessionBarIdxArr.Count - 1]))
                    {
                        newSessionBarIdxArr.Add(CurrentBar);
                    }
                    cacheSessionDate = sessionDateTmp;
                }
                return(sessionDateTmp);
            }
            else if (pivotRange == PivotRange.Weekly)
            {
                DateTime tmpWeeklyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Weekly);
                if (tmpWeeklyEndDate != cacheWeeklyEndDate)
                {
                    if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBar > (int)newSessionBarIdxArr[newSessionBarIdxArr.Count - 1]))
                    {
                        newSessionBarIdxArr.Add(CurrentBar);
                    }
                    cacheWeeklyEndDate = tmpWeeklyEndDate;
                }
                return(tmpWeeklyEndDate);
            }
            else             // pivotRange == PivotRange.Monthly
            {
                DateTime tmpMonthlyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Monthly);
                if (tmpMonthlyEndDate != cacheMonthlyEndDate)
                {
                    if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBar > (int)newSessionBarIdxArr[newSessionBarIdxArr.Count - 1]))
                    {
                        newSessionBarIdxArr.Add(CurrentBar);
                    }
                    cacheMonthlyEndDate = tmpMonthlyEndDate;
                }
                return(tmpMonthlyEndDate);
            }
        }
 private DateTime RoundUpTimeToPeriodTime(DateTime time, PivotRange pivotRange)
 {
     if (pivotRange == PivotRange.Weekly)
     {
         return(Gui.Tools.Extensions.GetEndOfWeekTime(time));
     }
     if (pivotRange == PivotRange.Monthly)
     {
         return(Gui.Tools.Extensions.GetEndOfMonthTime(time));
     }
     return(time);
 }
Exemple #4
0
 private DateTime RoundUpTimeToPeriodTime(DateTime time, PivotRange pivotRange)
 {
     if (pivotRange == PivotRange.Weekly)
     {
         DateTime periodStart = time.AddDays((6 - (((int)time.DayOfWeek) + 1) % 7));
         return(periodStart.Date.AddDays(Math.Ceiling(Math.Ceiling(time.Date.Subtract(periodStart.Date).TotalDays) / 7) * 7).Date);
     }
     if (pivotRange == PivotRange.Monthly)
     {
         var result = new DateTime(time.Year, time.Month, 1);
         return(result.AddMonths(1).AddDays(-1));
     }
     return(time);
 }
Exemple #5
0
 public Pivots Pivots(ISeries <double> input, PivotRange pivotRangeType, HLCCalculationMode priorDayHlc, double userDefinedClose, double userDefinedHigh, double userDefinedLow, int width)
 {
     if (cachePivots != null)
     {
         for (int idx = 0; idx < cachePivots.Length; idx++)
         {
             if (cachePivots[idx] != null && cachePivots[idx].PivotRangeType == pivotRangeType && cachePivots[idx].PriorDayHlc == priorDayHlc && cachePivots[idx].UserDefinedClose == userDefinedClose && cachePivots[idx].UserDefinedHigh == userDefinedHigh && cachePivots[idx].UserDefinedLow == userDefinedLow && cachePivots[idx].Width == width && cachePivots[idx].EqualsInput(input))
             {
                 return(cachePivots[idx]);
             }
         }
     }
     return(CacheIndicator <Pivots>(new Pivots()
     {
         PivotRangeType = pivotRangeType, PriorDayHlc = priorDayHlc, UserDefinedClose = userDefinedClose, UserDefinedHigh = userDefinedHigh, UserDefinedLow = userDefinedLow, Width = width
     }, input, ref cachePivots));
 }
Exemple #6
0
 public Indicators.Pivots Pivots(ISeries <double> input, PivotRange pivotRangeType, HLCCalculationMode priorDayHlc, double userDefinedClose, double userDefinedHigh, double userDefinedLow, int width)
 {
     return(indicator.Pivots(input, pivotRangeType, priorDayHlc, userDefinedClose, userDefinedHigh, userDefinedLow, width));
 }
Exemple #7
0
 public Pivots Pivots(PivotRange pivotRangeType, HLCCalculationMode priorDayHlc, double userDefinedClose, double userDefinedHigh, double userDefinedLow, int width)
 {
     return(Pivots(Input, pivotRangeType, priorDayHlc, userDefinedClose, userDefinedHigh, userDefinedLow, width));
 }
Exemple #8
0
 public Indicators.FibonacciPivots FibonacciPivots(PivotRange pivotRangeType, HLCCalculationMode priorDayHlc, double userDefinedClose, double userDefinedHigh, double userDefinedLow, int width)
 {
     return(indicator.FibonacciPivots(Input, pivotRangeType, priorDayHlc, userDefinedClose, userDefinedHigh, userDefinedLow, width));
 }
		private DateTime RoundUpTimeToPeriodTime(DateTime time, PivotRange pivotRange)
		{
			if (pivotRange == PivotRange.Weekly)
			{
				DateTime periodStart = time.AddDays((6 - (((int) time.DayOfWeek) + 1) % 7));
				return periodStart.Date.AddDays(System.Math.Ceiling(System.Math.Ceiling(time.Date.Subtract(periodStart.Date).TotalDays) / 7) * 7).Date;
			}
			else if (pivotRange == PivotRange.Monthly)
			{
				DateTime result = new DateTime(time.Year, time.Month, 1); 
				return result.AddMonths(1).AddDays(-1);
			}
			else
				return time;
		}
		private DateTime GetLastBarSessionDate(DateTime time, Data.Bars bars, int barsAgo, PivotRange pivotRange)
		{
			if (pivotRange == PivotRange.Daily && time > cacheSessionEndTmp1)
			{
				isEndOfMonthHoliday = false;
				if (Bars.BarsType.IsIntraday)
					sessionDateTmp = Bars.GetTradingDayFromLocal(time);
				else
					sessionDateTmp = time.Date;
				for (int i =0; i<3; i++)
				{
					if (publicHoliday[i].Date == sessionDateTmp)
						isEndOfMonthHoliday = true;
				}
				if(cacheSessionDate != sessionDateTmp) 
					cacheSessionDate = sessionDateTmp;
				Bars.Session.GetNextBeginEnd(bars, barsAgo, out cacheSessionBeginTmp, out cacheSessionEndTmp1);
				if(tickBuilt)
					cacheSessionEndTmp1 = cacheSessionEndTmp1.AddSeconds(-1);
			}
			else if (pivotRange == PivotRange.Monthly && time > cacheSessionEndTmp3) 
			{
				extendPublicHoliday = false;
				for (int i =0; i<3; i++)
				{
					if (publicHoliday[i].Date == sessionDateTmp)
						extendPublicHoliday = true;
				}
				if (Bars.BarsType.IsIntraday)
					sessionDateTmp = Bars.GetTradingDayFromLocal(time);
				else
					sessionDateTmp = time.Date;
				DateTime tmpMonthlyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Monthly);
				if(extendPublicHoliday)
					tmpMonthlyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp.AddDays(1), PivotRange.Monthly);
				if (tmpMonthlyEndDate != cacheMonthlyEndDate)
				{
					cacheMonthlyEndDate = tmpMonthlyEndDate;
					if (newSessionBarIdxArr3.Count == 0 || (newSessionBarIdxArr3.Count > 0 && CurrentBar > (int) newSessionBarIdxArr3[newSessionBarIdxArr3.Count - 1]))
						newSessionBarIdxArr3.Add(CurrentBar);
				}
				Bars.Session.GetNextBeginEnd(bars, barsAgo, out cacheSessionBeginTmp, out cacheSessionEndTmp3);
				if(tickBuilt)
					cacheSessionEndTmp3 = cacheSessionEndTmp3.AddSeconds(-1);
			}
			if (pivotRange == PivotRange.Daily)
				return sessionDateTmp;		
			else 
				return RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Monthly);
		}
Exemple #11
0
		private DateTime GetLastBarSessionDate(DateTime time, Data.Bars bars, PivotRange pivotRange)
		{
			if (time > cacheSessionEnd)
			{
				if (Bars.BarsType.IsIntraday)
				{
					Bars.Session.GetNextBeginEnd(time, out cacheSessionBegin, out cacheSessionEnd);
					sessionDateTmp = System.TimeZoneInfo.ConvertTime(cacheSessionEnd.AddSeconds(-1), System.TimeZoneInfo.Local, Bars.Session.TimeZoneInfo).Date;
				}
				else
					sessionDateTmp = time.Date;
			}	
			
			if (pivotRange == PivotRange.Daily)
			{	
				if(sessionDateTmp != cacheSessionDate)
				{
					if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBar > (int) newSessionBarIdxArr[newSessionBarIdxArr.Count - 1]))
						newSessionBarIdxArr.Add(CurrentBar);
					cacheSessionDate = sessionDateTmp;
				}
				return sessionDateTmp;
			}
			else if (pivotRange == PivotRange.Weekly) 
			{
				DateTime tmpWeeklyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Weekly);
				if (tmpWeeklyEndDate != cacheWeeklyEndDate)
				{
					if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBar > (int) newSessionBarIdxArr[newSessionBarIdxArr.Count - 1]))
						newSessionBarIdxArr.Add(CurrentBar);
					cacheWeeklyEndDate = tmpWeeklyEndDate;
				}
				return tmpWeeklyEndDate;
			}
			else // pivotRange == PivotRange.Monthly
			{
				DateTime tmpMonthlyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Monthly);
				if (tmpMonthlyEndDate != cacheMonthlyEndDate)
				{
					if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBar > (int) newSessionBarIdxArr[newSessionBarIdxArr.Count - 1]))
						newSessionBarIdxArr.Add(CurrentBar);
					cacheMonthlyEndDate = tmpMonthlyEndDate;
				}
				return tmpMonthlyEndDate;
			}
		}
		private DateTime GetLastBarSessionDate(DateTime time, Data.Bars bars, int barsAgo, PivotRange pivotRange)
		{
			if (time > cacheSessionEndTmp)
			{	
				extendPublicHoliday = false;
				for (int i =0; i<42; i++)
				{
					if (publicHoliday[i].Date == sessionDateTmp)
						extendPublicHoliday = true;
				}
				if (Bars.BarsType.IsIntraday)
					sessionDateTmp = Bars.GetTradingDayFromLocal(time);
				else
					sessionDateTmp = time.Date;
				if(cacheSessionDate != sessionDateTmp) 
				{
					cacheSessionDate = sessionDateTmp;
					if (!extendPublicHoliday && (newSessionBarIdxArr1.Count == 0 
						|| (newSessionBarIdxArr1.Count > 0 && CurrentBar > (int) newSessionBarIdxArr1[newSessionBarIdxArr1.Count - 1])))
							newSessionBarIdxArr1.Add(CurrentBar);
				}
				Bars.Session.GetNextBeginEnd(bars, barsAgo, out cacheSessionBeginTmp, out cacheSessionEndTmp);
				if(tickBuilt)
					cacheSessionEndTmp = cacheSessionEndTmp.AddSeconds(-1);
			}
			return sessionDateTmp;
		}
		private DateTime GetLastBarSessionDate(DateTime time, Data.Bars bars, int barsAgo, PivotRange pivotRange)
		{
			if (pivotRange == PivotRange.Daily && time > cacheSessionEndTmp1)
			{
				isEndOfWeekHoliday = false;
				if (Bars.BarsType.IsIntraday)
					sessionDateTmp = Bars.GetTradingDayFromLocal(time);
				else
					sessionDateTmp = time.Date;
				for (int i =0; i<4; i++)
				{
					if (publicHoliday[i].Date == sessionDateTmp)
						isEndOfWeekHoliday = true;
				}
				if(cacheSessionDate != sessionDateTmp) 
					cacheSessionDate = sessionDateTmp;
				Bars.Session.GetNextBeginEnd(bars, barsAgo, out cacheSessionBeginTmp, out cacheSessionEndTmp1);
				if(tickBuilt)
					cacheSessionEndTmp1 = cacheSessionEndTmp1.AddSeconds(-1);
			}
			else if (pivotRange == PivotRange.Weekly && time > cacheSessionEndTmp2) 
			{
				extendPublicHoliday = false;
				for (int i =0; i<4; i++)
				{
					if (publicHoliday[i].Date == sessionDateTmp)
						extendPublicHoliday = true;
				}
				if (Bars.BarsType.IsIntraday)
					sessionDateTmp = Bars.GetTradingDayFromLocal(time);
				else
					sessionDateTmp = time.Date;
				DateTime tmpWeeklyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Weekly);
				if(extendPublicHoliday)
					tmpWeeklyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp.AddDays(1), PivotRange.Weekly);
				if (tmpWeeklyEndDate != cacheWeeklyEndDate || (rthOHL && firstDayOfPeriod && sessionCount == 1 && activeSession == anaSessionCountCW43.Second)
					|| (rthOHL && firstDayOfPeriod && sessionCount ==2 && activeSession == anaSessionCountCW43.Third)) 
				{
					cacheWeeklyEndDate = tmpWeeklyEndDate;
					if (newSessionBarIdxArr2.Count == 0 || (newSessionBarIdxArr2.Count > 0 && CurrentBar > (int) newSessionBarIdxArr2[newSessionBarIdxArr2.Count - 1]))
						newSessionBarIdxArr2.Add(CurrentBar);
				}
				Bars.Session.GetNextBeginEnd(bars, barsAgo, out cacheSessionBeginTmp, out cacheSessionEndTmp2);
				if(tickBuilt)
					cacheSessionEndTmp2 = cacheSessionEndTmp2.AddSeconds(-1);
			}	
			if (pivotRange == PivotRange.Daily)
				return sessionDateTmp;
			else	
				return RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Weekly);
		}