• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Latest Price - market open/closed

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

    Latest Price - market open/closed

    Hi

    I'm looking to run some code when my indicator opens.

    What I need to do is figure out what the current price is.

    When the market is open - I need to know the last price traded on the last bar and I need to do the same thing when the market is closed.

    The thing I am having difficulty with is that the solutions I have seen so far rely on the use of the Historical flag which isn't going to work when the market is closed (I don't think).

    Cheers

    Pete

    #2
    Can't you just use Close[1]?

    Comment


      #3
      I don't think that will work because I want to run my routine once, based on the last traded price.

      Close[1] is the close of the prior bar, Close[0] is the close of the current bar - but how do I know the current bar is the last one?

      Comment


        #4
        So you just want to get the close price of the last bar of the day?

        Comment


          #5
          If the market is currently open - I want the latest price.

          if the market is currently closed - I want the price the market closed at....

          Comment


            #6
            Then just filter for the time, i.e.:

            if (close of market)
            marketclose = close[0]

            if (market hours)
            close = close[0]

            if (not market hours)
            close = marketclose

            Comment


              #7
              That won't work - any indicator will process all bars on the chart....

              I want to execute this one time only for the latest price, it won't work if I process every bar...

              Seems simple enough - just the closing price off the last bar visible (or from an internal property).

              All methods I've seen so far use the Historical flag.

              Comment


                #8
                Then maybe Bars.GetBar would be what you're looking for?

                http://www.ninjatrader.com/support/h...tml?getbar.htm

                Comment


                  #9
                  Where would such a command go?

                  Think about it - at what point in the execution cycle do you know that all bars are loaded?

                  NinjaScripts execute bar by bar. The problem here is how do you know all bars are loaded, getting the price from the last bar is fine as long as you know you are processing the last bar.

                  This is the issue I believe.

                  Comment


                    #10
                    After doing some testing, it looks like all bars are loaded when

                    CurrentBar == Bars.Count - 1

                    Comment


                      #11
                      That's an interesting way of doing it - I'm going to give that a go.

                      Thanks

                      Comment


                        #12
                        Originally posted by DionysusToast View Post
                        Where would such a command go?

                        Think about it - at what point in the execution cycle do you know that all bars are loaded?

                        NinjaScripts execute bar by bar. The problem here is how do you know all bars are loaded, getting the price from the last bar is fine as long as you know you are processing the last bar.

                        This is the issue I believe.
                        Wherever you want it to go. Just use a date far into the future, and it will always return the index of the last bar on the chart.

                        Comment


                          #13
                          Originally posted by DionysusToast View Post
                          That won't work - any indicator will process all bars on the chart....

                          I want to execute this one time only for the latest price, it won't work if I process every bar...

                          Seems simple enough - just the closing price off the last bar visible (or from an internal property).

                          All methods I've seen so far use the Historical flag.
                          Use a session template with only the market hours?

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Lisa Marshall, 01-25-2020, 04:17 PM
                          1 response
                          9 views
                          0 likes
                          Last Post NinjaTrader_ChrisSch  
                          Started by HiddenPhilosopher, Yesterday, 11:24 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post HiddenPhilosopher  
                          Started by akuntysh, 01-25-2020, 08:42 AM
                          2 responses
                          12 views
                          0 likes
                          Last Post akuntysh  
                          Started by nailz420, Yesterday, 09:15 PM
                          0 responses
                          0 views
                          0 likes
                          Last Post nailz420  
                          Started by ATMtrader0001, Yesterday, 01:27 PM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X