Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate time between two candles in ninjascript?

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

    Calculate time between two candles in ninjascript?

    How do i check the time that have elapsed between two candles in Ninjascript?

    In other words, i want to check how minutes have passed between the current Bar[0] and Bar[12]. Assuming current time is 1:00pm and Bar[12] closed at 12:40pm. The script will return 20mins.

    #2
    double diff = (Time[0] - Time[12]).TotalMinutes;
    or if you dont wanna fraction of minutes:
    int diff = (int)(Time[0] - Time[12]).TotalMinutes;
    Last edited by Leeroy_Jenkins; 10-13-2023, 01:26 AM.

    Comment


      #3
      Hello cryfgg,

      Leeroy_Jenkins suggestion should work.

      You can also use DateTime.Subtract(), which will return a timespan.
      Returns the value that results from subtracting the specified time or duration from the value of this instance.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Good reading here.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        35 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        13 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        19 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        21 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X