Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.



    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Yes Thank you so much for your support

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Kaledus, Today, 01:29 PM
      0 responses
      3 views
      0 likes
      Last Post Kaledus
      by Kaledus
       
      Started by PaulMohn, Today, 12:36 PM
      1 response
      16 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by yertle, Yesterday, 08:38 AM
      8 responses
      37 views
      0 likes
      Last Post ryjoga
      by ryjoga
       
      Started by rdtdale, Today, 01:02 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by alifarahani, Today, 09:40 AM
      3 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X