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 charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      73 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      152 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      100 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      288 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X