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 Mikey_, 03-23-2024, 05:59 PM
3 responses
49 views
0 likes
Last Post Sam2515
by Sam2515
 
Started by f.saeidi, Today, 12:14 PM
7 responses
16 views
0 likes
Last Post f.saeidi  
Started by Russ Moreland, Today, 12:54 PM
1 response
6 views
0 likes
Last Post NinjaTrader_Erick  
Started by philmg, Today, 12:55 PM
1 response
7 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Started by TradeForge, 04-19-2024, 02:09 AM
2 responses
32 views
0 likes
Last Post TradeForge  
Working...
X