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

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 AveryFlynn, Today, 04:57 AM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Started by Max238, Today, 01:28 AM
                      4 responses
                      37 views
                      0 likes
                      Last Post Max238
                      by Max238
                       
                      Started by r68cervera, Today, 05:29 AM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by geddyisodin, Today, 05:20 AM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by timko, Today, 06:45 AM
                      2 responses
                      14 views
                      0 likes
                      Last Post NinjaTrader_ChristopherJ  
                      Working...
                      X