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

Use of timestamps to log trading activity in the output windows.

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

    Use of timestamps to log trading activity in the output windows.

    Hi,

    For monitoring and debugging purpose, I am logging all trading activities to the output windows with the function Print().
    When doing so, I start my message with Times[BarsInProgress][0].ToString() to print the current time into a string.
    For instance I log trade executions when they occur in the OnExecution() function.

    Sometimes but not always i find that my timestamps are way off in comparison to the timestamps registered by my broker. Something like 15min or 20min earlier than the time when the trade actually took place.
    Am I doing something wrong writing timestamps like this?
    Is there a better way to do it?

    Thanks for the help

    #2
    Hello Orlanth,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    Times and Time will use the timestamp of the bar. This would be the time that the bar closes.
    For Tick based bars, the timestamp is the last tick that occurred for that bar. However, for time based bars such as Minute and Day, the timestamp reflects when the bar will close and not the last tick or the current time.

    You may wish to instead use DateTime.Now for your local PC time. You can find information on the DateTime at the following link: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Comment


      #3
      I am actually using tick data for future contracts known to be very liquid.
      Hence, if the time stamp of the last tick is 15min away, that can only mean an issue with the data feed!

      I though about using DateTime.Now, and this would work fine when writing the log of live trading activity. However, the same code would not work with simulated results on historical tick data.

      Any other way that would work in both backtest and live trading ?

      Comment


        #4
        Originally posted by Orlanth View Post
        I am actually using tick data for future contracts known to be very liquid.
        Hence, if the time stamp of the last tick is 15min away, that can only mean an issue with the data feed!
        Slow down a second.

        It doesn't matter if you are using tick data.

        What timeframes are you using? 15 minute and 20 minutes or more??

        Comment


          #5
          Actually, a second is a large slow down...

          My strategy does not use such a time frame.
          It computes on every incoming tick. i.e. CalculateOnBarClose = false;
          But because of the poor data quality (eSignal timestamps are accurate to the sec only, no ms in their historical data) i do have to slow down my calculation and run on every new second rather than on every tick.
          This logic could make a profit in a timeframe of less than a minutes, or more than an hour, it's all down to the markets movements of cointegrated products and how the strategy is managing its positions.

          Comment


            #6
            Originally posted by Orlanth View Post
            Actually, a second is a large slow down...

            My strategy does not use such a time frame.
            It computes on every incoming tick. i.e. CalculateOnBarClose = false;
            But because of the poor data quality (eSignal timestamps are accurate to the sec only, no ms in their historical data) i do have to slow down my calculation and run on every new second rather than on every tick.
            This logic could make a profit in a timeframe of less than a minutes, or more than an hour, it's all down to the markets movements of cointegrated products and how the strategy is managing its positions.
            You DID NOT answer my question. Avoidance I see.

            If you need 1 second time stamp accuracy then run on a 1 second chart.

            I run on 15 seconds chart and I get 15 second prints.

            Comment


              #7
              Yes, it looks like we do not understand each other indeed...

              Just to clarify, I don't "run on charts".
              i guess if the strategy was running on a specific chart, this would be a tick-by-tick chart.
              If i use charts it is only for monitoring purpose, because the strategy is fully automated.

              This being said, yes you are right i guess my strategy could run the same way on a second chart, but there are at least 2 issues I see with this:
              - first eSignal does not provide second data via NT, when you download it is tick, min or day.
              i use ticks because this is the most accurate i have.
              - second if you simulate with ticks and run live on sec, you are in to find many differences between simulated results and live trading results. My trading is all based on historical backtests, and having simulations as realistic as possible is a must in my experience. So the professional way to do this is: if you simulate with ticks, then you run your strategy live with ticks.

              if your prints are consistent with your charts, then good for you. But we are getting away from my issue here...
              Is there any other way to print a timestamp than using the two ways mentioned below?
              Preferably this would be something that would works the same in live trading and simulation...
              If not, then is my issue with a timestamp 15min too old a proof that i had a tick data feed issue?

              Comment


                #8
                Originally posted by Orlanth View Post
                Yes, it looks like we do not understand each other indeed...

                Just to clarify, I don't "run on charts".
                i guess if the strategy was running on a specific chart, this would be a tick-by-tick chart.
                If i use charts it is only for monitoring purpose, because the strategy is fully automated.


                if your prints are consistent with your charts, then good for you. But we are getting away from my issue here...
                Is there any other way to print a timestamp than using the two ways mentioned below?
                Preferably this would be something that would works the same in live trading and simulation...
                If not, then is my issue with a timestamp 15min too old a proof that i had a tick data feed issue?
                But - What timeframe are you using? If you add your strategy to control panel or backtest, you have to choose a timeframe, irrespective of CalculateOnBarClose... ?

                I've only run 2-3 backtests in my life... I don't deal with historical data. Too many issues with that than I want to deal with.

                I run market replay and live.

                Comment


                  #9
                  I load my strategies into the control panel and i apply it to a Data Serie of type "tick".
                  I don't see any field called "timeframe" there... are you referring to the Type of the Data series ?

                  Comment


                    #10
                    Ok. How many ticks are you using?

                    Comment


                      #11
                      That's intraday trading, so all ticks are used by the strategy since the beginning of each day.

                      However there is no MA or things that require a time frame, so all variable are calculated on each tick.
                      The strategy could trigger on the second tick if necessary, not need to wait for a number of ticks to happen...

                      But it is apparently very different than what you do since i focus a lot on backtesting.
                      When performing walk-forward backtest i might use 2-3 years of tick data.

                      Comment


                        #12
                        Hello Orlanth,

                        Thank you for your response.

                        Time[0] will pull the most recent Bar timestamp. So it is important to know what period type and value you are using when enabling the strategy. For example, do you use 1 Tick?

                        The 15 to 20 minute delay in the timestamp suggests that Time[0] is not pulling at the time you wish. Are you comparing the OnExecution() information as pulled when running the strategy over historical data?

                        To better clarify, right click on the strategy in the Strategies tab > select Strategy Performance > select Historical (not Real-time and Historical). Look at the execution times are these 15 to 20 minutes behind the actual report from the broker/brokerage technology?

                        Repeat these steps again but open the Real-Time performance instead (right click on the strategy in the Strategies tab > select Strategy Performance > select Real-Time (not Real-time and Historical)). Do these execution times match those of the broker/brokerage technology?

                        Comment


                          #13
                          As i mentioned in one of the previous comment, the type i use is 1 tick.
                          Obviously, considering that my eSignal data provider did not report any issue during this time and that the future contract i am using are very liquid, this indicate without a doubt that I had some tick data feed issue with NT API for eSignal. There is no way these contract stay 15min with an update on the bid/ask or a trade.

                          So i did the comparison with the broker timestamps already. I understand i can have a couple of second difference due to the fact that i write my timestamp when the OnExecution() is triggered, but there is no way that these timestamps can be 15min difference. the only explanation i see is my order was pending for 15min with a feed to get updated. When it finally get filled then i write a wrong timestamp 15min old in my output windows. And clearly at that time i could see the feed was delayed because it see the feed fine on the broker side. I reported the issue to NT support already, but they could not find any evidence of issue with the eSignal API and blamed it on my usage of the wrong IB build... i don't understand how a wrong IB build can impact my connection between eSignal and NT?

                          Comment


                            #14
                            Hello Orlanth,

                            I would think that was a mistake and the intent was to suggest using the supported version of eSignal. The supported version for NinjaTrader 7 is 10.6.2124. You can find the connection guide at the following link: http://ninjatrader.com/ConnectionGui...nnection-Guide

                            For 1 Tick chart's timestamp to be 15 to 20 minutes off from the execution time is quite daunting. I would suspect the behavior is caused due to the time. I would recommend syncing the PC clock time as well as verifying you are using the supported version of eSignal.

                            Please use the steps below to sync the PC clock:
                            • Close NinjaTrader.
                            • Open the Windows Control Panel
                            • Select Date and Time
                            • Click on Internet Time tab.
                            • Set the server to time.nist.gov and then click Update.
                            • Ensure to check for a message under the Update button that says it was successful.
                            • If it did not properly sync, even after a few tries, try manually setting your PC clock and then syncing.
                            • Your PC clock should now be updated.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by lightsun47, Today, 03:51 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post lightsun47  
                            Started by 00nevest, Today, 02:27 PM
                            1 response
                            8 views
                            0 likes
                            Last Post 00nevest  
                            Started by futtrader, 04-21-2024, 01:50 AM
                            4 responses
                            44 views
                            0 likes
                            Last Post futtrader  
                            Started by Option Whisperer, Today, 09:55 AM
                            1 response
                            13 views
                            0 likes
                            Last Post bltdavid  
                            Started by port119, Today, 02:43 PM
                            0 responses
                            9 views
                            0 likes
                            Last Post port119
                            by port119
                             
                            Working...
                            X