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

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 JonesJoker, 04-22-2024, 12:23 PM
      8 responses
      41 views
      0 likes
      Last Post JonesJoker  
      Started by timko, Today, 06:45 AM
      0 responses
      3 views
      0 likes
      Last Post timko
      by timko
       
      Started by Waxavi, 04-19-2024, 02:10 AM
      2 responses
      37 views
      0 likes
      Last Post poeds
      by poeds
       
      Started by chbruno, Yesterday, 04:10 PM
      1 response
      44 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by Max238, Today, 01:28 AM
      1 response
      25 views
      0 likes
      Last Post CactusMan  
      Working...
      X