Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time Between 2 Bars

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

    Time Between 2 Bars

    Hi,

    I've this logic in my strategy and the "diff" in time between 2 bars is printing properly. I'm trying to have a bool where if the time between bars is less than 5 seconds my bool would be false, otherwise true. I get an error code CS0019 saying I can't use "<" for TimeSpan and int for this part of the code: if (diff < 000005). How do I resolve this?

    Code:
    TimeSpan diff = Times[2][0] - Times[2][1];
    Print ("Time difference: "+diff);
    
    if (diff < 000005)
    {
    barok = false;
    }

    #2
    Try this,

    Code:
    TimeSpan diff = Times[2][0] - Times[2][1];
    Print ("Time difference: "+diff);
    
    if (diff.Seconds < 5)
    {
    barok = false;
    }
    Google is your friend.

    If you're still learning C# and/or NinjaScript,
    then google everything whenever you find
    yourself not knowing something. You'll learn
    things at a breath-taking pace, and become
    self-sufficient sooner -- you just have to get
    into the 'search the internet first' habit.

    Tips:
    For anything C# related, prefix your search string with C#.
    For anything NT related, prefix your search string with NinjaTrader.

    Just my 2˘.

    Last edited by bltdavid; 02-02-2025, 10:08 AM.

    Comment


      #3
      Thank you Sir. That worked.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      72 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      39 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X