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

most recent closed bar

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

    most recent closed bar

    As with swing where 0 is the most recent pivot, is Close[0] the same, basically it's the close of the most recent completed bar?

    So if it's 9:37am and I'm using 5min bars, would Close[0] give me the close price at 9:35am?

    #2
    Hi Zachj,

    This will depend on the CalculateOnBarClose and what it's set to.

    If this is set to true, then yes the Close[0] would be the 9:35 bar while the bar being built would be the 9:40 bar.

    If this is set to false then the Close[0] will be the 9:40 bar.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Yes I meant to state COBC = true. Then my second part of the question is, with the SMA's for the most recent closed SMA value I would have to use 1 instead of 0 I believe?

      So again if it's 9:37am, 5min bars, cobc true, SMA()[1] would give the SMA value at 9:35? Or would I use SMA()[0]?

      Comment


        #4
        SMA()[0] would give you the 9:35 bar in this case
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Sorry one more. If I have cobc true how do I get the current high of the daily bar in progress? If my primary bar is a daily bar I can't say High[0] for cobc true because the daily candle hasn't closed yet.

          Comment


            #6
            Zachj,

            You would have to switch to COBC false in order to get the current day's high for the scenario you described. If you need to run the rest of the code with COBC set to true, you can use a filter condition for first tick of bar to simulate this -

            Code:
            if(FirstTickOfBar)
            {
                 //rest of the strategy goes here...
            }
            http://www.ninjatrader.com/support/h...ttickofbar.htm
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              I'm backtesting though so it's always going to be cobc true

              Comment


                #8
                Zachj,

                With the Strategy Analzyer you would not be able to grab that most current bar like with the chart.
                However, using an intrabar granularity would be able to help simulate that COBC set to false. Link is below on a reference sample -
                http://www.ninjatrader.com/support/f...ead.php?t=6652
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Ok that's what I figured.

                  In the guide for CrossAbove they say below that the last bar is 1 that's only if cobc is set to false right? If it was set to true the last bar would be the 0 bar? They don't specify. Just want to make sure I'm solid on this.

                  // Go long if 10 EMA crosses above 20 EMA within the last bar
                  if (CrossAbove(EMA(10), EMA(20), 1))
                  EnterLong();

                  Comment


                    #10
                    The last bar is referring the number of bars to look back which must be a minimum of 1 bar. This is because it needs to test when the data series was either greater than or less than that second data series and then the current bar is greater than or less than that second dataseries.

                    We define a CrossAbvoe as --
                    Code:
                    if (dataseries1[1] < dataseries 2[1] && dataseries1[0] >= dataseries2[0])
                    Cal H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by WeyldFalcon, 12-10-2020, 06:48 PM
                    14 responses
                    1,426 views
                    0 likes
                    Last Post Handclap0241  
                    Started by Barry Milan, Today, 10:35 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post Barry Milan  
                    Started by DJ888, Yesterday, 06:09 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    40 views
                    0 likes
                    Last Post jeronymite  
                    Started by bill2023, Today, 08:51 AM
                    2 responses
                    16 views
                    0 likes
                    Last Post bill2023  
                    Working...
                    X