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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    35 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    12 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    18 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X