Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enter a position on Color Change

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

    Enter a position on Color Change

    Hello

    Im using the Strategy Builder and I would like to know how to enter a position on a color change of an Indicator
    Im using this Indicator


    //
    // Copyright (C) 2019, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    /// <summary>
    /// The Hull Moving Average (HMA) employs weighted MA calculations to offer superior
    /// smoothing, and much less lag, over traditional SMA indicators.
    /// This indicator is based on the reference article found here:
    /// http://www.justdata.com.au/Journals/...ll/hull_ma.htm
    /// </summary>
    public class UpDownHMA : Indicator
    {
    private Series<double> diffSeries;
    private WMA wma1;
    private WMA wma2;
    private WMA wmaDiffSeries;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionHMA;
    Name = "UpDownHMA";
    IsSuspendedWhileInactive = true;
    Period = 14;
    IsOverlay = true;

    AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meHMA);
    }
    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()
    {
    if(CurrentBar < 1)
    return;

    diffSeries[0] = 2 * wma1[0] - wma2[0];
    if(wmaDiffSeries[0] > wmaDiffSeries[1])
    {
    PlotBrushes[0][0] = Brushes.LimeGreen;
    }
    else
    {
    PlotBrushes[0][0] = Brushes.Red;
    }
    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
    }
    }

    #region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private UpDownHMA[] cacheUpDownHMA;
    public UpDownHMA UpDownHMA(int period)
    {
    return UpDownHMA(Input, period);
    }

    public UpDownHMA UpDownHMA(ISeries<double> input, int period)
    {
    if (cacheUpDownHMA != null)
    for (int idx = 0; idx < cacheUpDownHMA.Length; idx++)
    if (cacheUpDownHMA[idx] != null && cacheUpDownHMA[idx].Period == period && cacheUpDownHMA[idx].EqualsInput(input))
    return cacheUpDownHMA[idx];
    return CacheIndicator<UpDownHMA>(new UpDownHMA(){ Period = period }, input, ref cacheUpDownHMA);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.UpDownHMA UpDownHMA(int period)
    {
    return indicator.UpDownHMA(Input, period);
    }

    public Indicators.UpDownHMA UpDownHMA(ISeries<double> input , int period)
    {
    return indicator.UpDownHMA(input, period);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.UpDownHMA UpDownHMA(int period)
    {
    return indicator.UpDownHMA(Input, period);
    }

    public Indicators.UpDownHMA UpDownHMA(ISeries<double> input , int period)
    {
    return indicator.UpDownHMA(input, period);
    }
    }
    }

    #endregion

    #2
    Hello bofygym7,

    Thanks for your post.

    There is no means to enter based on a color change.

    The indicator does not expose the series that is being used to determine the color change: private WMA wmaDiffSeries; By keeping it private the Strategy builder or any Ninjascript would not have access to the color change criteria.

    Looking at the code for the color change, it looks like they are doing a simple check to see if the plots current value is greater than the previous value: if(wmaDiffSeries[0] > wmaDiffSeries[1]) the plot would be green, otherwise the assumption is that it is Red.

    You could do this same type of check in the strategy builder by comparing the current bar of the indicator to the previous bar of the indicator.



    Comment


      #3
      Yes Thank you so much for your support

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      63 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      137 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X