DB,Error on executing DB command: System.ArgumentException: The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example when the Kind property is DateTimeKind.Local the source time zone must be TimeZoneInfo.Local. Parameter name: sourceTimeZone at System.TimeZoneInfo.ConvertTime(DateTime dateTime TimeZoneInfo sourceTimeZone TimeZoneInfo destinationTimeZone TimeZoneInfoOptions flags CachedData cachedData) at NinjaTrader.Cbi.Order.DbAdd() at NinjaTrader.Cbi.DB.DBThread(),
In this segment of code- the only component of time, I manage around the margin windows. But i'm getting this error and I'm not sure how it needs to be resolved?
if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Future) { // Define variables for central time start and end bands in CT (3:45 - 4:00pm) but go a little earlier // Define the time zones for Central Time (CT) and Pacific Time (PT) TimeZoneInfo centralTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); TimeZoneInfo pacificTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); // Get the current date and time in Central Time (CT) DateTime currentDateTimeCT = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, centralTimeZone); // Calculate the current date and time in Pacific Time (PT) DateTime currentDateTimePT = TimeZoneInfo.ConvertTime(currentDateTimeCT, pacificTimeZone); // Combine the current date and time in Pacific Time (PT) with the specified times DateTime centralTimeStartPT = currentDateTimePT.Date.Add(centralTimeStartCT); DateTime centralTimeEndPT = currentDateTimePT.Date.Add(centralTimeEndCT); DateTime today5PMPT = currentDateTimePT.Date.Add(centralTime5PMCT); // Check if the current time falls within the trading hours in Pacific Time (PT) if (currentDateTimePT >= centralTimeStartPT && currentDateTimePT <= centralTimeEndPT && Position.MarketPosition == MarketPosition.Flat) { BackBrush = Brushes.DarkSlateBlue; return; } // If not flat, exit and end if (currentDateTimePT >= centralTimeStartPT && currentDateTimePT <= centralTimeEndPT && Position.MarketPosition != MarketPosition.Flat) { double initMargin = Account.Get(AccountItem.InitialMargin, Currency.UsDollar); double netLiq = Account.Get(AccountItem.NetLiquidation, Currency.UsDollar); if (Position.MarketPosition == MarketPosition.Long) { // ExitLong(); DateTime resultDateTime = DateTime.Now.Add(today5PMPT.TimeOfDay); CancelOrders(OrderState.Filled, 0, resultDateTime, false); BackBrush = Brushes.SlateGray; return; } else if (Position.MarketPosition == MarketPosition.Short) { // ExitShort(); DateTime resultDateTime = DateTime.Now.Add(today5PMPT.TimeOfDay); CancelOrders(OrderState.Filled, 0, resultDateTime, false); BackBrush = Brushes.SlateGray; return; } } }
Comment