Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does " ToTime(Time[0]) "still work properly?

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

    Does " ToTime(Time[0]) "still work properly?

    I want a little delay in code execution, so I added these very simple lines:

    Code:
    if ( Historical || (ToTime(Time[0]) >= 180000 && ToTime(Time[0]) <= 180010) )
                return;
    But between 18:00:00 and 18:00:10 the code doesn't execute the "return" as it should be, the Algo simply ignores that condition. Any ideas? In the past, I've never had problems with ToTime(Time[0] .

    Thanks

    #2
    Hi pstrusi, Thanks for your post.

    What time frame are you running this script on? Remember that a bar timestamp will only be as resolute as the bar period. A 60 minute chart will only increment by 1 hour, for example. If you're running this on a high period time frame and need to extra timestamp resolution, you can add another series with AddDataSeries.

    I look forward to hearing from you.

    Comment


      #3
      Tick by Tick, that's why I try to delay just a seconds

      Comment


        #4
        Hello pstrusi,

        When you add a print for ToTime(Time[0]), what value do you see? Does the value printed allow the

        (ToTime(Time[0]) >= 180000 && ToTime(Time[0]) <= 180010)

        condition to become true?

        As Chris mentioned, Time[0] reflects the timestamp of a bar. If you are testing against a time based data series, the bar timestamps may be made in increments larger than your time check. If you have a tick based bar, Time[0] will update with each new tick made.

        Note that having Calculate.OnEachTick will have OnBarUpdate update with each incoming tick, but with time based bars, the timestamp of the bar (Time[0]) will still reflect when the bar closes, not the current time.

        We look forward to assisting.

        Comment


          #5
          Also put in some print statements above that condition to see if that time even happens.

          Comment


            #6
            Since it's E-Mini futures tick by tick just starting the session, I can assure you that many ticks went through that condition as it didn't exist and I have that print out to confirm. So the question remains: How is that possible ?

            Comment


              #7
              NinjaTrader_ChrisL sorry for posting this here, but can you check PM? i've sent you a msg.

              Comment


                #8
                Hi pstrusi, thanks for your reply.

                I made a simple test with the condition and it works on my installation:

                protected override void OnBarUpdate()
                {
                if ((ToTime(Time[0]) >= 180000 && ToTime(Time[0]) <= 180010) )
                {
                Print("Condition Reached");
                Print("Time now: " + Time[0]);
                }
                }

                This works for 15 minute, 10 minute bars because those will land on 180000 exactly

                What is the bar period that you are testing on?

                Comment


                  #9
                  @TazoTodua, I changed your username, try logging out and back again to see the changes.

                  Comment


                    #10
                    Thanks Jim, Chris for the attention to the subject.

                    As you've told and I've confirmed with simple tests this week, the Time condition works just fine when markets are already opened and working. The problem is starting at 6:00 pm on Sundays that for some reason, the condition is false. I'm thinking that perhaps is cause sometimes, certain instruments's first tick could come before 6:00pm or something similar. Still, my original condition was :
                    (ToTime(Time[0]) >= 175900 && ToTime(Time[0]) <= 180010) therefore it should have caught any early tick before 6:00pm. Weird really. Any ideas ?

                    Comment


                      #11
                      Hi pstrusi, thanks for your reply.

                      Please make sure to Print out whatever the timestamp of the bar is so that you can make the comparison yourself at Sunday @ 6PM. What timestamp are you getting that makes your condition false when it's expected to be true?

                      Comment


                        #12
                        This time, with futures opening, this little code worked as thought. Perhaps it was the most broad timespan within the condition that caught any rogue tick, lol. So, problem solved. Thanks!

                        Code:
                        if ( Historical || (ToTime(Time[0]) >= 171000 && ToTime(Time[0]) <= 180010) )
                                    {
                                        Print(" ");
                                        Print(Time[0].ToString());
                                        Print("HISTORICAL OR TIME-CONDITION ON!! ");
                                        return; 
                                    }

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        79 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        45 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        29 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        32 views
                        0 likes
                        Last Post TheRealMorford  
                        Started by Mindset, 02-28-2026, 06:16 AM
                        0 responses
                        66 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Working...
                        X