• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    Patrick H.NinjaTrader Customer Service

    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.
        Patrick H.NinjaTrader Customer Service

        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.
            Patrick H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by seagraph, Today, 03:27 PM
            0 responses
            11 views
            0 likes
            Last Post seagraph  
            Started by dedouglas, Today, 02:54 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by elkhatabi, 08-01-2019, 06:36 PM
            5 responses
            53 views
            0 likes
            Last Post NinjaTrader_RyanL  
            Started by mr_trade, Today, 01:01 PM
            4 responses
            19 views
            0 likes
            Last Post mr_trade  
            Started by Renorail, Today, 12:31 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Working...
            X