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 WaveAtElliot, Today, 05:11 PM
                      1 response
                      7 views
                      1 like
                      Last Post hdge4u
                      by hdge4u
                       
                      Started by bosajin, Yesterday, 09:15 AM
                      5 responses
                      36 views
                      0 likes
                      Last Post NinjaTrader_Jim  
                      Started by Dolfan, Today, 12:24 PM
                      4 responses
                      23 views
                      0 likes
                      Last Post NinjaTrader_Jim  
                      Started by WeyldFalcon, Today, 11:09 AM
                      7 responses
                      26 views
                      0 likes
                      Last Post WeyldFalcon  
                      Started by DTSSTS, 08-10-2020, 09:48 AM
                      12 responses
                      67 views
                      0 likes
                      Last Post DTSSTS
                      by DTSSTS
                       
                      Working...
                      X