Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy entering trade at precise time.

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

    Strategy entering trade at precise time.

    Hello

    I am building a strategy that enters the market at a very precise time. For example at exactly 8:29:55 AM.

    I have tried this:

    if (ToTime(Time[0]) >= ToTime(8, 29, 55) { EnterLong(); }

    It executes at 8:29:00 instead of 8:29:55.
    Is there way to precisely compare times down to the second (or even millisecond)?
    I tried with CalculateOnBarClose set to both true and false.

    #2
    Hello stochasticsteve.

    Thank you for the question I will be happy to help.

    I looked at the code you have provided and I am not sure why you would get a time before what you have set, somehow that condition is becoming true before that time. you could try to replace the second ToTime with just the int time as 82955 and see if that works correctly.

    I would like to ask what type of a chart is this running on. Is this a minute or tick chart?

    Also is this running on live data or is this during a backtest?

    Being that it is executing on a specific time without any seconds this seems like it is being calculated on a bar close of possibly a minute chart but I could be wrong. I will need some additional information to correctly address what may be happening.

    As for comparing time down to the millisecond. NinjaTrader currently does not go down to the millisecond with any of the built in methods, Currently I don't believe there is a way you would be able to use milliseconds in a comparison with a bar time.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Thanks so much for your help. I am running this on a one-minute chart. I have only attempted to use it during market replay so far. Could it be that I only have minute data instead of tick data?

      Thanks

      Comment


        #4
        Hi Jesse,

        I tried this out in simulation mode real-time and it worked much better. It's very interesting; it filled at 45 seconds seconds instead of 55 though. Why would it do that? Does it use my computer's time or time from somewhere else?

        Thanks Jesse,
        Steve

        Comment


          #5
          I can see the difference in why is executed early now. It is because there are few trades going through in the aftermarket. I just tried it out set for 18:25:55 and it executed 10 seconds into the minute. The first tick that came through once that 25 (in this case) bar started, set the trade off. It's like it's ignoring the seconds setting.

          Thanks for your help on this Jesse!

          Comment


            #6
            Hello stochasticsteve,

            Thank you for the replies,

            For your first question:
            Yes using the minute data with no intra-minute or tick data would create orders on the minute regardless of the CalculateOnBarClose. This is because you are on a 1 minute chart and the chart is tick driven so every 1 minute there would be 1 tick to make OnBarUpdate happen.

            For the second question:

            You would see a delay if there is limited ticks because there is no reason for OnBarUpdate to process anything unless a tick is received. For it filling early If you are using a 10 second chart I could see this happening because you are using the >= so when the 45 bar closes the condition becomes true.

            For what you are trying to do it sounds like you may be better off comparing the PC clock time to your specified time, you could do that using the following:

            Code:
            if (ToTime(DateTime.Now) >= ToTime(8, 29, 55))
            { 
            }
            This would compare your current computer clock time to 8:29:55 if a tick happens and the pc clock is greater than or equal to that time, the condition would be true.

            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by trilliantrader, 04-18-2024, 08:16 AM
            4 responses
            18 views
            0 likes
            Last Post trilliantrader  
            Started by mgco4you, Today, 09:46 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by wzgy0920, Today, 09:53 PM
            0 responses
            9 views
            0 likes
            Last Post wzgy0920  
            Started by Rapine Heihei, Today, 08:19 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Rapine Heihei, Today, 08:25 PM
            0 responses
            10 views
            0 likes
            Last Post Rapine Heihei  
            Working...
            X