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

Referencing Close if CalculateOnBarClose set to false

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

    Referencing Close if CalculateOnBarClose set to false

    if you have CalculateonBarClose set to false because you want somethings like entry orders to update on each tick, how would you go about referencing the close of a bar (for example) a five minute bar if you are running a strategy on a chart with time interval of 5 minutes

    #2
    Hello fiddy,

    Thank you for writing in.

    What you could do is utilize the FirstTickOfBar property. What this does is check if the incoming tick that called OnBarUpdate() is the first tick of a new bar.

    If this is the case, then print Close[1]. This will return the close value of the most recently closed bar.

    Example:
    Code:
    // if the tick that called OnBarUpdate() is the first tick of a new bar, print the close value of the most recently closed bar
    if (FirstTickOfBar)
         Print(Close[1]);
    More information about FirstTickOfBar can be found here: http://ninjatrader.com/support/helpG...ttickofbar.htm

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      thanks

      if you wanted to reference the open would you also be able to use open[1] in the same context

      if (FirstTickOfBar)
      {
      open[1]
      }

      also if you wanted to reference two bars ago can you use Close[2] or does it not work like that? does this give two ticks ago result?

      Comment


        #4
        Hello fiddy,

        Using Open[1] in that context will provide the open price of the most recently closed bar.

        Close[2] will provide the close value of the close bar two bars ago.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ZacharyG View Post
          Close[2] will provide the close value of the close bar two bars ago.
          You sure about that?

          When COBC=false and FirstTickOfBar is true, you're saying that Close[2] is "close value of the close bar two bars ago"?

          To the OP, try using Closes[0][2] to get the Close price of two bars ago.

          See here:
          Last edited by bltdavid; 04-06-2016, 10:54 AM.

          Comment


            #6
            Hello bltdavid,

            Using ...

            Code:
            if (FirstTickOfBar)
                 Print(Close[2]);
            ... with CalculateOnBarClose = false will print out the close value two bars ago.

            Please take a look at this short demonstration video: http://screencast.com/t/SHHLzZfYbta
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ZacharyG View Post
              Hello bltdavid,

              Using ...

              Code:
              if (FirstTickOfBar)
                   Print(Close[2]);
              ... with CalculateOnBarClose = false will print out the close value two bars ago.

              Please take a look at this short demonstration video: http://screencast.com/t/SHHLzZfYbta
              That's news to me.

              The (very terse) documentation on FirstTickOfBar does not allude to this at all.

              Can you attached your test script used in the video?

              PS: See attached screenshot showing typo in NT8 documentation.
              Attached Files

              Comment


                #8
                Hello bltdavid,

                The script I have used in my demonstration video is attached to this post.

                I will be reporting the typo for IsFirstTickOfBar for the NinjaTrader 8 help guide. Thank you for catching this.
                Attached Files
                Zachary G.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by timmbbo, Today, 08:59 AM
                0 responses
                1 view
                0 likes
                Last Post timmbbo
                by timmbbo
                 
                Started by bmartz, 03-12-2024, 06:12 AM
                5 responses
                33 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by Aviram Y, Today, 05:29 AM
                4 responses
                14 views
                0 likes
                Last Post Aviram Y  
                Started by algospoke, 04-17-2024, 06:40 PM
                3 responses
                28 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by gentlebenthebear, Today, 01:30 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X