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

Average bar time

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

    Average bar time

    Hello,

    I'm trying to work on an indicator that calculates the average time it takes to form a non time bar ( range, volume etc.). The average is based on the last 10 candles and ideally, would be displayed on the bottom left portion of the screen, similar to the "bar timer" indicator.
    I searched the forum and got this code to start with:

    Code:
    private Stopwatch stopWatch = new Stopwatch();
    
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {
    stopWatch.Stop();
    
    TimeSpan ts = stopWatch.Elapsed;
    Print(String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
    ts.Hours, ts.Minutes, ts.Seconds,
    ts.Milliseconds / 10));
    stopWatch.Reset();
    stopWatch.Start();
    }
    I keep getting error code CS0246​ and can't figure it out.

    Any help would be greatly appreciated.​​

    #2
    Use a search to find out about compiler errors: https://learn.microsoft.com/en-us/do...essages/cs0246 Likely stopwatch() does not exist in the current libraries.

    A far easier way to determine how long it takes a bar to form would be based on the closing time of one bar to the next, so simply find the time difference from one bar to the next.

    bartime = Time[0] - Time[1].TotalSeconds; (assuming you are looking for seconds, otherwise look at other extensions such as TotalMinutes, TotalMilliseconds, etc.)

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ageeholdings, Today, 07:43 AM
    0 responses
    7 views
    0 likes
    Last Post ageeholdings  
    Started by pibrew, Today, 06:37 AM
    0 responses
    4 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    12 views
    0 likes
    Last Post burtoninlondon  
    Working...
    X