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

Geting Daily data at the end of the session

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

    Geting Daily data at the end of the session

    Hi,

    I'm developing NT strategy that analyze daily data at the end of the trading session and give me some statistic on the data.
    My problem is that if I want to get today data after the session is over before the next session start NT doesn't call the OnBarUpdate() because it will only be called when a new bar open and that will only be tomorrow when the next session start, and this is too late for me.
    Is there a way to overcome this issue?
    I'm using kinetick real-time service.

    TX,
    Roy

    #2
    Hello Roy,
    To assist you further may I know:
    1. Is calculate on bar close set to true or false
    2. Are you backtesting the strategy or using the Market Analyzer.


    I look forward to assisting you further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      CalculateOnBarClose = true;
      I'm using the backtesting.

      Comment


        #4
        Hello Roy,
        If you set CalculateOnBarClose to false from the initialize section of the NinjaScript code then can you get the current days bars into consideration.

        Please note in backtest, the calculations will be still be at the end of the bar.

        JoydeepNinjaTrader Customer Service

        Comment


          #5
          This strategy is only for backtesting, so there isn't any importance for CalculateOnBarClose.
          I just want to have access to the last bar when I'm running it and the session is over before another tick come and close the bar.

          Comment


            #6
            Hello freewind,
            By Default NT needs the next tick of the next bar as the closing event to create the bar. However you can play around with setting CalculateOnBarClose = false (in the Initialize section of your code) to work around this in the strategy backtest.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Hi guys,

              I've been strugling with same thing, and more.
              I want to have several methods that act on the following conditions:
              OnBarOpen()
              OnBarClose()
              OnSessionOpen()
              OnSessionClose()
              OnSatrtup() - this is already a built-in method that you can override.
              OnTermination()- this is already a built-in method that you can override.

              IMO these ought to be provided by NT, and should work for real-time, CalculateOnBarClose (true and false), market replay, and historical, for all bar types.

              I'm developing these myself for now. I have the followimg"
              OnBarOpen(), OnBarClose() - I use BarsPercentComplete to tigger both
              OnSessionOpen() - I use Bars.FirstBarOfSession and my OnBarOpen().
              OnSessionClose - the only thing I can do is to try and "catch" this at the last tick/bar of a session by playing with Time, etc. - ugly and tricky for all the testing conditions. I too don't want to wait for the next days' session to open to run this. It should be very easy for NT to provide this trigger.

              Does anyone have an elegant solution for these?

              Thanks,
              Dean

              Comment


                #8
                Hello Sphynxtrader,
                Welcome to the forum and I am happy to assist you.

                The open of a new bar essentially represents the close of the previous bar. Thus OnBarOpen is essentially the same as OnBarClose.

                You can use the FirstTickOfBar property to determine the new bar.


                So your code will essentially will be

                Code:
                if (FirstTickOfBar)
                {
                  //do something
                }
                The FirstBarOfSession and the LastBarOfSession will give you necessary information about when the first and last bar is in progress.


                Code:
                if (FirstTickOfBar && Bars.FirstBarOfSession)
                {
                    //do something
                }
                Please let me know if I can assist you any further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Thanks Joydeep,

                  Thanks for the FirstTickOfBar pointer - yes using this to detect OnCloseOFBar is mostly OK, EXCEPT at EndOfSession. The key problem we have is to detect the EndOfSession condition, as waiting for the next session to open to indicate the Close of a Session is not good enough.

                  Yetserday I played with this using MarketReplay (with Tick data) and the closest I could get was to trigger OnSessionClose during the FirstTickOfBar of the Last 1 Minute Bar. That bar with my AAPL July 13th data had 74 ticks remaining before the true EndOfSession.

                  I couldn't find a way to get the replay time beyond the opening of the last Bar which was the 13:00 Bar that opened at 12:59. Time[0], and Times.Ticks[0][0] are stuck at 13:00 and some long int when that last Bar opens and don't budge throughout that Bar.

                  Using the PercentOfBarComplete doesn't work in this case as the meaning of 100% is fuzzy and inmy case never triggered. It does trigger on 150 Tick Bars as there the meaning of 100% is predictable and guaranteed to happen.

                  Would it be possible for NT to provide a EndOfSession() method ?

                  Thanks,,
                  Dean

                  Comment


                    #10
                    Hello Sphynxtrader,
                    You have raised a fundamental question since NinjaTrader being an event driven application the end session may not trigger if there are no incoming ticks (in case of a low liquidity instrument).

                    I am not sure whether it can be implemented or not, I will send your feature request to development.

                    Meanwhile instead of using Percentage complete you can also use the GetNextBeginEnd to find the session end. You may have to further custom code it to met your exact requirements. Please refer to our help guide to know more about it.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Joydeep,

                      I appreciate the difficulties with event driven apps.
                      I do use GetNextBeginEnd to get the End time, but as I mentioned that gives me the First Tick of the Last Bar, or 12:59 for 1-minute Bars on regular stock trading days.

                      I have 2 questions that could get us closer to an EndOfSession event:

                      1. how can I access the timestamp of individual ticks ? As I mentioned the 13:00 1-minute bar of AAPL on 7/13 has 75 ticks (from Ameritrade's feed), and on 1X replay they do come sread out during that last minute 12:59-13:00. Time[0] and Times[0][0].Ticks stay static during that bar. One hack might be to use 1X replay and feed the seconds off of my PC DateTime - and stop somewhere closer to 13:00 - I realize that if the market is quiet I may not get a tick too close to 13:00, but I could get much closer than 12:59. This method would be too hard to use for multi-day replay backtesting.

                      2. Can you tell me how the NT ExitOnClose works ?
                      a. Without changing ExitOnCloseSeconds, when does this trigger?
                      b. Can I hijack this to serve my purposes of doing stuff at or very near the close of Session?

                      Thanks,
                      Dean


                      Comment


                        #12
                        Hello Sphynxtrader,
                        You can access the time in the OnMarketData event provided your connectivity provider supports it.

                        Code:
                        protected override void OnMarketData(MarketDataEventArgs e)
                        {
                        	Print(e.Time);
                        }


                        Yes, you can use the system time too.

                        You can also trigger a timer and can check the current system date (DateTime.Now). This is however beyond what we could support.
                        Provides a mechanism for executing a method on a thread pool thread at specified intervals. This class cannot be inherited.



                        Unfortunately ExitOnClose works the same way and has the same limitation.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks for all the great advice and pointers - I'll play with those.

                          Dean

                          Comment


                            #14
                            Hello Dean,
                            Thanks for your note.

                            Also development has assigned tracker id #1896 for your feature request (for EndOfSession event).

                            Please let me know if I can assist you any further.
                            JoydeepNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by inanazsocial, Today, 01:15 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post inanazsocial  
                            Started by trilliantrader, 04-18-2024, 08:16 AM
                            5 responses
                            22 views
                            0 likes
                            Last Post trilliantrader  
                            Started by Davidtowleii, Today, 12:15 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post Davidtowleii  
                            Started by guillembm, Yesterday, 11:25 AM
                            2 responses
                            9 views
                            0 likes
                            Last Post guillembm  
                            Started by junkone, 04-21-2024, 07:17 AM
                            9 responses
                            70 views
                            0 likes
                            Last Post jeronymite  
                            Working...
                            X