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

Daily WMA

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

    Daily WMA

    The attached indicator attempts to display a daily WMA on an intraday chart.

    To test I add this and a standard WMA indicator to a daily chart and compare.

    When I add the attached DailyWMA to a daily chart and compare it with a WMA the DailyWMA its a day out.

    I don't understand why it's happening?

    Any help appreciated.
    Attached Files

    #2
    Originally posted by futurenets View Post
    The attached indicator attempts to display a daily WMA on an intraday chart.

    To test I add this and a standard WMA indicator to a daily chart and compare.

    When I add the attached DailyWMA to a daily chart and compare it with a WMA the DailyWMA its a day out.

    I don't understand why it's happening?

    Any help appreciated.
    You have
    Code:
    CalculateOnBarClose = false;
    That means that the current bar of the calling indicator is reflecting the last valid value of the called indicator, which would be the value of the Plot on the last tick event of the called indicator, which event occurred on the previous bar, as the called indicator has COBC = true by default.

    Comment


      #3
      ok thanks but still don't understand why?

      I'm probably missing your point here but to help clarify ...

      I didn't think COBC affected historical values i.e. they're always the same closing values hence WMA [1] historical plot is the same with COBC = True or False.

      Thanks for helping.

      COBC Definition

      · When indicators or strategies are running on historical data, OnBarUpdate() is only called on the close of each historical bar even if this property is set to false. This is due to the fact that with a historical data set, only the OHLCVT of the bar is known and not each tick that made up the bar.
      Last edited by futurenets; 02-15-2015, 11:32 AM.

      Comment


        #4
        Originally posted by futurenets View Post
        ok thanks but still don't understand why?

        I'm probably missing your point here but to help clarify ...

        I didn't think COBC affected historical values i.e. they're always the same closing values hence WMA [1] historical plot is the same with COBC = True or False.

        Thanks for helping.

        COBC Definition

        · When indicators or strategies are running on historical data, OnBarUpdate() is only called on the close of each historical bar even if this property is set to false. This is due to the fact that with a historical data set, only the OHLCVT of the bar is known and not each tick that made up the bar.
        Which is exactly what I said. No?

        Your CALLING indicator must display something on every tick because it has COBC = false, so is calling the CALLED indicator on every tick. The CALLED indicator has COBC = true by default, so the value it passes back to the CALLING indicator is the last value on the closed bar (which is a historical bar).
        Last edited by koganam; 02-15-2015, 12:50 PM.

        Comment


          #5
          thank you for your patience. clearly this is obvious to yourself but unfortunately not to me.

          perhaps I need to understand how NT executes a script when COBC = True and COBC = False

          or is it

          COBC = True: execute the script on each closing bar to calculate a new indicator value, before this time its N/A

          COBC = False: execute script on each closing bar to calculate a new indicator value, before then use the previous indicator value?

          still not sure.

          as far as I was concerned the script calculates a new value for each historical bar based on the bars close whatever COBC is.

          if you have the patience to expand on this I look forward to hearing from you.

          Comment


            #6
            maybe this helps

            Top chart uses DailyWMA COBC= False (plus daily bar object)
            Bottom chart uses std WMA COBC=False (when True last bar = N/A all else same)

            I just think I just need to understand more about how NT processes scripts.
            Attached Files
            Last edited by futurenets; 02-15-2015, 02:34 PM.

            Comment


              #7
              Hello futurenets,

              Thank you for your post

              COBC = True means that the code is processed on the close of the bar. COBC = False means the code is calculating on each incoming tick - but historically it would be on each close of the bar.

              Within your DailyWMA you have set the code to only process on the FirstTickOfBar, this means no matter if you set COBC = True or False the code is going to process at the close of the previous bar (as a new tick also closes the previous bar) and thus the value is from the previous bar.

              Remove your if(FirstTickOfBar) condition and test again.

              Comment


                #8
                ok thanks Patrick. all that made sense but unfortunately I'm still a day out (see attached).

                FirstTickOfBar removed, COBC false on both.

                Thanks for help.

                Hoping it's me and the penny hasn't dropped yet but I just can't see how each indicator on bar[1] uses exactly the same closing values but arrives at (or plots) a different answer?
                Attached Files
                Last edited by futurenets; 02-16-2015, 05:34 AM.

                Comment


                  #9
                  Originally posted by futurenets View Post
                  ok thanks Patrick. all that made sense but unfortunately I'm still a day out (see attached).

                  FirstTickOfBar removed, COBC false on both.

                  Thanks for help.

                  Hoping it's me and the penny hasn't dropped yet but I just can't see how each indicator on bar[1] uses exactly the same closing values but arrives at (or plots) a different answer?
                  Let us reboot then. As there is no other way that I can think of explaining it, instead of saying that you do not understand what is happening, you tell us what you are expecting to see, that you are not seeing.

                  Comment


                    #10
                    ok thanks

                    Ultimately I'm attempting to display a daily WMA on an intraday chart.

                    To test I add the attached dailyWMA and a standard WMA indicator to a daily chart and would like them to be the same.
                    Attached Files

                    Comment


                      #11
                      Hello futurenets,

                      Thank you for your response.

                      Set the DailyWMA value inside the Daily bar update:
                      Code:
                      			if(BarsInProgress == 1)
                      			{
                      				if (CurrentBars[1] == 0)
                      				{
                      					dailyWMA1 = Closes[1][0];
                      				}
                      				else
                      				{
                      					int		back	= Math.Min(MAPeriod-1, CurrentBars[1]);
                      					double	val		= 0;
                      					int		weight	= 0;
                      					for (int idx = back; idx >= 0; idx--)
                      					{
                      						val		+= (idx+1) * Closes[1][back - idx];
                      						weight	+= (idx+1);
                      					}
                      					dailyWMA1 = val / weight;
                      					WMADaily.Set(dailyWMA1);
                      				}
                      			}
                      //			else if(BarsInProgress == 0)
                      //			{
                      //				WMADaily.Set(dailyWMA1);
                      //			}

                      Comment


                        #12
                        ok perfect.

                        I'll try and figure out why?

                        Comment


                          #13
                          Originally posted by futurenets View Post
                          ok thanks

                          Ultimately I'm attempting to display a daily WMA on an intraday chart.

                          To test I add the attached dailyWMA and a standard WMA indicator to a daily chart and would like them to be the same.
                          So you have a calling indicator called "DailyWMA", in which you have chosen to say: "calculate a value of every tick that comes in".
                          You have this "DailyWMA" speaking to another indicator called WMA, which is set by default to "Calculate only once, at the close of the bar".

                          For the sake of trying to explain things, it would not matter if there are 10 or 10,000 ticks in the current, now building bar, so let us just use 5 ticks, for grins and giggles. Here is the conversation between your objects for those 5 ticks.

                          Tick1:
                          DailyWMA: Hey there, WMA, what is your value?
                          WMA: DailyWMA, I only calculate at the close of a bar, so my value is the value at the last historical bar, which is the most recently closed bar.

                          Tick2:
                          DailyWMA: Hey there, WMA, what is your value.
                          WMA: DailyWMA, I only calculate at the close of a bar, so my value is the value at the last historical bar, which is the most recently closed bar.

                          Tick3:
                          DailyWMA: Hey there, WMA, what is your value.
                          WMA: DailyWMA, I only calculate at the close of a bar, so my value is the value at the last historical bar, which is the most recently closed bar.

                          Tick4:
                          DailyWMA: Hey there, WMA, what is your value.
                          WMA: DailyWMA, I only calculate at the close of a bar, so my value is the value at the last historical bar, which is the most recently closed bar.

                          Tick5:
                          DailyWMA: Hey there, WMA, what is your value.
                          WMA: DailyWMA, I only calculate at the close of a bar, so my value is the value at the last historical bar, which is the most recently closed bar.

                          IOW, the called indicator, WMA will always return the same value, because no new value will be calculated until the current bar closes.

                          If you want the called indicator to calculate values on the current building bar, then you MUST set its CalculateOnBarClose property to false, so that it would do so. One way is to repeat the calculations into your calling indicator, as NT Support has written. The other way is to use OOP principles: make your called indicator a named instance in the calling indicator, then set the CalculateOnBarClose property of the named instance indicator to false.

                          Comment


                            #14
                            no DailyWMA does not call WMA.

                            I guess my confusion lies in why historical barsinprogress 1 is one bar behind historical barsinprogress 0?
                            Last edited by futurenets; 02-16-2015, 12:37 PM.

                            Comment


                              #15
                              Originally posted by futurenets View Post
                              no DailyWMA does not call WMA.

                              I guess my confusion lies in why historical barsinprogress 1 is one bar behind historical barsinprogress 0?
                              OK. Then. I was talking at cross purposes.

                              However, the answer to your question is still the same. The last historical value on the daily chart was calculated on the daily chart, so querying its value today will return the value on the daily chart, calculated at the close of yesterday. Any intraday historical bar would be a bar calculated today. They are not even the same entity.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by benmarkal, Yesterday, 12:52 PM
                              3 responses
                              22 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by helpwanted, Today, 03:06 AM
                              1 response
                              18 views
                              0 likes
                              Last Post sarafuenonly123  
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              244 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Working...
                              X