Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

HMA Indicator But Modified

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

    HMA Indicator But Modified

    Hello,

    Im looking to modify the HMA indicator. I can use the HMA indicator with a displacement of -10 on my chart with no issues. But when it comes to using the displacement in a strategy, Strategy builder does not allow it, as far as I can tell. Is there a way to create a HMA indicator that plots with the displacement but able to be used in strategy builder?

    Thanks,

    #2
    Hello, thanks for writing in. The displacement is just a visual modification so it does not change the data on each bar when evaluating it. You can apply an offset in the builder which will move the HMA values up or down, or you can open the HMA indicator>Right Click>Save As>give it a custom name, then set the Displacement in State.SetDefaults, then use this copy in the strategy builder.

    Code:
    protected override void OnStateChange()
    {
    if(State == State.SetDefaults)
    {
    // Adds a plot for the MA values to be stored in
    AddPlot(Brushes.Orange, "MA");
    
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    Name = "MyHMA";
    Displacement = 10;
    }
    }

    Comment


      #3
      Thanks for the reply. Below is the built in state.setdefaults. From the code you posted below. Im assuming I will change the name and discription. Do I leave the rest of whats below and just add the calculate=calculate.onbarclose and displacement = 10?

      Code:
      if (State == State.SetDefaults)
                  {
                      Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionHMA;
                      Name                        = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameHMA;
                      IsSuspendedWhileInactive    = true;
                      Period                        = 14;
                      IsOverlay                     = true;
      
                      AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameHMA);
                  }​

      Comment


        #4
        Here is what I have. Specifically focusing on the state==state.setdefaults section.


        Code:
        public class HMA : Indicator
            {
                private Series<double> diffSeries;
                private WMA    wma1;
                private WMA wma2;
                private WMA wmaDiffSeries;
        
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                    = CustomerHMAIndicatorWithDisplacement
                        Name                        = MyHMA
                        IsSuspendedWhileInactive    = true;
                        Period                        = 14;
                        IsOverlay                     = true;
                        Calculate = Calculate.OnBarClose;
                        Displacement = 10;
        
                        AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameHMA);
                    }
                    else if (State == State.DataLoaded)
                    {
                        diffSeries        = new Series<double>(this);
                        wma1            = WMA(Inputs[0], (Period / 2));
                        wma2            = WMA(Inputs[0], Period);
                        wmaDiffSeries    = WMA(diffSeries, (int) Math.Sqrt(Period));
                    }
                }
        
                protected override void OnBarUpdate()
                {
                    diffSeries[0]    = 2 * wma1[0] - wma2[0];
                    Value[0]        = wmaDiffSeries[0];
                }
        
                #region Properties
                [Range(2, int.MaxValue), NinjaScriptProperty]
                [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
                public int Period
                { get; set; }
                #endregion
            }​

        Comment


          #5
          Hi, the Name and Description should be surrounded by quotes since they are String literals:

          Description = "CustomerHMAIndicatorWithDisplacement";
          Name = "MyHMA";

          Other than this, the code looks good. ​

          Comment


            #6
            Thanks Chris. It worked out.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X