Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

WMA not working correctly in NT8

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

    WMA not working correctly in NT8

    I know this is not very informative but there is definitely something wrong with the WMA indicator in NT8.

    I'm creating a dataseries, then passing this to WMA, but I get some strange values out. To fix I removed the 'additional' code that you have added to the WMA in NT8, which effectively took it back to the same code as NT7. This then works correctly. So it's something to do with the additional code you've added in NT8.

    As a first step I wondered if anyone else has already reported this? Or am I going to have post code examples?

    Thanks

    #2
    Hello bubblegum,

    Thank you for your post.

    What are the values that were outputted that were strange?
    Do you have a sample of the data series that we may try?

    I look forward to your response.

    Comment


      #3
      I don't know how you want your code, so let me know if it needs to be different.

      I apply this code to a 1 minute EURUSD chart.

      Code:
      	public class myWMAtest : Indicator
      	{
      		#region Variables
      			int Length = 12; 
      
      			private BarsPeriodType symbolbartype = BarsPeriodType.Minute;
                  private int symbolinterval = 1;
      
      			private Series <double> mycalc;
      		#endregion
      
      		protected override void OnStateChange()
      		{
      			if (State == State.SetDefaults)
      			{
      	            AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Line, "myPlot");
      
      				Description							= @"xx";
      				Name								= "myWMAtest";
      				Calculate							= Calculate.OnBarClose;
      				IsOverlay							= false;
      				DisplayInDataBox					= true;
      				DrawOnPricePanel					= true;
      				DrawHorizontalGridLines				= true;
      				DrawVerticalGridLines				= true;
      				PaintPriceMarkers					= true;
      				ScaleJustification					= NinjaTrader.Gui.Chart.ScaleJustification.Right;
      				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
      				//See Help Guide for additional information.
      				IsSuspendedWhileInactive			= true;
      			}
      			else if (State == State.Configure)
      			{
      				mycalc = new Series <double> (this);
      
      				AddDataSeries("AUDCAD", symbolbartype, symbolinterval);
      			}
      		}
      
      		protected override void OnBarUpdate()
      		{
      
      			mycalc[0] = EMA(Closes[1], 10)[0];
      
      			myPlot[0] = WMA(mycalc, (int)(Length * 0.5))[0];
      		}
      
              #region Properties
      	      [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              public Series <double> myPlot
              {
                  get { return Values[0]; }
              }
      		#endregion
      	}
      It produces the first image.

      Then if I change 'WMA' to 'myWMA' I get different results, shown in second image.

      So, WMA is your indicator in NT8.

      Code:
      		protected override void OnBarUpdate()
      		{
      			if (BarsArray[0].BarsType.IsRemoveLastBarSupported)
      			{
      				if (CurrentBar == 0)
      					Value[0] = Input[0];
      				else
      				{
      					int back = Math.Min(Period - 1, CurrentBar);
      					double val = 0;
      					int weight = 0;
      					for (int idx = back; idx >= 0; idx--)
      					{
      						val += (idx + 1) * Input[back - idx];
      						weight += (idx + 1);
      					}
      					Value[0] = val / weight;
      				}
      			}
      			else
      			{
      				if (IsFirstTickOfBar)
      				{
      					priorWsum = wsum;
      					priorSum = sum;
      					myPeriod = Math.Min(CurrentBar + 1, Period);
      				}
      
      				wsum = priorWsum - (CurrentBar >= Period ? priorSum : 0) + myPeriod * Input[0];
      				sum = priorSum + Input[0] - (CurrentBar >= Period ? Input[Period] : 0);
      				Value[0] = wsum / (0.5 * myPeriod * (myPeriod + 1));
      			}
      		}
      'myWMA' is the same code but with the new NT8 stuff removed

      Code:
      		protected override void OnBarUpdate()
      		{
      			if (CurrentBar == 0)
      				Value[0] = Input[0];
      			else
      			{
      				int back = Math.Min(Period - 1, CurrentBar);
      				double val = 0;
      				int weight = 0;
      				for (int idx = back; idx >= 0; idx--)
      				{
      					val += (idx + 1) * Input[back - idx];
      					weight += (idx + 1);
      				}
      				Value[0] = val / weight;
      			}
      		}
      This essentially takes the WMA indicator back to what it was in NT7.

      I've looked at this for so long it's confusing me now, but I think there are three things that seem to make things different.

      1. If I change this line from
      WMA(mycalc, (int)(Length * 0.5))[0]
      to
      WMA(mycalc, 10)[0]
      then it seems to be 'correct'.
      2. If I do the WMA calc on the close price, rather than a datastream (mycalc) then it seems to be 'correct'.
      3. If I remove the second datastream then it seems to be 'correct'.

      So over to you. Something is wrong. I'm getting the correct answer in NT7, which matches the answer I get with the 'myWMA' indicator in NT8. But your standard 'WMA' indicator in NT8 is definitely doing something different.
      Attached Files

      Comment


        #4
        Thank you, bubblegum.

        I will investigate further and we will implement any needed fixes.

        Comment


          #5
          Thanks. Do you have a bug tracking mechanism? Do you have a bug ID and a bug fix list that I can look at in future releases to see if this is fixed?

          Comment


            #6
            Originally posted by bubblegum View Post
            I'm creating a dataseries, then passing this to WMA, but I get some strange values out.
            So this is only occurring when passing a cusotm data series as the input series of the WMA in NT8? If you run the NT 7 and NT 8 WMAs on a chart they do match, correct?

            Once this has been reported to development as a bug with reproducible steps I will have a number for this item.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,607 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            15 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X