• 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

ToTime() issue

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

    ToTime() issue

    Here's the code i am pasting from the NT help files.

    // Only trade between 7:45 AM and 1:45 PM
    if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
    {
    // Strategy logic goes here
    }
    I want to do similar, BUT the strategy within the quotes triggers all the time.

    I had it print out what time it said it was.. see the code snippet first:

    if (ToTime(Time[0]) >= 155500 && ToTime(Time[0]) <= 160000)

    {
    // something useful

    Print(ToTime(Time[0]));

    }
    It is currently 1:54PM EST and the print out is 4PM (160000) which happens to be the closing time of my daily chart that it is running on.

    Why 4PM? Should it not read 135400 ??
    Last edited by Steve R; 03-03-2014, 01:03 PM.

    #2
    Hello Steve R,

    Thanks for your post.

    If this code is written into OnBarUpdate then the print will come at the end of a bar. If you have a daily bar and the bar closes at 160000 then the print will come at the time of the bar close.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      yeah that's what i figured.. so..

      how do i get the exact time IE at the time 135400 ??

      That NT code is pretty misleading really, because it does not tell you this at all.

      I know i've mentioned it before and i guess the help files are semi-gratis but that thing is pretty loose in the explanations and descriptions.

      EDIT: In a way that I can use it in an IF statement?? IE there's not likely an easy way to use DateTime.Now in this case too easily?
      Last edited by Steve R; 03-03-2014, 01:13 PM.

      Comment


        #4
        Hello Steve R,

        You will need to use a smaller interval on your chart. Day bars will always end at the end of the session. Minute bars will always close at the end of a minute.

        Use a 1 minute chart to capture a bar closing at 135400.

        You can also add 1 minute granularity to your chart by adding a secondary data series and process using using the minute chart.

        OnBarUpdate - http://www.ninjatrader.com/support/h...nbarupdate.htm
        Add() (to add a secondary data series) - http://www.ninjatrader.com/support/h...s/nt7/add3.htm
        BarsInProgress - http://www.ninjatrader.com/support/h...inprogress.htm
        BarsArray - http://www.ninjatrader.com/support/h.../barsarray.htm

        If you run during BarsInProgress 1 this can cause actions to happen at 135400 when the minute bar closes, but your daily bar will still not be closed yet.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          AH gotcha. I guess hoping for an easier route is not in the cards but hey i must be (slowly) learning, because i understand what you're saying.

          Thanks again, that'll work just fine.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by suprsnipes, Today, 08:26 PM
          0 responses
          2 views
          0 likes
          Last Post suprsnipes  
          Started by RobertoPaez, Today, 06:47 PM
          0 responses
          7 views
          0 likes
          Last Post RobertoPaez  
          Started by catinabag, Today, 06:45 PM
          0 responses
          4 views
          0 likes
          Last Post catinabag  
          Started by darkgreen, Today, 03:35 PM
          0 responses
          9 views
          0 likes
          Last Post darkgreen  
          Started by GTBrooks, Today, 02:44 PM
          3 responses
          14 views
          0 likes
          Last Post GTBrooks  
          Working...
          X