Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Weekly pivot levels refresh day

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

    Weekly pivot levels refresh day

    Dear NT team,

    Please take a look at the following attached charts:
    • both charts show 6E daily data with weekly pivots plotted;
    • the chart as of 8am GMT Monday is still plotting weekly pivot levels applicable during the previous week;
    • the chart as of 8am GMT Tuesday is plotting correct levels for the current week.


    The pivots indicator was set to use intraday data in this case, but I believe it does not make a difference if the daily bars option is selected. The same behaviour can be observed for a live connection.

    The expected behaviour is for the weekly pivot levels to refresh starting Sunday market open.

    Regards,
    Roman
    Attached Files

    #2
    Hello Roman,

    Thanks for your note. I have inquired with the NinjaTrader development on the expected behavior.

    I appreciate your patience while wait for a response.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      As far as I can see the pivots were used on a daily chart.

      If you wish to display weekly pivots on a daily chart on Monday, you need to set the indicator to Calculate == Calculate.OnPriceChange.

      If you leave the indicator in Calculate == Calculate.OnBarClose, it will not take into account the last bar of the chart and will still display last week's pivots.

      This is as expected by design.

      Comment


        #4
        Thank you, Harry, you are correct.

        But as a note (probably, for the NT team), this does not seem to be efficient: why waste CPU clock to run the pivots' OBU on every price change/tick (albeit if just to test whether levels have been calculated already)? Why not instead upon Friday bar close (through chart's daily bars series or the nested weekly bar series) calculate new pivots, store as current values and display until changed. I remember coding something like this when daily pivots in earlier NT8 versions had a bug.

        Or is there something I missed why NT should wait for Monday close when using OnBarClose?

        Comment


          #5
          Originally posted by roman_ch View Post
          Thank you, Harry, you are correct.

          But as a note (probably, for the NT team), this does not seem to be efficient: why waste CPU clock to run the pivots' OBU on every price change/tick (albeit if just to test whether levels have been calculated already)? Why not instead upon Friday bar close (through chart's daily bars series or the nested weekly bar series) calculate new pivots, store as current values and display until changed. I remember coding something like this when daily pivots in earlier NT8 versions had a bug.

          Or is there something I missed why NT should wait for Monday close when using OnBarClose?
          Usually indicators calculate values from the current bar. For example if you apply a SMA to the chart, the value of the current bar is used to perform the calculation. If you do not need to recalculate values with every incoming tick, then you simply leave the indicator in mode Calculate == Calculate.OnBarClose, and it will only calculate once per bar.

          The pivots indicator is an exception, as it does NOT use the current bar's value for the calculation. Therefore, if you wish to have it up-to-date on a Monday, you need to set it to Calculate = Calculate.OnPriceChange.

          You are correct that this is inefficient. Also the pivots indicator calls the daily bar's high, low and close with every incoming tick, because due to a NinjaTrader design flaw, yesterday's daily bar cannot be programmatically accessed. But the CPU load it causes should be moderate, as it does little else than updating high, low and close.

          Comment


            #6
            Hello roman_ch,

            I've clarified with my lead that the Pivots indicator does reset the support and resistance values on Sunday.

            If the script is running on an intra-day chart allowing for the script to update before the end of the session, or if the script is running with Calculate set to OnPriceChange or OnEachTick allowing the script to update before the end of the session, that this will cause these values to be reset on Sunday.

            When Calculate is set to OnBarClose, no script will update until the bar closes. If the bar is a daily bar, this update would occur after the open of the next session.

            May I confirm, that you are allowing the script to update while the session is open by using an intra-day chart or that you have Calculate set to OnPriceChange or OnEachTick and that the values are not being reset?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you, Cheslea. Appreciate you taking time to answer. Yes, as I mentioned to Harry, I agree that Weekly pivots are updated if Calculate.OnPriceChange (or tick) is used. We probably could leave it here, but because we all have already invested some time, here are some thoughts after having a better look into the Pivots code.
              1. I believe NT8 rendering is set to 4 FPS. This is very telling for a commercial product, so some attention to improving algorithms should be a good thing (if not a must);
              2. Following on some of the lines in the previous posts, I tried to profile Pivots' OBU. In short, I did not manage to marry properly my profiler’s API with NT, but one observation is that from the whole Indicator family, two f(x)s pop up on the profiler in my setup: TRIX’s OBU and Pivot’s OnRender;
              3. The generic purpose of updating an indicator’s value OnPriceChange (or tick) is to react to the incoming data at the time when the bar is being built. In our case, there is no need to use new incoming data to calculate Weekly pivots when Monday’s bar is being built, all the data is available as of Friday’s close. Accordingly, having an algorithm which requires OBU to fire on each price change so that correct levels are plotted on Monday is inefficient and not a good style. Although given the observation in (2), it seems to be a relatively insignificant waste (as Harry suggested)
              4. The current simplified sequence for calculating Weekly pivots is along the following lines:
                • Get prev HLC
                • Get end date for current week
                • If above date falls after cached date, calculate pivots
                • Save end date as cached date
              5. The sequence in (4) looks at Pivots from now time and asks what has happened in the past (as Harry pointed out). There is another way to look at the problem: recognize that when a daily bar closes, new values can be calculated and saved for future use until change (as I suggested earlier). These are two different solutions. If I was to code, I would try the second one and I am not sure if there are any pitfalls there (does not seem like it)
              6. Given that the algo set out in (4) which is used by NT looks into the past, of course OBU needs to fire for the Monday bar before it is closed to plot correct levels. If one accepts that using OnPriceChange is inefficient, I take it that a mod along the below helps to improve when State >= RealTime:
                • Add a weekly roll-over int flag. If daily bar close Time == session end, flag = CurBar + 1 (otherwise, set to a sentinel value), calc new pivots and store in a member (not Values)
                • If CurBar == flag, copy saved levels into Values, reset flag to sentinel
                • In OnRender, if flag != sentinel, shorten lines to be drawn one day and use stored pivot levels (not Values)


              No doubt, there will be more pressing topics for improvement in NT than the Pivots’ code. However, my view is that a commercial product should not demand users to waste CPU clock to make up for algo design.

              EDIT: NT7, I think, used a negative index to set future plot value, so code would have been very succinct there.

              Kind regards,
              Roman
              Last edited by roman_ch; 03-19-2017, 09:51 AM.

              Comment


                #8
                Hello Roman,

                Thank you for your detail.

                It appears you are making a feature request for specific changes to the Pivots indicator.

                From my understanding, you would like the script to update with OnEachTick or OnPriceChange and have the script continue reusing values and return (and not process) in OnBarUpdate before doing any calculations unless the time is equal to the session close time, is this correct?

                Comment


                  #9
                  Hello Patrick,

                  Thank you. I am not sure what I had in mind is a feature request. The "factory" pivots code is now inefficient and I thought that NT dev team could take a look at that / improve in due course.

                  Just to be clear, what I had in mind is that the weekly pivots should be correctly displayed on Monday on a daily chart even if Calculate == OnBarClose. Currently, weekly pivots are correct on a daily chart with OnEachTick or OnPriceChange (but not with OnBarClose).

                  Personally, I have re-coded the pivots already, but I think that the community would also benefit from a "factory" improvement.

                  Regards,
                  Roman

                  Comment


                    #10
                    Originally posted by roman_ch View Post
                    Personally, I have re-coded the pivots already, but I think that the community would also benefit from a "factory" improvement.
                    Hello roman_ch,

                    Do you mind sharing your re-coded weekly pivot indicator.

                    Comment


                      #11
                      Originally posted by ramos04 View Post
                      Hello roman_ch,

                      Do you mind sharing your re-coded weekly pivot indicator.
                      I have posted below the code I have for weekly pivots on a daily chart. This is for educational purposes only, use (or not) at totally your own risk, no warranties, express or implied.

                      A few comments:
                      1. works with Calculate == OnBarClose;
                      2. uses daily bars closes to calculate levels (no option to use intraday prices, like NT factory indi has) as I do not know when it makes sense to use intraday for futures
                      3. posts values in same series as NT factory BUT Value[0][0] is actually applicable to the next bar (for my purposes, it seemed more CPU-efficient as this adds less instructions in OnRender, which fires relatively frequently, of course)


                      I have not included the actual OnRender() in the file. Please feel free to code yourself or I know NT factory's version of Pivots will fit (I mean it is their code). If you are re-using NT's code, that version has a for loop commented "Loop through visible bars to render plot values" (which is that it does, of course). In respect of that loop:
                      • in the line "double val = Values[seriesCount].GetValueAt(idx - 1);" you must add the highlighted bit to use correct values (to address Values[0][0] actually being applicable to the next bar) ;
                      • NT factory version recalculates endX = chartControl.GetXByBarIndex(ChartBars, lastBarPainted); unnecessarily in the loop. Instead, this line should be cut-pasted directly after the ending curly brace for that loop. And for better visual results, I would add the following additional line of code to extend endX it to the end of the last bar: endX += chartControl.GetBarPaintWidth(ChartBars)/2;. So that one line is gone from the loop and two new are added right after the brace:
                        endX = chartControl.GetXByBarIndex(ChartBars, lastBarPainted);
                        endX += chartControl.GetBarPaintWidth(ChartBars) / 2;


                      Regards,
                      Roman
                      Attached Files

                      Comment


                        #12
                        Roman_ch, thanks for the options

                        For sure I have tried to implement them but my code knowledge couldnt let me. I will pass on this one.

                        Regards

                        Comment


                          #13
                          Originally posted by ramos04 View Post
                          Roman_ch, thanks for the options

                          For sure I have tried to implement them but my code knowledge couldnt let me. I will pass on this one.

                          Regards
                          Just to be clear, I did not include NT's OnRender as I am not sure how publishing this sits with their copyright. You could just open their @Pivots.cs file and it should be fairly easy to see their whole OnRender() code. It just needs one change.

                          Comment


                            #14
                            Originally posted by roman_ch View Post
                            You could just open their @Pivots.cs file and it should be fairly easy to see their whole OnRender() code. It just needs one change.
                            Yes I opened the pivots code and tried to find (Ctrl + F) different words like render, onrender even words from the lines to change like endx and others.

                            In some cases, I would be notified that "The specified text was not found" and in others the closest similar lines that I got to your text were

                            double val = series.Get(idx);
                            int x = ChartControl.GetXByBarIdx(BarsArray[0], idx);
                            int y = ChartControl.GetYByValue(this, val);

                            but even those were not exactly your text ie

                            double val = Values[seriesCount].GetValueAt(idx)
                            endX = chartControl.GetXByBarIndex(ChartBars, lastBarPainted);

                            Now I must be missing some thing because of my lack of code knowledge but I had thought that if I searched (Ctrl + F) and found, then I would simply replace.

                            I have sent you a PM. If you dont mind, lets shift over there.
                            Last edited by ramos04; 04-10-2017, 04:38 PM.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by kempotrader, Today, 08:56 AM
                            0 responses
                            6 views
                            0 likes
                            Last Post kempotrader  
                            Started by kempotrader, Today, 08:54 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post kempotrader  
                            Started by mmenigma, Today, 08:54 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post mmenigma  
                            Started by halgo_boulder, Today, 08:44 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post halgo_boulder  
                            Started by drewski1980, Today, 08:24 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post drewski1980  
                            Working...
                            X