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

Indicator's PriorDayOHLC().PriorClose[0]

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

    Indicator's PriorDayOHLC().PriorClose[0]

    I want to get this value: priorOpenPrice0 = PriorDayOHLC().PriorClose[0]; for a specific indicator (the last indicator value for the day before).
    How can I get that?

    #2
    Hello dafonseca,

    Thanks for your post.

    If I understand correctly, you want to obtain the value of an indicator on the last bar of the session.

    Here is a code example, using the SMA indicator

    if (Bars.FirstBarOfSession)
    {
    double yesterdaysEndingSMA = SMA[1]; // save the prior sma value on first bar of new session.
    }

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      If I understood, this will get the first bar value of the current session. What I want is the last bar value of the previous session.

      Comment


        #4
        Hello dafonseca,

        Thanks for your reply.

        I apologize for not explaining the logic better.

        This statement: if (Bars.FirstBarOfSession) will be true on the very first bar of the session.

        This statement: double yesterdaysEndingSMA = SMA[1]; will get the previous SMA value and put it in the double variable yesterdaysEndingSMA. This was just an example indicator.

        Please note that SMA[0] would be the current bar so if the current bar is the first bar of the session that would mean the the prior bar [1] is the last bar of the previous session. You could apply the logic to any indicator.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          now I see.

          In case I am using a indicator such as:
          ncatHistoricalVolatility("6229", 40, false, 1, PeriodType.Minute)

          Can I use
          ncatHistoricalVolatility("6229", 40, false, 1, PeriodType.Minute)[1]
          ??

          Comment


            #6
            Hello dafonseca,

            Thanks for your reply.

            I'm sorry, I have no knowledge of that indicator but if it outputs on a bar to bar basis then I suspect it will.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              I will check, But one more question:
              regarding (Bars.FirstBarOfSession)

              how can I be sure that (Bars.FirstBarOfSession) will consider the right value.

              In case of backtesting, for instatnce, does (Bars.FirstBarOfSession) consider the first bar of each session??
              supposing I am runing my strategy on a 5 days chart, will (Bars.FirstBarOfSession) updated all five days' sessions?

              Comment


                #8
                Hello dafonseca,

                Thanks for your reply and great questions.

                When you load an indicator or strategy (backtesting, market replay, live data) it will start at very first bar of the data series and work from left to right ending at the current bar on the chart. As it moves from the end of one session to the beginning of the next the bool FirstBarOfSession will be true for the duration of the first bar.

                You can validate this yourself by adding print statements and observing the data printed in the output window, something like:

                if (Bars.FirstBarOfSession)
                {
                Print ("FirstBarofSession: "+Time[0]); //print the date/time of the first bar of the session as it occurs
                }
                if you had 5 days of data, you would likely see 4 - 5 prints.
                Paul H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jxs_xrj, 01-12-2020, 09:49 AM
                4 responses
                3,281 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 geddyisodin, 04-25-2024, 05:20 AM
                8 responses
                58 views
                0 likes
                Last Post NinjaTrader_Gaby  
                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