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

Indicator - Possible to Limit to Only Certain Hours?

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

    Indicator - Possible to Limit to Only Certain Hours?

    I've developed an indicator script which uses data from several instruments, loaded in at the Initialize section:

    example: Add("XXX",PeriodType.Minute,1);


    When I reload this indicator (after editing or when opening a workspace which includes it), I often get the following error message (outside of extended market hours):

    TDA: ERROR:BACKFILL "XXX" response too short {2D}{20}{2D}{20}{2D}

    (My data connection is TDA).

    I was wondering if there was a way to limit the processing of this script to certain hours of the day so as to avoid these very annoying error messages?

    Can the "Add" instrument lines reside somewhere besides the Initialize section? Or somehow be time-restricted in the Initialize section? Or can the Initialize section be delayed from initialzing until a certain time criteria? Etc...???

    Thanks.

    #2
    allman,

    Please see our Strategy reference sample on Using a time filter to limit trading hours. While this is demonstrated in a strategy, you could apply the same concept to an indicator as well to prevent the OnBarUpdate events from triggering.



    It is recommended to call the Add() method from the Initialize() method. Initiailize will be called anytime a script is reloaded and there isn't anyway to prevent these from being called.

    The error you are reported from TDA has reported to only affect Daily intervals. To avoid issues you could then supplement your data from Kinetick - End of Day (free) from the File--> Connect menu.
    MatthewNinjaTrader Product Management

    Comment


      #3
      [QUOTE=NinjaTrader_Matthew;252820]allman,

      Please see our Strategy reference sample on Using a time filter to limit trading hours. While this is demonstrated in a strategy, you could apply the same concept to an indicator as well to prevent the OnBarUpdate events from triggering.



      Can this be done using the Strategy Wizard or must one edit the code?

      Best regards,

      Dolfan

      Comment


        #4
        Hello Dolfan,

        Thanks for your post.

        Yes, you can easily configure time filters in the strategy wizard.

        Here is a link to the strategy wizard condition builder screens: http://ninjatrader.com/support/helpG...on_builder.htm Please review the section, "How to create time comparisons".
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          I played around this quite a bit last night and ran a lot of back testing. After the back test results pop up I select Periods, then Hour of the Day. My question is, for the hours that are displayed, is this the time that the trade opened or the time that the trade closed? I found very little consistency in the results, even with subtle changes.

          Comment


            #6
            Hello Dolfan,

            Thanks for your reply.

            When viewing the performance report period tab this would show closed trades within the period selected. For example if you ran the analysis over a 3 month period, the "Hour of day" would show a summary of closed trades in each hour over the 3 months period.

            If you have further questions on strategy analyzer, please post them in the appropriate forum thread located here: http://ninjatrader.com/support/forum...splay.php?f=17
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Matthew View Post
              allman,

              Please see our Strategy reference sample on Using a time filter to limit trading hours. While this is demonstrated in a strategy, you could apply the same concept to an indicator as well to prevent the OnBarUpdate events from triggering.



              It is recommended to call the Add() method from the Initialize() method. Initiailize will be called anytime a script is reloaded and there isn't anyway to prevent these from being called.

              The error you are reported from TDA has reported to only affect Daily intervals. To avoid issues you could then supplement your data from Kinetick - End of Day (free) from the File--> Connect menu.
              I have a question about the referenced "Using a time filter to limit trading hours" post. The code shown has hardcoded values based on GMT -5:00 EST.

              I am new to NT, and I am guessing that all time values are evaluated based on whatever timezone the computer is set to that runs the platform. So if I were to use this code in EST, then traveled to the west coast and run the platform with my computer changed to PST, this code block would not function as intended, and would require a code change and re-compile. Is this correct?

              Wouldn't it be better to do something like this:

              Code:
              (DateTime.UtcNow.Ticks >= DateTime.UtcNow.Date.AddHours(14.5).Ticks 
                && DateTime.UtcNow.Ticks < DateTime.UtcNow.Date.AddHours(17).Ticks) 
              || (DateTime.UtcNow.Ticks >= DateTime.UtcNow.Date.AddHours(19).Ticks 
                && DateTime.UtcNow.Ticks < DateTime.UtcNow.Date.AddHours(20.45).Ticks)

              However, I don't think this accounts for daylight savings time.

              Thoughts?

              Comment


                #8
                Hello banach,

                Thanks for your post and welcome to the NinjaTrader forums!

                You are correct you would need to adjust the time. Certainly tying it to UTC would work.

                The example is provided to show how the time can be used to filter the code. What is not shown is how to be able to set up time outside of the strategy/indicator in the user interface panel so that the indicator/strategy could be adapted for the left or right coast or somewhere else without the need to recompile the code by simply entering new time values. An example of using time as a user adjustable input can be found here: http://ninjatrader.com/support/forum...ead.php?t=8600

                Alternatively in your travel example, you could leave your PC always set to EST as many traders do regardless of where they reside.
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ntram, Today, 05:39 PM
                0 responses
                2 views
                0 likes
                Last Post ntram
                by ntram
                 
                Started by giulyko00, Today, 11:49 AM
                2 responses
                11 views
                0 likes
                Last Post giulyko00  
                Started by Aviram Y, Today, 06:03 AM
                2 responses
                10 views
                0 likes
                Last Post Aviram Y  
                Started by FishTrade, Today, 03:42 PM
                0 responses
                1 view
                0 likes
                Last Post FishTrade  
                Started by Richozzy38, Today, 01:06 PM
                3 responses
                14 views
                0 likes
                Last Post Richozzy38  
                Working...
                X