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

Question about Bars.TickCount

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

    Question about Bars.TickCount

    Hi,

    I am trying to obtain a measure of the price movement in ticks. And if I use Bars.TickCount, like:

    Draw.TextFixed(this, "Info", "\nNo of ticks: "+Bars.TickCount, TextPosition.TopRight);

    I see that the result with TickCount is really a value that is much higher that the real price movement in ticks. In the following video you can see this. Bars.TickCount increases very quick up to 28 when the real tick-movement of the price is 5-6 ticks.



    So, my question is: Is there any method to obtain the real price movement in ticks?

    Thanks,

    #2
    Hello,

    Thank you for the question.

    The Bars.TickCount would be the total number of ticks of the current bar processing rather than a number of ticks in movement. To get the amount of ticks of price movement, this is something you would need to calculate.

    You could likely store the price of when a bar starts and then subtract the current price to get a difference. The difference you could convert to an amount of Ticks to find the difference in Ticks.

    Here is one example, this assumes the script is running OnEachTick:

    Code:
    private double storedPrice;
    protected override void OnBarUpdate()
    {
    	if(IsFirstTickOfBar)
    	{
    		storedPrice = Close[0];
    	}
    	double ticks = Math.Ceiling((Close[0] - storedPrice) / TickSize );
    	Draw.TextFixed(this, "Info", "\nNo of ticks: "+ticks, TextPosition.TopRight);
    }




    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      This is clear, thanks. But I need to count the number of changes in ticks regardless the direcction of the movement. I mean, imagine that in your example No of ticks have the following values:
      0,1,2,1,0,0,0,0,0,0,-1,-2,-1,0,0,0, so I need to have a counter that tell me the number of changes, in this case: 15 that corresponds with the movement in ticks (the Sum of all ticks movement). I don't know if I have explain me well?.

      I tried to use a conter (int counter) and a boolean (bool changetick), like this:

      TickArray[i]= Math.Ceiling((Close[0] - storedPrice) / TickSize );

      if(i>0)
      {
      if(TickArray[i]!=TickArray[i-1] && !changeTick) {j++; changeTick=true;}
      else changeTick=false;
      }

      if(i>1) Draw.TextFixed(this, "Info", "\n\nMovimiento Ticks: "+j, TextPosition.TopRight);
      i++;

      But the result is not accurate, see the following video to check:



      The counter = 7 but the real times of ticks movement is 10.

      Thanks,

      Comment


        #4
        Hello,

        Thank you for the reply.

        If you are trying to detect when there was a change, you would likely need to store the prior ticks value and then check if the new value is different. If so, increment your counter.

        perhaps something like the following would work for what you are trying?
        Code:
        private int lastTickValue = -1;
        
        if(lastTickValue != Math.Ceiling((Close[0] - storedPrice) / TickSize ))
        {
            i++;
            lastTickValue = Math.Ceiling((Close[0] - storedPrice) / TickSize );
        }

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          If I wish to find out the number of ticks (trades) in the current bar I can use Bars.TickCount. Can this be used with an index to find out the number of ticks in the previous bar such as Bars.TickCount[1] etc?

          Comment


            #6
            Hello,

            Thank you for the post.

            There is no historical collection of tick counts, so this would be something you need to store yourself or do with your own logic. You could look into using a Series<int> to store each bars Tick Count if it is needed later:



            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            20 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            45 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            21 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            181 views
            0 likes
            Last Post jeronymite  
            Working...
            X