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

NEED HELP to count ticks in last 3600 seconds

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

    NEED HELP to count ticks in last 3600 seconds


    Hello,

    I am new in NinjaScript development and I am trying to learn how to code in NinjaScript and because of it I am doing many testing and exercises.
    Currently I have goal to develop indicator which will give Long or Short signals.
    Inputs are:
    AmountOfSeconds = 3600;
    PercentChangeInPrice = 1;
    NumberOfTicks = 100;
    VolumeTraded = 10;

    So signals are:
    Long setup:
    1) In last 3600 seconds price changed at least 1% in positive direction(moving up).
    2) in last 3600 seconds ticks was equal or more then 100.
    3) in last 3600 seconds traded volume was equal or more then 10.
    Short setup:
    reversal of Long setup.

    So my main problem is that I don't know how to find:
    1) exact price 3600 seconds ago.
    2) how many ticks we had in last 3600 seconds.
    3) what was volume 3600 seconds ago.

    Hope someone could help me.

    Thanks in advanced.


    #2
    Hello Revazi123,

    Thanks for your post and welcome to the NinjaTrader forums!

    It appears you have posted twice on the same subject. We will close your other post and add a link to direct anyone reading it to this thread. Going forward please only create one post on a subject.

    To provide relevant answers, can you clarify what type and size are the chart bars that you are applying this strategy script to?
    Last edited by NinjaTrader_PaulH; 11-16-2020, 01:11 PM. Reason: Closed wrong thread, re-opening in Strategy
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello Revazi123,

      Thanks for your post and welcome to the NinjaTrader forums!

      It appears you have posted twice on the same subject. We will close your other post and add a link to direct anyone reading it to this thread. Going forward please only create one post on a subject.

      To provide relevant answers, can you clarify what type and size are the chart bars that you are applying this strategy script to?
      Thanks Paul. I have posted first time here and I will not duplicate posts again. Now what about my problem can you help me?

      Comment


        #4
        Hello Revazi123,

        Thanks for your reply.

        So that we can assist, please advise, "To provide relevant answers, can you clarify what type and size are the chart bars that you are applying this strategy script to?"

        These answers would help put some context with which to answer.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello Revazi123,

          Thanks for your reply.

          So that we can assist, please advise, "To provide relevant answers, can you clarify what type and size are the chart bars that you are applying this strategy script to?"

          These answers would help put some context with which to answer.
          I am using M1 timeframe. Instrument doesn't matters.

          Comment


            #6
            Hello Revazi123,

            Thanks for your reply.

            I will assume that M1 means 1-minute bars and not 1-month bars so if that is incorrect please advise.

            To find the price 60 minutes ago, you can use the price type and use 60 for the bars ago, for example, Close[60] provides the close price 60 minutes ago.


            To find the volume 60 minutes ago, you can use the Volume series and use 60 for the bars ago, for example, Volume[60] provides the volume 60 minutes ago.
            Reference: https://ninjatrader.com/support/help...?getvolume.htm

            Regarding ticks, do you mean changes in price over the hour, so you would want the Min and Max of price over the hour?
            Or do you mean the number of trades made in the hour?


            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_PaulH View Post
              Hello Revazi123,

              Thanks for your reply.

              I will assume that M1 means 1-minute bars and not 1-month bars so if that is incorrect please advise.

              To find the price 60 minutes ago, you can use the price type and use 60 for the bars ago, for example, Close[60] provides the close price 60 minutes ago.
              https://ninjatrader.com/support/help...riceseries.htm

              To find the volume 60 minutes ago, you can use the Volume series and use 60 for the bars ago, for example, Volume[60] provides the volume 60 minutes ago.
              Reference: https://ninjatrader.com/support/help...?getvolume.htm

              Regarding ticks, do you mean changes in price over the hour, so you would want the Min and Max of price over the hour?
              Or do you mean the number of trades made in the hour?

              Yes I meant 1 minute bar.
              Thanks for answer.
              In case if I am trying to use 59 seconds or less then how can I get such information?
              what about ticks I meant numbers. How many ticks we have received in last 3600 seconds. Seconds is Key for me. So sorry that I made misunderstood you and for better example instead of 3600 seconds lets use 59 seconds so its mess then 1 minute bar. I need whole information work based on Seconds. Thats why I couldn't made it work using Close[X] and Volumen[X].

              Thanks.
              Last edited by Revazi123; 11-17-2020, 09:50 AM. Reason: https://ninjatrader.com/support/helpGuides/nt8/?priceseries.htm

              Comment


                #8
                Hello Revazi123,

                Thanks for your reply.

                If I understand correctly you now want the information based on 59 seconds.

                The price of 59 seconds ago
                The Volume of 59 seconds ago.
                The number of ticks (transactions) in the last 59 seconds?

                Do I understand correctly?
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_PaulH View Post
                  Hello Revazi123,

                  Thanks for your reply.

                  If I understand correctly you now want the information based on 59 seconds.

                  The price of 59 seconds ago
                  The Volume of 59 seconds ago.
                  The number of ticks (transactions) in the last 59 seconds?

                  Do I understand correctly?
                  Yes exactly. You understood it correctly

                  Comment


                    #10
                    Hello Revazi123,

                    Thanks for your reply.

                    What I would suggest is to run your script using the setting of Calculate.OnEachTick. With live data, this will allow you to capture all of the events you need.

                    You would need to add a 1 tick dataseries so that you can capture all of the ticks within the specified time period. This will create the script as a multi-series/time frame script. There is significant changes needed to work with multi series and I highly recommend you review the complete section here: https://ninjatrader.com/support/help...nstruments.htm

                    You can use the system bool IsFirstTickOfBar as a means to start your counters/accumulators/values when the primary series (the 1 minute chart bars) has triggered the bool (new bar).

                    I assume that in this case, the Open price meets your needs for the price 59 seconds ago of the 1 minute bar. The current price, while the bar is forming, would actually be the value of the Close[0]

                    When the first tick of the bar is true, you would save the open[0] price (or just use Open[0] later as it will not change within the bar), reset your tick counter (an int variable) to 1 (for the first tick).

                    While the time is between the first tick of the bar and the 59th second of the bar, you increment your tick counter on each tick (as that is how often your script will run with Calculate.OnEachTick).

                    On the 59th second, you can then compare the current price which would be Close[0] to the Open[0] price, you can pull the Volume[0] which would be the accumulated volume of that bar (I am unsure what you want to compare it to as the volume starts at 0 for each bar).

                    To trigger on the 59th second you would need to compare the current 1 tick bar time to the close time of the current 1-minute (which will be the 1-minute close time) bar minus 1 second Times[0][0].addseconds(-1).

                    References:






                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_PaulH View Post
                      Hello Revazi123,

                      Thanks for your reply.

                      What I would suggest is to run your script using the setting of Calculate.OnEachTick. With live data, this will allow you to capture all of the events you need.

                      You would need to add a 1 tick dataseries so that you can capture all of the ticks within the specified time period. This will create the script as a multi-series/time frame script. There is significant changes needed to work with multi series and I highly recommend you review the complete section here: https://ninjatrader.com/support/help...nstruments.htm

                      You can use the system bool IsFirstTickOfBar as a means to start your counters/accumulators/values when the primary series (the 1 minute chart bars) has triggered the bool (new bar).

                      I assume that in this case, the Open price meets your needs for the price 59 seconds ago of the 1 minute bar. The current price, while the bar is forming, would actually be the value of the Close[0]

                      When the first tick of the bar is true, you would save the open[0] price (or just use Open[0] later as it will not change within the bar), reset your tick counter (an int variable) to 1 (for the first tick).

                      While the time is between the first tick of the bar and the 59th second of the bar, you increment your tick counter on each tick (as that is how often your script will run with Calculate.OnEachTick).

                      On the 59th second, you can then compare the current price which would be Close[0] to the Open[0] price, you can pull the Volume[0] which would be the accumulated volume of that bar (I am unsure what you want to compare it to as the volume starts at 0 for each bar).

                      To trigger on the 59th second you would need to compare the current 1 tick bar time to the close time of the current 1-minute (which will be the 1-minute close time) bar minus 1 second Times[0][0].addseconds(-1).

                      References:





                      Thanks for your help. I will check everything and get back to you. Thanks again.

                      Comment


                        #12
                        I have still all 3 issues:
                        1) I can't get numbers of ticks.
                        2) I can't get price change.
                        3) I can't get volume.

                        Now I will try my best to explain everything in details as much as I can.
                        For example I am using this indicator on 5 minute bars timeframe. but my setting for timer is 55 seconds. In this case I want to count numbers of ticks in last 55 seconds. price change in last 55 seconds and volumes traded in last 55 seconds. So for me timeframe on what I will use this indicator doesn't matters I want to get those details by seconds.
                        Attached Files

                        Comment


                          #13
                          Hello Revazi123,

                          Thanks for your reply.

                          Please note that we do not provide programming or debugging services. If you would like something created for you, we can provide a link to 3rd party programmers who can meet your needs.

                          Using a 5 minute bar would require something a bit different but much the same as I previously advised.

                          You would need to add a 1 tick series.

                          You would need to code according to the references previously provide for Multi series/time frame. IE: handling BarsInProgress and appropriate accessing Closes, Volumes, etc.

                          Instead of triggering on the first tick of the bar as discussed with 1 minute bars, you would need to compare the time of the current tick (from the 1 tick series) to the chart bar time minus 55 seconds. The first time that condition is true would be the trigger to set your variables to the current bar volume, the current price, set your tick count variable to zero and a once per bar bool to false. You would also increment your tick counter.

                          Once the current bar closes and the first tick of next bar begins, IsFirstTickOfBar will be true and you can then compare the saved bar volume from 55 seconds ago to the finished bar volume from the previous bar, you can then compare the saved price to the previous bar close price, you can then review the previous bars tick count.
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_PaulH View Post
                            Hello Revazi123,

                            Thanks for your reply.

                            Please note that we do not provide programming or debugging services. If you would like something created for you, we can provide a link to 3rd party programmers who can meet your needs.

                            Using a 5 minute bar would require something a bit different but much the same as I previously advised.

                            You would need to add a 1 tick series.

                            You would need to code according to the references previously provide for Multi series/time frame. IE: handling BarsInProgress and appropriate accessing Closes, Volumes, etc.

                            Instead of triggering on the first tick of the bar as discussed with 1 minute bars, you would need to compare the time of the current tick (from the 1 tick series) to the chart bar time minus 55 seconds. The first time that condition is true would be the trigger to set your variables to the current bar volume, the current price, set your tick count variable to zero and a once per bar bool to false. You would also increment your tick counter.

                            Once the current bar closes and the first tick of next bar begins, IsFirstTickOfBar will be true and you can then compare the saved bar volume from 55 seconds ago to the finished bar volume from the previous bar, you can then compare the saved price to the previous bar close price, you can then review the previous bars tick count.
                            Thanks. I have done what I wanted. Thanks again. Bye

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by cmtjoancolmenero, Yesterday, 03:58 PM
                            11 responses
                            42 views
                            0 likes
                            Last Post cmtjoancolmenero  
                            Started by FrazMann, Today, 11:21 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post FrazMann  
                            Started by geddyisodin, Yesterday, 05:20 AM
                            8 responses
                            52 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by DayTradingDEMON, Today, 09:28 AM
                            4 responses
                            27 views
                            0 likes
                            Last Post DayTradingDEMON  
                            Started by George21, Today, 10:07 AM
                            1 response
                            22 views
                            0 likes
                            Last Post NinjaTrader_ChristopherJ  
                            Working...
                            X