Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ToTime() not returning seconds.

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

    ToTime() not returning seconds.

    I've been working on a real time strategy that needs the time of each incoming tick down to the seconds on a 1 minute chart. The problem is my output looks like this

    Code:
    3/24/2015 1:02:00 AM 3/24/2015 1:02:00 AM, 0
    
    3/24/2015 1:02:00 AM 3/24/2015 1:02:00 AM, 0
    
    3/24/2015 1:03:00 AM 3/24/2015 1:03:00 AM, 0
    
    3/24/2015 1:03:00 AM 3/24/2015 1:03:00 AM, 0
    
    3/24/2015 1:03:00 AM 3/24/2015 1:03:00 AM, 0
    The code I use for this example is

    Code:
    PrintWithTimeStamp(", " + exitTime);
    Exit time being my change to this time but it never works because the seconds are not calculated.

    Any help would be useful, even just figuring out why I'm not getting seconds.

    #2
    Hello magnatauren,

    Thank you for your post.

    Please try Print(Time[0]);.

    Comment


      #3
      I changed it to see my error and I understand where I'm wrong on that part, but it still returns as

      11600
      11600
      11700
      11700
      I'm missing the seconds which are the most important to this specific strategy

      Comment


        #4
        Hello magnatauren,

        Can you provide what formatting you are doing?

        Comment


          #5
          I need the time in seconds so that I can exit the trade [hours + minutes + seconds] later

          Code:
          			addedTime = (hour * hours) + (minute * minutes) + (second * seconds);
          Code:
                      // Condition set 1
                      if (DivergenceLiveTestIndic(14, "Alert1.wav", Color.DarkMagenta, DashStyle.Solid, 3, 14, 5, 3, 9, "Alert2.wav", 0, 1, Color.Cyan, 12, 26, 9, 5, "Alert1.wav", D3SpotIndicatorMethod.RSI, 14, 14, 0, D3SpotPriceType.Open_Close, 14, rSIPeriod, 3, 14, lookBackMax, false, 25, lookBackMin, 13, 25, 7, 14, 3, 3, 14, 14, Color.Yellow, true).LongShort[0] == -1
          				&& RSI(rSIPeriod, 5)[LowestBar(RSI(rSIPeriod, 5), lookBackMax)] < (100 - overBought))
                      {
                          EnterLong(DefaultQuantity, "");
          
          				if(ToTime(Time[0]) + addedTime > 240000)
          					exitTime = ToTime(Time[0]) + addedTime;
          				else
          					exitTime = ((ToTime(Time[0]) - 240000) + addedTime);
                      }
          
                      // Condition set 2
                      if (DivergenceLiveTestIndic(14, "Alert1.wav", Color.DarkMagenta, DashStyle.Solid, 3, 14, 5, 3, 9, "Alert2.wav", 0, 1, Color.Cyan, 12, 26, 9, 5, "Alert1.wav", D3SpotIndicatorMethod.RSI, 14, 14, 0, D3SpotPriceType.Open_Close, 14, rSIPeriod, 3, 14, lookBackMax, false, 25, lookBackMin, 13, 25, 7, 14, 3, 3, 14, 14, Color.Yellow, true).LongShort[0] == 1
          				&& RSI(rSIPeriod, 5)[HighestBar(RSI(rSIPeriod, 5), lookBackMax)] > overBought)
                      {
                          EnterShort(DefaultQuantity, "");
          				
          				if(ToTime(Time[0]) + addedTime > 240000)
          					exitTime = ToTime(Time[0]) + addedTime;
          				else
          					exitTime = ((ToTime(Time[0]) - 240000) + addedTime);
                      }
          			
          			#endregion
          			
          			Print(Time[0]);
          This returns as

          3/24/2015 1:23:00 AM
          3/24/2015 1:23:00 AM
          3/24/2015 1:23:00 AM
          3/24/2015 1:24:00 AM
          3/24/2015 1:24:00 AM
          I need the seconds so that i know exactly when to execute the next bit of code.

          Comment


            #6
            I just set the time to 60 Seconds to see if that would have an impact and it did not.
            a 1 second chart on the other hand returns the seconds like I'm looking for but I don't know how i would run this on 1 second charts.

            Comment


              #7
              I've tried using a multi-timeframe but I'm not sure I know how I would be able to make one indicator work for one timeframe but get the ticks from the other.

              Comment


                #8
                Hello magnatauren,

                Thank you for your patience.

                I should have caught this earlier, but this is expected with the timestamps of the Minute bars. So you solution of an added bar series would be the recommended solution here. You can add a 1 Tick bar series for example and call it's timestamp with Times[1][0]: http://www.ninjatrader.com/support/h.../nt7/times.htm

                Comment


                  #9
                  Thank you Patrick, I actually found this solution last night and it was what i needed to solve my problem.

                  Just for reference, Times[0][0] is the current time on the default input and Times[1][0] is the current timestamp on the first ADDED input, and Times[2][0] and so on?

                  Comment


                    #10
                    Hello magnatauren,

                    Just for reference, Times[0][0] is the current time on the default input and Times[1][0] is the current timestamp on the first ADDED input, and Times[2][0] and so on?
                    Correct.

                    Comment


                      #11
                      Thank you, looks like I'll be able to finish this.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      571 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      330 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      101 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      548 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      549 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X