• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time and triggering

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

    Time and triggering

    Hello,

    I´m experiencing a strange behavior and when going over the code I can´t see anything wrong.

    I have

    if((ToTime(Time[0]) > 55959 && ToTime(Time[0]) < 70000 || (ToTime(Time[0]) > 093000 && ToTime(Time[0]) < 103000)) && Position.MarketPosition == MarketPosition.Flat)
    {[then do...}

    But there was an entry now at 11:14:35 (?)

    How it this possible please, Do I have to add like "&& if Currentday? (if so, how to do please?)

    Thank you!
    Tony

    #2
    Hello tonynt,

    Thanks for opening the thread.

    Your logic is valid for creating entries between a certain interval. I would suspect some other logic is causing entries after your time check or your PC clock is out of sync.

    Here is a demonstration I put together using your entry condition: https://www.screencast.com/t/Vb2GdjPe

    Here is the code used so you can test the same on your end:
    Code:
    protected override void OnBarUpdate()
    {
    	if((ToTime(Time[0]) > 55959 && ToTime(Time[0]) < 70000 || (ToTime(Time[0]) > 093000 && ToTime(Time[0]) < 103000)) && Position.MarketPosition == MarketPosition.Flat)
    		EnterLong();
    	
    	if (Position.MarketPosition == MarketPosition.Long)
    		ExitLong();
    }
    Please use the steps below to change/check your Time Zone and sync the PC clock:
    • Shutdown NinjaTrader
    • Right-click the clock in the lower right corner of your desktop
    • Select Adjust date/time
    • For Windows 10 click 'Additional date, time, & regional settings' -> then click 'Set the time and date'
    • Select the 'Internet Time' tab at the top
    • Set the server to time.nist.gov and then click Update.
    • If the message that appears says successful your PC clock should now be updated.
    • If not, select a different server from the Server: drop-down and try again (repeat until one of the servers is successful)

    After updating the PC clock, please restart NinjaTrader, then right-click the chart and select Reload All Historical Data.

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim,

      we have tested with your snippet and this works when script is cobc=true!

      When we run script on cobc=false (which is what we need) then eg with if((ToTime(Time[0]) > 144830 && ToTime(Time[0]) < 145100) we had an entrylong at computer time 14:48:02, then exit, new entry 14:48:10, then exit, new entry 14:48:26.

      All 3 entries are done with time condition ">144830".

      Why does it work with cobc=true and not with cobc=false. What do we have to use when script is running cobc=false?

      Thank you!
      Tony

      Comment


        #4
        Hello Tony,

        COBC should not have an effect on this. Could you answer the following questions so I may assist you further?

        Is this the only condition where you enter a position?

        What is the order method you are using to enter?

        Is this a Multi-Series Strategy?

        When you use Prints to print out the variables for the condition that fires your order method, what values are you getting when the entry happens out of bounds? Please provide a snippet of the entry condition and a copy of the NinjaScript Output Window with the variable values for the occurrence that happens "out of bounds."

        I look forward to your reply.
        JimNinjaTrader Customer Service

        Comment


          #5
          new test, adding screenshot

          Hello Jim,

          I have simply in the code form your reply above (and this works on cobc=true but not cobc=false, as described with the time and entries). The only condition is with your test:

          if((ToTime(Time[0]) > 144830 && ToTime(Time[0]) < 145100 || (ToTime(Time[0]) > 145400 && ToTime(Time[0]) < 145700)) && Position.MarketPosition == MarketPosition.Flat)
          EnterLong(1);

          if (Position.MarketPosition == MarketPosition.Long)
          ExitLong();
          }

          entry at 14:48:02, 14:48:10, 14:48:25 (all 3 <144830)

          I changed settings again to test and to send you a screenshot of code and exec.tab.

          Best
          Tony
          Attached Files
          Last edited by tonynt; 08-15-2017, 02:13 PM.

          Comment


            #6
            Hello Tony,

            Please add a Print() for ToTime(Time[0]) along side your entry condition and test with Market Replay data starting at 2:47PM. Make sure to have the Output Window open before enabling the strategy. Once the Playback connection passes over 2:48 and creates entries, please take a screenshot of the Output window to observe the time associated with Time[0] when the entry occurred.

            Time[0] will represent the time that the bar will close, and not the current time. If you would like more granular Time checks, I would suggest to add a finer data series and reference the Times object of that data series.

            Documentation on creating multi series NinjaScripts can be found here: https://ninjatrader.com/support/help...nstruments.htm

            Times object - https://ninjatrader.com/support/help.../nt7/times.htm

            I look forward to being of further assistance.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hello,

              what I recognize now when doing so is that in the output file there is only hour:min and no seconds.
              Why?

              If so then this is the explanation to my screenshot I sent where entries in cobc=false were triggered right before the minute. We examined and we found out that NT is rounding up to the next minute.

              Why are there not seconds showing in orders tab and only eg 16:34:00.

              Best regards
              Tony

              Comment


                #8
                Hello tonynt,

                The time is not rounding up. It is giving the time of the bar close for the current developing bar.

                Time[0] will represent the time that the bar will close, and not the current time. If you would like more granular Time checks, I would suggest to add a finer data series and reference the Times object of that data series.

                Documentation on creating multi series NinjaScripts can be found here: https://ninjatrader.com/support/help...nstruments.htm

                Times object - https://ninjatrader.com/support/help.../nt7/times.htm
                Please let me know if you have any additional questions.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jim,

                  thank you for your reply. With COBCtrue of course. But with COBCfalse?

                  We are running the script to test this with COBCfalse and in output window appear time xx:yy:00 always (even when entry is eg at xx:yy:07)

                  Thank you!
                  Tony

                  Comment


                    #10
                    COBC=true will iterate OnBarUpdate() on the close of the bar, while COBC=false will iterate OnBarUpdate() as the bar develops with each tick. Time[0] still represents the time of the bar close, not the current time.

                    Since the bar is developing when you reference Time[0] in COBC=false, you get the time that the bar will close.
                    JimNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by rainbow47, Today, 06:10 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post rainbow47  
                    Started by stenberg98, Today, 04:53 AM
                    2 responses
                    7 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Started by wukefuha, Today, 03:20 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Started by mbcmbc, Yesterday, 10:12 PM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_ChrisSch  
                    Started by fx.practic, Today, 03:44 AM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Working...
                    X