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 Philippe56140, Today, 02:35 PM
    0 responses
    1 view
    0 likes
    Last Post Philippe56140  
    Started by 00nevest, Today, 02:27 PM
    0 responses
    1 view
    0 likes
    Last Post 00nevest  
    Started by Jonafare, 12-06-2012, 03:48 PM
    5 responses
    3,986 views
    0 likes
    Last Post rene69851  
    Started by Fitspressorest, Today, 01:38 PM
    0 responses
    2 views
    0 likes
    Last Post Fitspressorest  
    Started by Jonker, Today, 01:19 PM
    0 responses
    2 views
    0 likes
    Last Post Jonker
    by Jonker
     
    Working...
    X