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

Count Ticks

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

    Count Ticks

    Hi everybody
    How can i detect if price is upper than a special amount for 3 continues ticks.
    For example i have 1298 as a constant and want to check the price per tick to detect if the price is greater than 1298 for 3 continues ticks

    #2
    Hello amiralimadadi,

    Thanks for your post.

    There are a few ways this could be accomplished. One way is to use a multi series NinjaScript that adds a single tick data series. If the single tick data series is the first data series added in the NinjaScript code, then the ticks could be referenced with Closes[1][0]. For a complete guide to writing a multi series NinjaScript please refer to the Multi-Time Frame and Instruments documentation page. This information is publicly available and I'll provide a link below.

    Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

    Another way this could be accomplished is by setting the strategy to calculate on each tick and then to check if Close[0] is reaches your price level, and if it does to iterate your counter. When Close[0] is no longer above your price level, reset the counter.

    If you are using the Strategy Builder, this could be done with a series of conditions and enabling the strategy with Calculate On Each Tick. The first condition should check if Close[0] is above a certain price level. If it is, set a bool to true. In another condition, if that bool is true and Close[0] is above that price level, set another bool to true. If the second bool is true and Close[0] is still above a certain price level, then you have detected three consecutive ticks above a price level. When Close[0] drops below the price level, set your bools back to false.

    For a complete guide to using the Strategy Builder, I recommend viewing the Strategy Builder 301 tutorial.

    Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt90GAs9k

    Please let us know if we may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim
      But i am a little bit confused. I think i should use multi time frame, because i want to use 3 series and check the price. But it is not clear for me. each series has its own tick, so where should i write my code? in "onbarupdate" event? or anywhere else. how can i detect which series is calling the event?

      Comment


        #4
        Originally posted by amiralimadadi View Post
        Hi everybody
        How can i detect if price is upper than a special amount for 3 continues ticks.
        For example i have 1298 as a constant and want to check the price per tick to detect if the price is greater than 1298 for 3 continues ticks


        What's the problem ?

        double xy = 1298 ;
        if (Close > xy && Close[1] > xy && Close[2] > xy)
        {
        Print(Time[0] + " Hi I have found 3 ticks ! Are you happy ? );
        // make xyz
        }

        Comment


          #5
          I want to know where i should write this piece of code? in which event?
          because there are 3 series and every series has different ticks, so in which event should i check the prices?

          Comment


            #6
            you need 3 different data series (instruments) ?
            your first question says nothing about this ?

            if there only one instrument, just ad one tick chart data series ...

            if (State == State.SetDefaults)
            {
            ..
            ..
            }
            else if (State == State.Configure)
            {
            AddDataSeries(BarsPeriodType.Tick,1);

            }


            if (BarsInProgress == 1 ) // tick chart code ...
            {

            }
            Last edited by jr123; 04-09-2018, 02:51 AM.

            Comment


              #7
              Originally posted by jr123 View Post
              you need 3 different data series (instruments) ?
              your first question says nothing about this ?

              if there only one instrument, just ad one tick chart data series ...

              if (State == State.SetDefaults)
              {
              ..
              ..
              }
              else if (State == State.Configure)
              {
              AddDataSeries(BarsPeriodType.Tick,1);

              }


              if (BarsInProgress == 1 ) // tick chart code ...
              {

              }
              I have mentioned in the second question that i have 3 data series.
              I want to know in which event i should write this piece of code

              if (BarsInProgress == 1 ) // tick chart code ...
              {

              }

              Comment


                #8

                search for : Alphabetical Reference - BarsInProgress

                i guess you should check every data serie....
                but without more from you ... (what kind of instruments you want check ? why 3 instruments ? )
                i can only guess...

                Comment


                  #9
                  Hello amiralimadadi,

                  Yes, you could put that logic in a check for the BarsInProgress of your 1 tick data series.

                  There are two articles in the Multi Time Frame and Instruments documentation page from my first reply that can provide further direction/explanation.

                  The first article is the "True Event Driven OnBarUpdate() Method" - https://ninjatrader.com/support/help...arupdateMethod

                  This article explains how to set up your OnBarUpdate() logic for different BarsInProgress iterations.

                  The second article is the Accessing Price Data in a Multi-Bars NinjaScript - https://ninjatrader.com/support/help...arsninjascript

                  This article explains how different price data should be referenced when you are using a multi series NinjaScirpt and how the "Close" instead of "Closes" will represent the current iterating data series/BarsInProgress.

                  This document was written to be read from the beginning to the end and provides complete reference for how multi series NinjaScripts should be written and used. If you have any questions on this information, please don't hesitate to ask.
                  JimNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, Today, 06:40 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post algospoke  
                  Started by maybeimnotrader, Today, 05:46 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post maybeimnotrader  
                  Started by quantismo, Today, 05:13 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post quantismo  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  8 responses
                  168 views
                  0 likes
                  Last Post jeronymite  
                  Started by cre8able, Today, 04:22 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X