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:
          http://ninjatrader.com/support/helpG...t7/?closes.htm
          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 ketostrongdiet, Today, 12:34 AM
                0 responses
                6 views
                0 likes
                Last Post ketostrongdiet  
                Started by ketostrongdiet, Today, 12:33 AM
                0 responses
                7 views
                0 likes
                Last Post ketostrongdiet  
                Started by mattdowns1234, Yesterday, 06:57 PM
                0 responses
                16 views
                0 likes
                Last Post mattdowns1234  
                Started by dgee949, Yesterday, 06:26 PM
                0 responses
                26 views
                0 likes
                Last Post dgee949
                by dgee949
                 
                Started by dgee949, Yesterday, 05:58 PM
                0 responses
                32 views
                0 likes
                Last Post dgee949
                by dgee949
                 
                Working...
                X