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

how to get tick count for a certain range?

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

    how to get tick count for a certain range?

    Hi,

    I'm developing an indicator that needs to get the total number of tick counts within a specific range.

    For example, if I'm loading a daily bar chart for the last 30 days. I need to count how many ticks there are in total in these 30 daily bars.

    I found Bars.TickCount. But it only returns total number of ticks of current bar. Then how do I return total number of ticks within last 30 bars?

    Thank you!

    #2
    Hello HiddenPhilosopher, thanks for your question.

    That would need to be implemented in the indicator e.g.

    Code:
    public class CountTicks : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    //...
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                }
            }
    
            int tickCounter = 0;
            protected override void OnBarUpdate()
            {
                if(BarsInProgress == 1)
                {tickCounter++;}
    
                if(BarsInProgress == 0)
                {
                    if(CurrentBars[0] % 30 == 0)
                    {
                        Print(tickCounter);
                        tickCounter = 0;
                    }
                }
    
            }
        }
    That's just one way you could do it. There could be many ways though.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rayyyu12, Today, 05:38 PM
    0 responses
    2 views
    0 likes
    Last Post rayyyu12  
    Started by xepher101, Yesterday, 12:19 PM
    2 responses
    28 views
    0 likes
    Last Post xepher101  
    Started by thumper57, Today, 04:30 PM
    0 responses
    4 views
    0 likes
    Last Post thumper57  
    Started by OllieFeraher, 05-09-2024, 11:14 AM
    5 responses
    16 views
    0 likes
    Last Post MisterTee  
    Started by jackiegils, Yesterday, 11:05 PM
    1 response
    11 views
    0 likes
    Last Post marcus2300  
    Working...
    X