Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Arithmetic operations with times.

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

    Arithmetic operations with times.

    Hello!

    I want to draw Rays based on Time[x].
    I want afterwards to be able to move my ray from Time[x] to another. I thought about an integer and I would have something like this:
    HTML Code:
    Time[x] + (y*BarsPeriod.Value)
    The problem here is that I am failing to make addition on DateTime and an integer. The best way would be to convert my integer to DateTime or the dateTime to integer, but the number would be very high.
    In the dosumentation on DateTime in google, I have seen either comparison or operation on two DateTimes.

    Does someone have an idea on how to such operation as specified above?

    Many thanks!

    #2
    Hello Stanfillirenfro,

    What are you trying to add or subtract?

    Are you trying to add or subtract a number of bars ago?

    int fiveBarsAgo = CurrentBar - 5;

    // print the time of the bar from 5 bars ago
    Print(Time[fiveBarsAgo]);

    Are you trying to add or subtract a number of minutes from a date?

    DateTime fiveMinutesAgo = Time[0].AddMinutes(-5);

    // print the time of the bar from 5 minutes ago
    Print(Time[CurrentBar - Bars.GetBar(fiveMinutesAgo)]);
    Last edited by NinjaTrader_ChelseaB; 10-21-2022, 09:59 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Many thanks NinjaTrader_ChelseaB for your reply.
      I am working with 2000 ticks bars and not with time based bars.
      I am also in a loop and I want an operation such as:
      HTML Code:
       for(int i = y; i >= 1; i--)
      {
       Time[0] + (i*BarsPeriod.Value)
      }

      Comment


        #4
        Hello Stanfillirenfro,

        What are you using the loop for? What are you trying to loop over?

        Ok, you are using tick bars and not time based bars. I understand this. Tick bars are indexed with BarsAgo values and the bar index can still be retrieved by time, just like any other bar type.

        What are you trying to add or subtract?

        Are you trying to add or subtract a number of bars ago?

        Are you trying to add or subtract a number of minutes from a date?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Many thanks NinjaTrader_ChelseaB for your reply.

          I want to substract the number of bars ago.
          I think your explanation gives me an idea. I will implement it in the code and revert to you if I am still having problem.
          Thanks again for your help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          661 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          375 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          579 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X