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

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 jaybedreamin, Today, 05:56 PM
          0 responses
          3 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          18 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          1 view
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          6 views
          0 likes
          Last Post Javierw.ok  
          Started by timmbbo, Today, 08:59 AM
          2 responses
          10 views
          0 likes
          Last Post bltdavid  
          Working...
          X