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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      152 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      87 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      131 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      127 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      106 views
      0 likes
      Last Post CarlTrading  
      Working...
      X