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

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?

                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 tsantospinto, 04-12-2024, 07:04 PM
                          4 responses
                          61 views
                          0 likes
                          Last Post aligator  
                          Started by michi08, 10-05-2018, 09:31 AM
                          3 responses
                          740 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by sightcareclickhere, Today, 01:55 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post sightcareclickhere  
                          Started by Mindset, 05-06-2023, 09:03 PM
                          9 responses
                          258 views
                          0 likes
                          Last Post ender_wiggum  
                          Started by Mizzouman1, Today, 07:35 AM
                          4 responses
                          18 views
                          0 likes
                          Last Post Mizzouman1  
                          Working...
                          X