Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Create a WMA of a custom slope indicator

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

    Create a WMA of a custom slope indicator

    I created an indicator that calculates / plots the slope of the HMA called HMAslope. I would like to calculate and plot the WMA of the HMAslope. Do I need to define the HMAslope as a series before I can use it in the WMA function? I have attached my code for the HMAslope custom indicator.


    Attached Files

    #2
    Hello herbnderby, thanks for writing in.

    You are assigning the Slope value to the Value array which is already a Series<double> object, so you can use that series in the WMA e.g.

    Value[0] = Slope(HMA(Period), StartBarsAgo, EndBarsAgo);
    double myValue = WMA(Value, 20)[0];

    Kind regards,
    -ChrisL

    Comment


      #3
      I added that line of code. How do I plot this WMA on the same plot as the HMAslope?

      Comment


        #4
        Hi herbnderby, thanks for your reply.

        You will need to call AddPlot() one more time, then access the second plot, e.g.

        Value[0][0] = Slope(HMA(Period), StartBarsAgo, EndBarsAgo); //first plot
        Values[1][0] = WMA(Value, Period)[0]; //second plot


        Best regards,
        -ChrisL

        Comment


          #5
          Okay, I modified my code as shown above but I received the error message "Cannot apply indexing with [] to an expression of type "double".

          So I modified the code to this:

          Values[0][0] = Slope(HMA(PeriodHMA), 1, 0); //first plot
          Values[1][0] = WMA(Values[0], PeriodWMA)[0]; //second plot

          I don't get any errors after compiling but the indicator still doesn't plot anything.

          Comment


            #6
            Hi herbnderby,

            I added a CurrentBar check at the top to ensure there are enough bars to process and all the plots show up:

            Code:
            protected override void OnBarUpdate()
            {
                if(CurrentBar < 20) return;
            
                Values[0][0] = Slope(HMA(20), 1, 0); //first plot
            
                Values[1][0] = WMA(Values[0], 20)[0]; //second plot
            }
            Best regards,
            -ChrisL

            Comment


              #7
              This has solved the issue. Thank you ChrisL, I appreciate it.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              599 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              344 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              558 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              557 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X