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

Milliseconds granularity

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

    Milliseconds granularity

    Hello!
    Is it possible to calculate strategy (or indicator) with granularity in milliseconds?
    I saw, that when I'm using EnterLong logic I have my Print (for debugging) earlier then the EnterLong event. And in all situations the EnterLong occurs on the next tick of the next second after signal comes.
    I'm using tick timeframes for calculations and it's very important to get that signal in the current millisecond..
    F.e.: I have signal (timestamp at 13:08:01:0158 and it prints me that time, but the EnterLong will occur at least at 13:08:02:xxxx , where xxxx is the first tick of the new second.
    How can I fix that? I want to enter and print at the same time.
    Thank you.

    #2
    I saw that we can use C# to change the granularity for ms with DateTime structure. How to do it? Can you give the sample please?

    Comment


      #3
      Hello YevhenShynkarenko,

      This would be general C# and not specific to NinjaScript.

      That said, you can use custom datetime format strings.
      Below is a public link to the Microsoft documentation.
      Learn to use custom date and time format strings to convert DateTime or DateTimeOffset values into text representations, or to parse strings for dates & times.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        Hello YevhenShynkarenko,

        This would be general C# and not specific to NinjaScript.

        That said, you can use custom datetime format strings.
        Below is a public link to the Microsoft documentation.
        https://msdn.microsoft.com/en-us/lib...vs.110%29.aspx
        I know that public link. Can you provide an example on how to use it in NinjaScript code?

        Comment


          #5
          Hello YevhenShynkarenko,

          I'm copying and pasting the example from the documentation and modifying this to use 'ffff', save to a string, then printing the string.

          Below is a link to the help guide on Print().
          https://ninjatrader.com/support/help.../nt8/print.htm
          Code:
          DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15, 18);
          CultureInfo ci = CultureInfo.InvariantCulture;
          
          string dateString = date1.ToString("hh:mm:ss.ffff", ci);
          
          Print(dateString);
          Shortened:
          Code:
          Print(new DateTime(2008, 8, 29, 19, 27, 15, 18).ToString("hh:mm:ss.ffff"));
          Below is a link to a forum post with helpful information about getting started with NinjaScript and C#.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello YevhenShynkarenko,

            I'm copying and pasting the example from the documentation and modifying this to use 'ffff', save to a string, then printing the string.

            Below is a link to the help guide on Print().
            https://ninjatrader.com/support/help.../nt8/print.htm
            Code:
            DateTime date1 = new DateTime(2008, 8, 29, 19, 27, 15, 18);
            CultureInfo ci = CultureInfo.InvariantCulture;
            
            string dateString = date1.ToString("hh:mm:ss.ffff", ci);
            
            Print(dateString);
            Shortened:
            Code:
            Print(new DateTime(2008, 8, 29, 19, 27, 15, 18).ToString("hh:mm:ss.ffff"));
            Below is a link to a forum post with helpful information about getting started with NinjaScript and C#.
            https://ninjatrader.com/support/foru...040#post786040
            Great, buy I need to calculate ALL my strategy with the "fff". Without this delay in 1 second which NT always using in calculating and especially in ENTRIES!!!!! Read the first post please with example of the problem.

            Comment


              #7
              Hello YevhenShynkarenko,

              I'm not quite sure I'm understanding.. Are you wanting a millisecond bar type?

              Is using Calculate with On each tick insufficent?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post
                Hello YevhenShynkarenko,

                I'm not quite sure I'm understanding.. Are you wanting a millisecond bar type?

                Is using Calculate with On each tick insufficent?
                Yes, it's calculating with On each tick, but in any case I have one second delay when I'm trying to enter position. I have print with miliseconds, and then looking for entry order time - it always waiting for next second (not for next tick!) - and only then filled. In some situations there are more then 100 ticks in that second! And I need to enter "right now". How to do that?

                Comment


                  #9
                  Hello YevhenShynkarenko,

                  If you have a print appearing the moment the order is submitted and this is being submitted after a tick is received and OnBarUpdate is triggered, that order is submitted at that time. NinjaTrader is not intentionally waiting one second before placing your order.

                  Once a live order is submitted to a broker, it takes some time for the order to become initialized, pending a submission, submission, transmission through the internet to the brokerage server, processing on the brokerage server, transmission to the exchange, processing on the exchange for the order to become working, time for a opposite trader to be paired up, and then an exchange execution, this has to be reported back to the broker, and then back to NinjaTrader through the internet, and then processed on NinjaTrader's side to know there is a fill.

                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hello YevhenShynkarenko,

                    If you have a print appearing the moment the order is submitted and this is being submitted after a tick is received and OnBarUpdate is triggered, that order is submitted at that time. NinjaTrader is not intentionally waiting one second before placing your order.

                    Once a live order is submitted to a broker, it takes some time for the order to become initialized, pending a submission, submission, transmission through the internet to the brokerage server, processing on the brokerage server, transmission to the exchange, processing on the exchange for the order to become working, time for a opposite trader to be paired up, and then an exchange execution, this has to be reported back to the broker, and then back to NinjaTrader through the internet, and then processed on NinjaTrader's side to know there is a fill.
                    It doesnt sumbitted after a tick recieved! It waits FOR A SECOND and ONE TICK after! Ii ALWAYS waits for closing current SECOND, and then one tick. And in that waiting can be more then 200 ticks!!!! This situation happens all times!!! It's Market Replay, no Internet connection needed. It must provide orders without ping.

                    Comment


                      #11
                      Hello YevhenShynkarenko,

                      Is this a live order submitted to the broker?

                      Or is this an order placed to the Sim101 processed by the Simulation engine with incoming real-time data?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_ChelseaB View Post
                        Hello YevhenShynkarenko,

                        Is this a live order submitted to the broker?

                        Or is this an order placed to the Sim101 processed by the Simulation engine with incoming real-time data?
                        This is the Sim01 with real-time data and Market Replay data is the same.

                        Comment


                          #13
                          Hello YevhenShynkarenko,

                          The Simulation engine is powered by incoming data.

                          An order placed on the Sim101 will fill with the next received tick. (and will not fill until that next tick is received)

                          If no next tick is received within about 30 seconds, an error will appear notifying "There is no market data available to drive the simulation engine" and the order will be rejected.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_ChelseaB View Post
                            Hello YevhenShynkarenko,

                            The Simulation engine is powered by incoming data.

                            An order placed on the Sim101 will fill with the next received tick. (and will not fill until that next tick is received)

                            If no next tick is received within about 30 seconds, an error will appear notifying "There is no market data available to drive the simulation engine" and the order will be rejected.
                            IT DOES NOT FILLED ON THE NEXT TICK!
                            IT FILLED AFTER A SECOND AND THE NEXT TICK!!!!!!!!!!!!!!!!! HEAR ME!!!!!!!!!

                            Look on the chart.
                            That Print to Output and EnterLong are in the same section of the code ! It goes
                            EnterLong();
                            Print();

                            AND NOW LOOOOOOK on the chart. How many ticks are gone after that print comes? ONE ?? OR MORE???
                            I know about what I'm talking. DELAY IS ALWAYS ONE SECOND AND ONE TICK AFTER. WHAT TO DO?

                            Comment


                              #15
                              Hello YevhenShynkarenko,

                              You can print out the ticks and the order progression so that we do not have to visually look at a chart.

                              Unfortunately, I am not able to look at this chart and see the issue.

                              Which specific tick is the big red x on?


                              Please use prints.

                              Below is a link to a forum post that demonstrates how to use prints to understand behavior.


                              Print one line below the EnterLong() call, Print(string.Format("{0} | Calling EnterLong()", Time[0]));
                              Print every tick on OnBarUpdate() outside of any condition.
                              Print the order object from OnOrderUpdate().

                              Save the output from the output window.
                              Post the output with your reply.

                              If we are seeing from the output the order is a market order and there are multiple ticks processed in OnBarUpdate() before the order state of the order transitions to order submitted, I would like to look into this further.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by swestendorf, Today, 11:14 AM
                              2 responses
                              5 views
                              0 likes
                              Last Post NinjaTrader_Kimberly  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              4 responses
                              13 views
                              0 likes
                              Last Post xiinteractive  
                              Started by Mupulen, Today, 11:26 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Mupulen
                              by Mupulen
                               
                              Started by Sparkyboy, Today, 10:57 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by TheMarlin801, 10-13-2020, 01:40 AM
                              21 responses
                              3,917 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Working...
                              X