Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get Open price of Current Live bar of higher timeframe

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

    Get Open price of Current Live bar of higher timeframe

    Hello, I am working with multi data series solution, and want to know whether current daily, weekly and monthly bar is green or red.

    How can I get the value of current Live bar of open (for this month - open of live bar, i.e. October, for this week - open of live bar, i.e. open of this Monday, for this day - open of today).

    ​​​I am using Calculate on bar close, so Open[0] would not work, as it would refer to the most recent closed bar.

    #2
    Hello UltraNIX,

    Thanks for your post.

    A green bar is when the Close is greater than the Open, and a red bar is when the Close is less than the Open.

    You could consider adding a daily, weekly, and monthly data series to your script, and then either checking the corresponding Opens[BarisInProgressIndex][0] and Closes[BarisInProgressIndex][0], or you can check Open[0] and Close[0] in a BarsInProgress check corresponding to your added daily, weekly, and monthly data series.

    BarsInProgress is 0 when the primary data series is processing and BarsInProgress will be 1 for the first added data series, and so on.

    Please be sure to review our Multi Time Frame and instruments documentation for how to add additional data, how to reference that data, and how to use BarsInProgress.

    Multi Time Frame and Instruments (Important Read!) - https://ninjatrader.com/support/help...nstruments.htm

    Please also note that if the script is processing OnBarClose, we will not see a developing Daily, Weekly, or Monthly bar. You may wish to use OnPriceChange to be able to reference these bars as they are developing.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      That is the catch. Suggest me a workaround to get a developing (month/week/day) bar WITH CALCULATE ON BAR CLOSE.

      With indicator? With another strategy? I am sure this is not a rocket science, so there should be a workaround.

      It's basic logic. Why else would you want to use multiple time frame feature, if you cannot access the developing bar?

      Comment


        #4
        Hello UltraNIX,

        You need to use Calculate.OnPriceChange or Calculate.OnEachTick to get values of developing bars.

        You can recreate OnBarClose logic when using Calculate.OnPriceChange or Calculate.OnEachTick by checking IsFirstTickOfBar and referencing 1 bar ago. (This is the first tick of a new bar which is the same signal for a bar closure, and we are referencing the previous bar instead of the current bar.)

        IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

        This would be the path towards your goal.

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          All my strategies run with On Bar Update and I don't want to mess it around.

          My idea was to add smaller data series, like daily and then scratch my head how to reference the correct daily bar for weekly/monthly.

          There I need your assistance - for weekly, I could use weekday name and then subtract number of days to get monday's open, if current day is not monday. But how to reference 1st day of the month?

          Comment


            #6
            Another idea is to create indicator that would calculate OnPriceChange and then call it in strategy that calculates OnBarUpdate. Is that possible?

            Comment


              #7
              Hello UltraNIX,

              I still recommend using Calculate.OnPriceChange and adjusting your strategy logic accordingly to put it in a IsFirstTickOfBar check, and then to add 1 to all of your BarsAgo references there in.

              Your proposal from post #5 will be difficult because you would have to account for holidays and will need to use variables to check if you have started processing a bar with a timestamp that is a new month or a new week. If you want to go down this road, you could look further into DateTime properties (Time[0] is a DateTime object) so you can differentiate a new month or a new week.

              I.E. You can use variables to check when Time[0].Month changes to identify a new month, but identifying the first day of a week will be more difficult as you will also have to consider holidays as Monday may not be the first trading day of the week.

              DateTime (publicly available resource) - https://docs.microsoft.com/en-us/dot...ew=netcore-3.1

              Your proposal in post #6 would not be possible because hosted indicators inherit the Calculate mode of the hosting script. See Calculate documentation.

              Calculate - https://ninjatrader.com/support/help...?calculate.htm

              We look forward to assisting.
              JimNinjaTrader Customer Service

              Comment


                #8
                Hello UltraNIX,

                What's the timeframe of your primary series? Hopefully smaller than daily.
                At which point in time do you need the respective Open of 1) Day, 2) Week and 3) Month? During the first bar of your primary series already or only as of the close of such first bar?
                If during already, then you don't have much choice. If only as of the first close, you can leverage the DateTime properties.

                Originally posted by NinjaTrader_Jim View Post
                Hello UltraNIX,
                ...
                Your proposal from post #5 will be difficult because you would have to account for holidays and will need to use variables to check if you have started processing a bar with a timestamp that is a new month or a new week. If you want to go down this road, you could look further into DateTime properties (Time[0] is a DateTime object) so you can differentiate a new month or a new week.
                I.E. You can use variables to check when Time[0].Month changes to identify a new month, but identifying the first day of a week will be more difficult as you will also have to consider holidays as Monday may not be the first trading day of the week.
                ...
                Holidays from the trading hour template don't reach back very far, and it makes perfect sense to create your own list and loop through the data if you want to build more advanced code, but do you really need the holidays for what you are trying to achieve? Perhaps you could start with just indirectly identifying holidays? Holidays are weekdays for which no market data is available b/c the exchange is closed :-).

                With a few bools and variables and a routine running daily after the first bar of your primary series closed, you should be able to grab what you need.

                As soon as the first bar of the day closes and the day of current bar differs from the day of the previous bar, you have identified a new trading day, the Open of day is available and can be logged.
                Same logic (month of current bar differs from month of previous bar) can be applied to identify the break and log the Open of the month.

                To catch the open of the week is not a rocket science either. If the int of the workday of primary series Open [0] is
                1) lower than the int of the workday of Open [1], and
                2) greater or equal to one,
                you have identified the Open of a new week, no matter if the new trading week starts on a Monday or not, (Monday = 1, Friday = 5).

                Easy, yet effective. The attachments illustrate the outcome using hourly bars (and extensive printing to the Output Window).

                With your variables DailyOpen, WeeklyOpen and MonthlyOpen, you have all you need. Just compare these values with the current close of your primary series on each bar update and you will be able to tell for each of them if they are currenty green or red at any point in time.

                Have fun.
                NT-Roland
                Attached Files

                Comment


                  #9
                  Originally posted by NT-Roland View Post
                  Hello UltraNIX,

                  What's the timeframe of your primary series? Hopefully smaller than daily.
                  At which point in time do you need the respective Open of 1) Day, 2) Week and 3) Month? During the first bar of your primary series already or only as of the close of such first bar?
                  If during already, then you don't have much choice. If only as of the first close, you can leverage the DateTime properties.



                  Holidays from the trading hour template don't reach back very far, and it makes perfect sense to create your own list and loop through the data if you want to build more advanced code, but do you really need the holidays for what you are trying to achieve? Perhaps you could start with just indirectly identifying holidays? Holidays are weekdays for which no market data is available b/c the exchange is closed :-).

                  With a few bools and variables and a routine running daily after the first bar of your primary series closed, you should be able to grab what you need.

                  As soon as the first bar of the day closes and the day of current bar differs from the day of the previous bar, you have identified a new trading day, the Open of day is available and can be logged.
                  Same logic (month of current bar differs from month of previous bar) can be applied to identify the break and log the Open of the month.

                  To catch the open of the week is not a rocket science either. If the int of the workday of primary series Open [0] is
                  1) lower than the int of the workday of Open [1], and
                  2) greater or equal to one,
                  you have identified the Open of a new week, no matter if the new trading week starts on a Monday or not, (Monday = 1, Friday = 5).

                  Easy, yet effective. The attachments illustrate the outcome using hourly bars (and extensive printing to the Output Window).

                  With your variables DailyOpen, WeeklyOpen and MonthlyOpen, you have all you need. Just compare these values with the current close of your primary series on each bar update and you will be able to tell for each of them if they are currenty green or red at any point in time.

                  Have fun.
                  NT-Roland
                  Wow. It is all I need. Can you share your code from the script that you have in screenshots?

                  Also. Does ir work with OnBarUpdate or does it need OnPriceChange/OnEachTick?

                  My primary series is 900 ticks for MES and 2000 ticks for ES. However, when I am backtesting setups on higher timeframes, be it weekly/monthly, I want this multiple timeframe stuff to work down to lower timeframes.
                  Last edited by UltraNIX; 10-17-2020, 12:53 PM.

                  Comment


                    #10
                    Hi UltraNIX,
                    It works OnBarUpdate with Calculate.OnBarClose and relevant data points realized as of strategy activation are available as of the close of the first bar close each day.
                    The higher the timeframe you use, the longer you have to wait until you can log the Open of the Day, etc. unless you use a small timeframe for the drum beat (OnBarUpdate) and the longer timeframe (or/and dataseries) for your strategy signals.
                    Yes, I would be willing to share the code with you via PM. I trust, you don't mind sharing back what you do with this info in your strategy once you had the chance to verify the code.
                    NT-Roland
                    Attached Files
                    Last edited by NT-Roland; 10-17-2020, 03:45 PM. Reason: Added screenshots evidencing that data points don't change irrespective of duration of bar type, here 900 Ticks vs. 1H

                    Comment


                      #11
                      Deal! I sent you a PM.

                      Comment


                        #12
                        Wonderful. I did the same. Let me know if questions.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by localappleseed, Today, 09:51 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post localappleseed  
                        Started by wehewwehd, Today, 09:13 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post wehewwehd  
                        Started by aaajv, Yesterday, 06:45 AM
                        3 responses
                        21 views
                        0 likes
                        Last Post NinjaTrader_ThomasC  
                        Started by asmmbillah, Today, 08:13 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post asmmbillah  
                        Started by Bionian, Today, 07:07 AM
                        2 responses
                        7 views
                        0 likes
                        Last Post Bionian
                        by Bionian
                         
                        Working...
                        X