Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

a question about time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    a question about time

    a question about time, how to import time from trading hours correctly, or how to convert time to the desired time by zone using the code

    Code:
    if(ToTime(Time[0]) == 063000)
    {
    CloseTime = Close[0];
    }

    in this code the time is my local of my pc

    How can I make the condition fulfillment time in a different zone and not my pc? how to convert time what systaxis? thank you in advance

    #2
    Hello memonolog,

    You can use general C# like the TimeZoneInfo.ConvertTime() to convert a DateTime object from your local PC time to another time zone.

    Below is a publicly available link to the Microsoft documentation.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello memonolog,

      You can use general C# like the TimeZoneInfo.ConvertTime() to convert a DateTime object from your local PC time to another time zone.

      Below is a publicly available link to the Microsoft documentation.
      https://docs.microsoft.com/en-us/dot...e?view=net-5.0
      I'm trying to convert time from example, I don't understand what's wrong

      Code:
      private DateTime startDateTime;
      private DateTime endDateTime;
      protected override void OnBarUpdate()
      {
      // Check to make sure the end time is not earlier than the start time
      if (EndHour < StartHour)
      return;
      
      
      //Do not calculate the high or low value when the ending time of the desired range is less than the current time of the bar being processed
      if (ToTime(EndHour,EndMinute,0) > ToTime(Time[0]))
      return;
      
      [B]DateTime ExchangeDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Time[0], ("Eastern Standard Time"));[/B]
      
      
      // If the stored date time date is not the same date as the bar time date, create a new DateTime object
      if (startDateTime.Date != Time[0].Date)
      {
      startDateTime = new DateTime([B]ExchangeDateTime[/B].Year, [B]ExchangeDateTime[/B].Month, [B]ExchangeDateTime[/B].Day, StartHour, StartMinute, 0);
      endDateTime = new DateTime([B]ExchangeDateTime[/B].Year, [B]ExchangeDateTime[/B].Month, [B]ExchangeDateTime[/B].Day, .EndHour, EndMinute, 0);
      }
      
      // Calculate the number of bars ago for the start and end bars of the specified time range
      int startBarsAgo = Bars.GetBar(startDateTime);
      int endBarsAgo = Bars.GetBar(endDateTime);
      
      /* Now that we have the start and end bars ago values for the specified time range we can calculate the highest high for this range
      
      Note: We add 1 to the period range for MAX and MIN to compensate for the difference between "period" logic and "bars ago" logic.
      "Period" logic means exactly how many bars you want to check including the current bar.
      "Bars ago" logic means how many bars we are going to go backwards. The current bar is not counted because on that bar we aren't going back any bars so it would be "bars ago = 0" */
      double highestHigh = MAX(High, endBarsAgo - startBarsAgo + 1)[CurrentBar - endBarsAgo];
      
      // Now that we have the start and end bars ago values for the specified time range we can calculate the lowest low for this range
      double lowestLow = MIN(Low, endBarsAgo - startBarsAgo + 1)[CurrentBar - endBarsAgo];
      
      // Set the plot values
      HighestHigh[0] = highestHigh;
      LowestLow[0] = lowestLow;
      }
      Last edited by memonolog; 03-06-2021, 08:01 AM.

      Comment


        #4
        the task is to indicate the work of the indicator in full time regardless of the local time

        something like

        // TIME US
        DateTime ExchangeDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Time[0], ("Eastern Standard Time"));

        if (ToTime(ExchangeDateTime) == 093000)
        {
        if (IsFirstTickOfBar)
        {
        OpenRTH = Close[0];
        }
        }

        Comment


          #5
          Hello memonolog,

          I'm not certain that I understand. NinjaTrader already converts all data to your local time zone.

          You are trying to convert to a specific time zone that does not match the local time zone?

          When you mention something is wrong, are you seeing error? Is the time zone not being converted?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello memonolog,

            I'm not certain that I understand. NinjaTrader already converts all data to your local time zone.

            You are trying to convert to a specific time zone that does not match the local time zone?

            When you mention something is wrong, are you seeing error? Is the time zone not being converted?
            I want to convert the local time of my PC during the exchange by the exchange time zone, and run the start time of the indicator calculation by the exchange time and not the local time

            Comment


              #7
              Hello memonolog,

              Are you printing ExchangeDateTime and this is not printing the time of the bar in Eastern Time?

              Print(string.Format("Time[0]: {0}, ExchangeDateTime: {1}", Time[0], ExchangeDateTime));
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by adeelshahzad, Today, 03:54 AM
              4 responses
              22 views
              0 likes
              Last Post adeelshahzad  
              Started by merzo, 06-25-2023, 02:19 AM
              10 responses
              823 views
              1 like
              Last Post NinjaTrader_ChristopherJ  
              Started by frankthearm, Today, 09:08 AM
              5 responses
              15 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              43 views
              0 likes
              Last Post jeronymite  
              Started by yertle, Today, 08:38 AM
              5 responses
              16 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X