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 Hwop38, 05-04-2026, 07:02 PM
            0 responses
            160 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            307 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            244 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            348 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            178 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Working...
            X