Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple time based action

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

    Simple time based action

    Hello, I'm struggling on a simple concept here.

    Say I enter a position at point a and if it's gone nowhere in 30 mins i want to exit ... how do I calculate the time difference?

    I understand that I could do

    if (EntryTime+30 minutes<=CurrentTime)
    exit code goes here

    But how do I achieve the time comparison? If I use ToTime(Time[0]) it turns it into an integer, which is no use as adding 3000 to 163000 doesn't get you to 170000 e.g. 166000<=170000 evaluates as true (so this way is no use to me). Can I turn everythiing into seconds and do a comparison that way?

    e.g.

    if (EntryTimeinSeconds+1800<=CurrentTimeinSeconds)
    exit code goes here

    Thanks
    Al

    #2
    You could mark the bar you enter and do simple math to check

    if (CurrentBar - markedBar >= 6)
    // Do something

    This would work for 5 minute bars and likely the simplest approach. Otherwise, you would have to work with methods and properties on the DateTime class.

    Something like this, don't recall exact syntax. Look up this class in MSDN help guide online or Google it.

    Time[0].Subtract(Time[barsAgoOfEntry]).Minutes > 30
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks, I'll look at that
      Al

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      558 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X