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 ticks of bar?

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

    How to get ticks of bar?

    In MetaTrader, there is two variables for ech bar provided (even for historical):


    tick_volume : how many ticks (trades) happened
    real_volume : how many amount (real volume) traded


    in NT8, for realtime bars, i calculate ticks amount this way:

    Code:
    ticks_thisbar = IsFirstTickOfBar  ? 0 :   ticks_thisbar +1;
    however, i think i am doing wrong, there should be some property/method builtin in NT to get like MetaTrader.

    Whats more, how to get them on historical bars?

    p.s. i might use minute, renko, range charts.

    p.s.2. I am surprised, that in some topics, I see solution like this:

    Code:
    double ticks =(Close[0] - Open[0]) / TickSize );
    how this calculates ticks I cant understand, price may go up and down hundreds of time, and this code is something fake, how it relates to real result?.
    Last edited by ttodua; 05-23-2018, 10:56 AM.

    #2
    Hello TazoTodua,
    Thanks for your post.

    You can use Bars.TickCount to get the total number of ticks in the current bar and Bars.GetVolume(BarIndex) to get the volume of a specific bar index value. For example, the following snippet would print the tick count and current volume of a bar to the output window.
    Code:
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {
    	Print("Current Tick Count = "+Bars.TickCount.ToString());
    	Print("Current Volume     = "+Bars.GetVolume(CurrentBar));
    }
    In regards to the snippet of code you provided; I am not sure what is trying to be accomplished there. I can see how it could potentially be used to determine an up or down tick. What topic specifically are you referring to?

    Help Guide - TickCount

    Help Guide - GetVolume()
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks... but that doesnt work on historical.
      I want for historical bars

      Comment


        #4
        Correct. For Bars.TickCount you must use Calculate.OnEachTick with TickReplay enabled to use it historically.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Hi,
          I know this post is a bit old, but relevant.
          If I want to know the up ticks and volume and the down ticks and volume, possible?
          Morris

          Comment


            #6
            Hello morrnel,

            I don't see up/down ticks in the thread earlier, are you asking about checking for a trend?
            JesseNinjaTrader Customer Service

            Comment


              #7
              Perhaps my question is unrelated to this thread.

              My question is:

              For each tick in a bar, I want to know if up or down, time, volume, price.

              I see in the post how to get the total tick count and total volume.

              Print("Current Tick Count = "+Bars.TickCount.ToString()); Print("Current Volume = "+Bars.GetVolume(CurrentBar));

              Comment


                #8
                Hello morrnel,

                NinjaTrader just keeps track of the Open High Low Close, and Volume of a bar. Analyzing the ticks in a bar would involve tracking each tick as the bar build.

                Processing data in OnBarUpdate is generally done following Calculate.OnBarClose, but if we use Calculate.OnEachTick, we can process each tick of the bar with real-time data. Or, as is mentioned in post #4, Calculate.OnEachTick can be used with Tick Replay to get each tick update inside each bar when we process historical data.

                As you process each tick, comparisons can be made to determine if the tick was an up or down tick.

                If we are processing each tick we could use private class level variables in our script to track the previous tick's value so for each new tick, we would:
                1. Compare with previous tick's value
                2. Count an up tick or a down tick for that bar based on that comparison
                3. Update the "previous tick" values with the current values.
                This is a rough overview: for some values you would also want to reset your variables back to 0 after each new bar is formed.

                IsFirstTickOfBar can show you when we have had the first tick of a new bar, and this could be used to reset variables that would be used for per bar values.

                IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

                JimNinjaTrader Customer Service

                Comment


                  #9
                  I am making good progress figuring all thids out. See the message below: Can i make changees to make the message go away? That is other than stop writing to output.
                  Morris

                  You have reached the maximum threshold of the NinjaScript Output window. Some of your output messages have been suppressed.
                  ===================== Tot Ticks: 30
                  Ask Time: 5/4/2022 6:57:50 PM Price: 4288 Vol: 1

                  Comment


                    #10
                    Hello morrnel,

                    There is not a way to prevent that message, if you need to output more data you can use a C# streamwriter to write to a text file: https://ninjatrader.com/support/help...o_write_to.htm
                    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