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 crazyhorse2393, Today, 03:31 PM
                          1 response
                          3 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by wooofad, Today, 02:56 PM
                          1 response
                          11 views
                          0 likes
                          Last Post NinjaTrader_Kate  
                          Started by jalley, Today, 02:29 PM
                          1 response
                          4 views
                          0 likes
                          Last Post NinjaTrader_Kate  
                          Started by dtl-saw, Today, 02:53 PM
                          1 response
                          8 views
                          0 likes
                          Last Post NinjaTrader_ChrisL  
                          Started by wildwex, Today, 01:43 PM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_ChristopherJ  
                          Working...
                          X