Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help creating a Parabolic Weighted Moving Average(PWMA)

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

    Help creating a Parabolic Weighted Moving Average(PWMA)

    Hi,
    I have looked at the code for WMA in NT 8 and understand that the calculation uses a triangular number for the denominator. For clarity, a Parabolic Weighted Moving Average(PWMA) is the same as a Weighted Moving Average except that each period is squared and multiplied by Price instead of WMA, where each period is multiplied by Price. The rest of the WMA logic remains the same. I couldn't find any solutions on the web for a triangular denominator which could be used for the PWMA. Does anyone know what values should be used?(in WMA the denominator is n(n+1)/2 where n = period).
    Or if this isn't possible within the OnBarUpdate() method, how would you suggest I implement this?
    Any help appreciated!

    Kind Regards,
    /george

    #2
    Hello george,

    I wasn't able to find any similar existing indicators like this so I think you would be creating something new.

    Below is a link to a forum post with helpful resources on getting started with C# and NinjaScript.


    While I wouldn't be able to suggest specific logic I can try and help you find the values if you know what you are looking for.

    The WMA is open source and you are free to view the code.

    The main logic is:
    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));

    ​In this, the Period is the number of bars for the calculation input by the user. The myPeriod variable is using whichever is smaller, the number of bars or the period (to prevent barsAgo index errors).

    Are you wanting something like 'Period * ( Period + 1 ) / 2'?


    This thread will also remain open for any community members that would like to assist you with your custom calculation.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChlseaB! and thank you for your reply.

      The programming is not the problem, as I have experience with C# and NinjaScript. I have already looked at the WMA source code and understood what it is doing. As I mentioned above, the PWMA uses the squares of the period multiplied by the price so the denominator would need to be different from WMA(which is n(n+1)/2) in order to get the correct PWMA.
      The solutions for SMA, EMA and WMA are all elegant vis-a-vis OnBarUpdate(). I would prefer logic similar to the SMA/WMA rather than performing a loop calculation within OnBarUpdate().

      Hoping there are some good math folks out there that can help with my dilemma.

      Kind Regards,
      /george

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      88 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      48 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      30 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      34 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      68 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X