Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry Bars?

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

    Entry Bars?

    Hi,

    I have a simple thing I want to do. A requirement of a strategy I'm working on is to exit 120-minutes after an entry occurred. However the BarsSinceEntry method returns the number of bars since the last entry. Is there a way to query NT to figure out how long ago all the entries were entered?


    thanks!
    jon

    #2
    Jon, you could record the bar time of the entry -



    However it might be easier to just calc how many bars you're 120 min would represent and then using this with BarsSinceEntry...

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Jon, you could record the bar time of the entry -



      However it might be easier to just calc how many bars you're 120 min would represent and then using this with BarsSinceEntry...
      Bertrand,

      Hmm...Ok this is what I did. I created a dictionary that contained all my entries by name and the integer value of Time[0] of the bar. I then compared the entry time value with the current bar's Time[0] value and checked to see if it was ever greater or equal to 7200 (120 minutes * 60 seconds). However this is what happened:

      I have an entry at the 9:08AM bar (the Time[0] value of 90800) and at 10:00AM (the Time[0] value is 100000). The difference between these two values is 9200 and therefore my exit code got called. However this is NOT 120 minutes after the entry.

      Is there something I'm doing wrong? I'm assuming my calculation is off somehow?
      Maybe I should be comparing the difference to 20000 (110800 - 90800)?

      thanks!

      Comment


        #4
        jonmoron,

        You cannot use math like that to try and check time. Time is not on a 10 base system while actual numbers are.

        To check how much time has passed you would want to just subtract the two DateTime objects from each other to get a TimeSpan object. Then check the TimeSpan object to contain a time span greater than 2 hrs.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          jonmoron,

          You cannot use math like that to try and check time. Time is not on a 10 base system while actual numbers are.

          To check how much time has passed you would want to just subtract the two DateTime objects from each other to get a TimeSpan object. Then check the TimeSpan object to contain a time span greater than 2 hrs.
          Thanks! That works perfectly.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          669 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          378 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          111 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          581 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X