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.
    Chris L.NinjaTrader Customer Service

    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.
        JimNinjaTrader Customer Service

        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?
                Chris L.NinjaTrader Customer Service

                Comment


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

                  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?
                      Chris L.NinjaTrader Customer Service

                      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 ghoul, Today, 06:02 PM
                        2 responses
                        12 views
                        0 likes
                        Last Post ghoul
                        by ghoul
                         
                        Started by jeronymite, 04-12-2024, 04:26 PM
                        3 responses
                        44 views
                        0 likes
                        Last Post jeronymite  
                        Started by Barry Milan, Yesterday, 10:35 PM
                        7 responses
                        20 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by AttiM, 02-14-2024, 05:20 PM
                        10 responses
                        180 views
                        0 likes
                        Last Post jeronymite  
                        Started by DanielSanMartin, Yesterday, 02:37 PM
                        2 responses
                        13 views
                        0 likes
                        Last Post DanielSanMartin  
                        Working...
                        X