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 Hwop38, 05-04-2026, 07:02 PM
    0 responses
    164 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    318 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    246 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    350 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    179 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X