Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adx nt8

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

    Adx nt8

    Hello Support,
    Could you show me how to change the line color of the NT8 ADX indicator to change to green when it is above 20 and is sloping up(rising). Ineed to use in strategy builder
    NinjaTrader 8

    #2
    Hello pickles1774,

    Thank you for your note.

    You could create a copy of the ADX indicator in the NinjaScript Editor by opening the script, then right-click it and select Save As. Give your copy of the ADX indicator a new name. Then, you would need to add logic that changes the PlotBrushes color depending on when the plot is above 20 and is rising or not. We have a reference sample that demonstrates how to modify the colors of plots under certain conditions here:


    After saving your changes to the copy, your modified indicator saved under the new name should be available for use in the Strategy Builder.

    Please let us know if we may be of further assistance.

    Comment


      #3
      Emily,
      i dont have coding expereince. I dont know where I would place the logic into the code: So what i need to change the color of the line Green when it is above 20 and when slope is rising. If it is below 20 then line is Red color.
      CAUTION: This is an email from an external source. Do not click links or open attachments unless you recognize the sender and know the content is safe.
      //
      // Copyright (C) 2023, 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 Average Directional Index measures the strength of a prevailing trend as well as whether movement
      /// exists in the market. The ADX is measured on a scale of 0 100. A low ADX value (generally less than 20)
      /// can indicate a non-trending market with low volumes whereas a cross above 20 may indicate the start of
      /// a trend (either up or down). If the ADX is over 40 and begins to fall, it can indicate the slowdown of a current trend.
      /// </summary>
      public class ADX : Indicator
      {
      private Series<double> dmPlus;
      private Series<double> dmMinus;
      private Series<double> sumDmPlus;
      private Series<double> sumDmMinus;
      private Series<double> sumTr;
      private Series<double> tr;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionADX;
      Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meADX;
      IsSuspendedWhileInactive = true;
      Period = 14;

      AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meADX);
      AddLine(Brushes.SlateBlue, 25, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLo wer);
      AddLine(Brushes.Goldenrod, 75, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUp per);
      }
      else if (State == State.DataLoaded)
      {
      dmPlus = new Series<double>(this);
      dmMinus = new Series<double>(this);
      sumDmPlus = new Series<double>(this);
      sumDmMinus = new Series<double>(this);
      sumTr = new Series<double>(this);
      tr = new Series<double>(this);
      }
      }

      protected override void OnBarUpdate()
      {
      double high0 = High[0];
      double low0 = Low[0];

      if (CurrentBar == 0)
      {
      tr[0] = high0 - low0;
      dmPlus[0] = 0;
      dmMinus[0] = 0;
      sumTr[0] = tr[0];
      sumDmPlus[0] = dmPlus[0];
      sumDmMinus[0] = dmMinus[0];
      Value[0] = 50;
      }
      else
      {
      double high1 = High[1];
      double low1 = Low[1];
      double close1 = Close[1];

      tr[0] = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
      dmPlus[0] = high0 - high1 > low1 - low0 ? Math.Max(high0 - high1, 0) : 0;
      dmMinus[0] = low1 - low0 > high0 - high1 ? Math.Max(low1 - low0, 0) : 0;

      if (CurrentBar < Period)
      {
      sumTr[0] = sumTr[1] + tr[0];
      sumDmPlus[0] = sumDmPlus[1] + dmPlus[0];
      sumDmMinus[0] = sumDmMinus[1] + dmMinus[0];
      }
      else
      {
      double sumTr1 = sumTr[1];
      double sumDmPlus1 = sumDmPlus[1];
      double sumDmMinus1 = sumDmMinus[1];

      sumTr[0] = sumTr1 - sumTr1 / Period + tr[0];
      sumDmPlus[0] = sumDmPlus1 - sumDmPlus1 / Period + dmPlus[0];
      sumDmMinus[0] = sumDmMinus1 - sumDmMinus1 / Period + dmMinus[0];
      }

      double sumTr0 = sumTr[0];
      double diPlus = 100 * (sumTr0.ApproxCompare(0) == 0 ? 0 : sumDmPlus[0] / sumTr[0]);
      double diMinus = 100 * (sumTr0.ApproxCompare(0) == 0 ? 0 : sumDmMinus[0] / sumTr[0]);
      double diff = Math.Abs(diPlus - diMinus);
      double sum = diPlus + diMinus;

      Value[0] = sum.ApproxCompare(0) == 0 ? 50 : ((Period - 1) * Value[1] + 100 * diff / sum) / Period;
      }
      }

      region Properties
      [Range(1, 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 ADX[] cacheADX;
      public ADX ADX(int period)
      {
      return ADX(Input, period);
      }

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

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

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

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

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

      #endregion​

      Comment


        #4
        Hello pickles1774,

        Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one-on-one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates. This thread will remain open in case any members of the forum community would like to assist you with this script.

        That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior. For example, I have shared the link to the multi-colored plots sample with you:


        When certain conditions are met, that examples changes the PlotBrushes color for the desired plot:


        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one-on-one educational services.

        Thank you for using NinjaTrader.​

        Comment


          #5
          Hello Emily
          Here my attempt to create the condition that changes the color of the ADX line Green when the ADX line is greater than 20 and is rising. However, it should turn back to the default color when these two conditions are not true. The indicator just paint the line green only.
          Attached Files

          Comment


            #6
            Originally posted by pickles1774 View Post
            Hello Emily
            Here my attempt to create the condition that changes the color of the ADX line Green when the ADX line is greater than 20 and is rising. However, it should turn back to the default color when these two conditions are not true. The indicator just paint the line green only.
            What is the condition that you are using in your script? I realize that my advice to create a copy of the ADX indicator is also not necessary for your needs; you could create a brand new indicator in the NinjaScript Editor via the NinjaScript Wizard (be sure to add your plot in the wizard):


            If you add a plot in the NinjaScript Wizard, you will see that the script calls AddPlot with the default color selected. In your logic, you would set that plot to equal the value of the ADX with the desired period. Finally, you would set your logic to change the PlotBrushes color when your desired conditions are met. Here is an example with an ADX that has a period of 14:
            Code:
                    protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Description                                    = @"Enter the description for your new custom Indicator here.";
                            Name                                        = "ADXColors";
                            Calculate                                    = Calculate.OnPriceChange;
                            IsOverlay                                    = false;
                            DisplayInDataBox                            = true;
                            DrawOnPricePanel                            = true;
                            DrawHorizontalGridLines                        = true;
                            DrawVerticalGridLines                        = true;
                            PaintPriceMarkers                            = true;
                            ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                            //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                            //See Help Guide for additional information.
                            IsSuspendedWhileInactive                    = true;
            
            // I used the NinjaScript wizard to add a plot called ADXPlot and the default color is Red
                            AddPlot(Brushes.Red, "ADXPlot");
                        }
                        else if (State == State.Configure)
                        {
                        }
                    }
            
                    protected override void OnBarUpdate()
                    {
            // since the ADX has a period of 14, we want to make sure there are at least 14 bars on the chart
                        if (CurrentBar < 14)
                            return;
            // set the ADXPlot for the current bar to equal the ADX with a period of 14 for the current bar
                        ADXPlot[0] = ADX(14)[0];
                        
            // if the ADX with a period of 14 is greater than 20 on the current bar and it is rising, change the plot to green. Otherwise, the plot will be the default color of Red
                        if (ADX(14)[0] > 20 && IsRising(ADX(14)))
                            PlotBrushes[0][0] = Brushes.Green;
                    }​
            Please let us know if we may be of further assistance.

            Comment


              #7
              Emily, I thought I had explained the condition above. I use NT8 ADX indicator and renamed it so I have my own copy. There are two conditions:
              ADX line greater than 20
              Sloping is Rising
              If the above conditions are true change the line color to Green. If false keep the default color which is Cyan.

              Comment


                #8
                Originally posted by pickles1774 View Post
                Emily, I thought I had explained the condition above. I use NT8 ADX indicator and renamed it so I have my own copy. There are two conditions:
                ADX line greater than 20
                Sloping is Rising
                If the above conditions are true change the line color to Green. If false keep the default color which is Cyan.
                You did explain that information. I am advising that you do not need to make a copy of the NT8 ADX indicator and it would be more simple to create a new, basic indicator with one plot. You then set the plot's value to the ADX value (this is where you get the ADX data rather than copying the indicator itself and using the full calculation of the value). You can configure your conditions to change the plot color. Have you tested the code I provided in my previous response? It is an example of what I am trying to explain and I suspect it very closely suits your needs, then you could make any desired changes fairly easily.

                Thank you for your time and patience.

                Comment

                Latest Posts

                Collapse

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