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

Volume bar timer

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

    Volume bar timer

    I'm plotting volume bars and writing a simple indicator to show the amount of time elapsed from the prev bar to the current bar:

    protectedoverridevoid OnBarUpdate()
    {
    if (CurrentBar < 2)
    return;
    int TimeVar =(ToTime(Time[0]))/100 -(ToTime(Time[1]))/100 ;
    Plot0.Set(TimeVar);
    }

    I divided by 100 because I am not interested in resolution beyond a minute. This works fine unless the previous bar is before an hour rollover, ie bar[1]'s time =11:50 and bar[0]'s time = 12:04. I seem to get a 40 minute offset added to the plot for those bars. I could work around this if I could compare the left two digits of the ToTime values. Is there a way to truncate those values to the left 2 digits?

    #2
    What you could try is use TimeSpan objects instead.
    Code:
    TimeSpan timer = Time[0] - Time[1];
    Plot0.Set((int)timer.Minutes);
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh

      That worked first crack out of the bag. Thanks much.

      Max

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      53 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      33 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      5 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      19 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      6 views
      0 likes
      Last Post cre8able  
      Working...
      X