Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X