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

C# Newbie -- Helpful Percentage Loaded Function

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

    C# Newbie -- Helpful Percentage Loaded Function

    Hey there, just sharing something that might help while you are debugging. I found that when loading intraday I wanted to get a better sense of how much was left to process, so I made this function to do it.

    Code:
            // You can paste this anywhere inside the "public class <your indicator name> : Indicator" block of code, right before the  "protected override void OnStateChange()" block
    
            // Function that displays chart loading progress for debug
            public void chartLoadProgress(string myTimeframe) // Takes "Intraday" or "Daily" edit as needed
            {
                double tempProgress = 0;
                double loadedProgress = 0; // For % loaded counter
                double myBars = 0;
    
                if (myTimeframe == "Intraday")
                {
                    myBars = Convert.ToDouble(CurrentBars[0]);
                }
                else if (myTimeframe == "Daily")
                {    
                    myBars = Convert.ToDouble(CurrentBars[1]);
                }
    
                tempProgress = (myBars / Convert.ToDouble(Count));
                loadedProgress = Math.Round(tempProgress, 2, MidpointRounding.AwayFromZero) * 100;
    
                if (loadedProgress < 100)
                {
                    Print("Chart load progress: " + loadedProgress + "%");
                }
            }​
    To use, just call the function anywhere in the "protected override void OnBarUpdate()" block, optionally you can specify what series you are dealing with, if you're doing multi-timeframe like this:

    Code:
            protected override void OnBarUpdate()
            {
    
                if(BarsInProgress == 0) // Primary intraday bar series
                {
                    chartLoadProgress("Intraday"); // Display loaded percentage​
                }
    
            }
    Of course if you were using it for Daily you'd have it inside a statement like "BarsInProgress == 1" and such... easy enough to edit for your own usage depending on what data series you have.

    Enjoy!

Latest Posts

Collapse

Topics Statistics Last Post
Started by usazencort, Today, 01:16 AM
0 responses
1 view
0 likes
Last Post usazencort  
Started by kaywai, 09-01-2023, 08:44 PM
5 responses
603 views
0 likes
Last Post NinjaTrader_Jason  
Started by xiinteractive, 04-09-2024, 08:08 AM
6 responses
22 views
0 likes
Last Post xiinteractive  
Started by Pattontje, Yesterday, 02:10 PM
2 responses
21 views
0 likes
Last Post Pattontje  
Started by flybuzz, 04-21-2024, 04:07 PM
17 responses
230 views
0 likes
Last Post TradingLoss  
Working...
X