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

current intra bar. how to code it

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

    current intra bar. how to code it

    there is something i see time in time again. but, i can only take advantage of it if i can program the present bar. is there a way to do that? i don't want to look at [0], or farther back. just the present intra bar. high above a line and price below a line..enter.

    #2
    Hello SteveReiza,

    Thank you for your post.

    To process your script on the currently forming bar, you would reference 0 barsAgo but the script needs to be set to calculate either OnPriceChange or OnEachTick rather than OnBarClose. For more information regarding the Calculate property:


    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      thanks for the reply. i thought 0 bars ago was the most recently closed bar? that was just told to me. in fact i just re-did all my code because of that. i did think that [0] is the current bar that's active.

      i just received explanation that on bars close. that when a determination is made. the execution happens at the start of the next bar not immediately. this conversation led to hearing that 0 bars ago is the most recently closed bar. and [1] is 1 bar ago behind that, etc.

      Comment


        #4
        Originally posted by SteveReiza View Post
        thanks for the reply. i thought 0 bars ago was the most recently closed bar? that was just told to me. in fact i just re-did all my code because of that. i did think that [0] is the current bar that's active.

        i just received explanation that on bars close. that when a determination is made. the execution happens at the start of the next bar not immediately. this conversation led to hearing that 0 bars ago is the most recently closed bar. and [1] is 1 bar ago behind that, etc.
        Hello SteveReiza,

        Thank you for your reply.

        0 bars ago refers to different bars when calculating OnBarClose vs. OnPriceChange/OnEachTick. This is because the calculation determines how frequently OnBarUpdate() is called. When it is only called on bar close, 0 bars ago (the "current bar") is the most recently closed bar. When it is called for every change in price or every tick, it gets called even after the last bar closes and will continue to be called during the currently forming bar which is 0 bars ago (the "current bar").

        For a visual example, you could add an indicator to your chart such as the SMA. Set the indicator to calculate On Bar Close, and you will notice that the indicator only updates once per bar. If you were to print the indicator's value for 0 bars ago, you would get one print on each bar as it closes. Now, change calculate to On Price Change or On Each Tick; the indicator plot will continue to update as the price changes on the currently forming bar. If you were to print the indicator's value for 0 bars ago, there would be a print for each price change or each tick as the current bar (0 bars ago) is continuously forming.

        Thank you for your time and patience.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          thanks for the reply. okay, i'm tracking. the clarification helps. and, that makes sense.

          i did have if low is within so many of bollinger line [2] and then [1] as the candle in respect to the previous. i respects to the previous candle: high greater than high, close greater than close, low greater than open. but on bar close. it wouldn't enter until the next candle so that doesn't make sense. it would be way too late. so i now have it as [1] within so many of the bollinger line. and, [0] as comparison to the candle. will that make sense though? i'm comparing low to previous open and high to previous high and close to previous close on the current bar - that moves and calculates intra bar. its not complete yet, so the low technically could be lower then the previous open at some time during the bar - right? or is it going to wait until the bar is finished since its asking for low, high and close? that's not technically there until after completion of the bar right?

          Comment


            #6
            Hello SteveReiza,

            Thank you for your reply.

            It will not wait for the bar to finish if you are calculating On Price Change or On Each Tick and accessing the Open, High, Low, or Close price. I suggest using prints to get a deeper understanding of how the prices are updated as the bar is forming. You are correct that, since the bar is not complete yet, at some point intrabar the low could become lower than the previous open at some point during the bar.

            If you need to separate some of your logic so that it is calculating intrabar on the price change or on each tick and other logic so that it is calculating on bar close, you could utilize IsFirstTickOfBar in your condition:

            In the Strategy Builder, you can find IsFirstTickOfBar in the Miscellaneous folder and you can check if Misc > IsFirstTickOfBar Equals Misc > True:


            Any set that contains this condition would be processed on the close of a bar instead of continuously calculating intrabar.

            Please let us know if we may be of further assistance.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              thanks for the reply. that might make sense. i'm trying to have [1] and [2] be on bar close. then [0] intra bar. i don't want it to calculate anymore on [1] and [2] after the bar closes. where would i put isfirsttickofbar in that scenario?

              Comment


                #8
                Hello SteveReiza,

                Thank you for your reply.

                I'm not sure exactly what you are referring to. Are you using numbers in brackets as barsAgo indexes? IsFirstTickOfBar would be used for any condition that you only want to be executed on the close of a bar. For example, you could add a print statement that only prints to the NinjaScript Output window once per bar. Here are some prints you could use in a script that updates On Price Change and see the difference between prints on bar close vs. on price change:

                Code:
                // print once on the close of each bar
                if (IsFirstTickOfBar)
                Print(Time[0] + " This print shows once per bar.");
                // print once on each update of the price
                Print(Time[0] + " Price updated. Close[0]: " Close[0]);
                Please let us know if we may be of further assistance.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  thanks for the reply. alright the clarification helps!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by geddyisodin, 04-25-2024, 05:20 AM
                  8 responses
                  58 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by jxs_xrj, 01-12-2020, 09:49 AM
                  4 responses
                  3,285 views
                  1 like
                  Last Post jgualdronc  
                  Started by Option Whisperer, Today, 09:55 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post Option Whisperer  
                  Started by halgo_boulder, 04-20-2024, 08:44 AM
                  2 responses
                  22 views
                  0 likes
                  Last Post halgo_boulder  
                  Started by mishhh, 05-25-2010, 08:54 AM
                  19 responses
                  6,189 views
                  0 likes
                  Last Post rene69851  
                  Working...
                  X