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

How to compile a new indicator with another pre-existing uncompiled one

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

    How to compile a new indicator with another pre-existing uncompiled one

    I have an in process indicator taking a long time to fix and in the meantime I wanted to rewrite some default ninja indicators to use my settings as defaults like color and length rather than resetting them each time I load on a chart without using a template.
    Apparently until I resolve that earlier one I cant.
    I tried using /* */ to make it invisible and also the icons that do it but that wont let me either.

    There must be a way. is there?

    #2
    You will have to fix the problems in the unfinished indicator first, I believe. If the indicator doesn't work yet, comment out the problem section. If that is too hard to find, use explorer to cut the indicator from the indicators folder and paste it somewhere else. Now your other indicators will compile fine. Paste it back in to work on it again.
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      simpletrades,

      If you are comfortable with posting the code, we can help with suggestions.

      RJay
      RJay
      NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

      Comment


        #4
        Originally posted by eDanny View Post
        You will have to fix the problems in the unfinished indicator first, I believe. If the indicator doesn't work yet, comment out the problem section. If that is too hard to find, use explorer to cut the indicator from the indicators folder and paste it somewhere else. Now your other indicators will compile fine. Paste it back in to work on it again.
        along that same line, yesterday i wanted to save the indicators i already have written that do work and i exported them in the zip file the utility uses but dont know where they exported to. where do i find my saved files? i tried using search from my start menu for the zip file name i created but nothing came up.

        Comment


          #5
          Originally posted by rt6176 View Post
          simpletrades,

          If you are comfortable with posting the code, we can help with suggestions.

          RJay
          I am trying to make the MACD a histogram (easy) but recolor each bar depending on whether it is longer than the prior bar (greater value if above zero or lesser value when MACD is below zero)

          I tried copying the Ninja MACD into a new code window then copying and pasting the original coloring where I set up the conditions, but nothing prints on the chart but it did compile.

          I am attaching a screenshot at the very end of how I did it on tradestation. Its a nice visual telling at a glance all you need--the signal line is the red line.

          I had the indicator on a separate thread but the help i was offered was too confusing. I tried incorporating it but no luck.

          I am going to post the full code so i can delete it on my end and move along. I will try and post it separately as I just got an error message saying this post had too many characters.

          Then I am going to start it over initially just trying to get one color if MACD as a histogram is >0 and one color if MACD<0 and if that at least works, then try to get it to color a lighter shade if the bar is longer than the prior.

          In my screenshot is also a paintbar indicator I wrote for myself on tradestation based on 4 separate indicators and when all are suggesting a long entry--blue--or all suggesting short--pink. If any of the 4 dont agree then its gray. That I got done in less than 24 hours with forum help here so i'm still optimistic.
          Attached Files
          Last edited by simpletrades; 08-08-2009, 12:11 PM.

          Comment


            #6
            Originally posted by simpletrades View Post
            I am going to post the full code so i can delete it on my end and move along. I will try and post it separately as I just got an error message saying this post had too many characters.
            I started by copying the ninja default MACD script.
            The //************* are incorporated forum suggestions and/or my own attempts to follow them.
            The colors are irrelevent, just to see if anything works.
            HTML Code:
            #region Using declarations
            using System;
            using System.ComponentModel;
            using System.Diagnostics;
            using System.Drawing;
            using System.Drawing.Drawing2D;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Data;
            using NinjaTrader.Indicator;
            using NinjaTrader.Gui.Chart;
            using NinjaTrader.Strategy;
            #endregion
            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Indicator
            {
            /// <summary>
            /// MACD current bar color depends on length compared to prior histogram bar
            /// </summary>
            [Description("MACD current bar color depends on length compared to prior histogram bar")]
            public class MACDhistogramBarRecolor : Indicator
             
            {
            #region Variables
            private int fast = 8;
            private int slow = 18;
            private int smooth = 9;
            private DataSeries fastEma;
            private DataSeries slowEma;
            private Color UpBar = Color.Lime; //*********************
            private Color DownBar = Color.Red;//************************* 
            #endregion
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
            //****** here you'll need to add a plot object for each different color bar you'd like
            Add(new Plot(Color.Green, "Macd"));
            Add(new Plot(Color.DarkViolet, "Avg"));
            Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Diff"));
            Add(new Line(Color.Blue, 0, "Zero line"));
            //******if you wanted another plot named "UpBar" you could add the following line:
            //*****Add(new Plot(new Pen(Color.RoyalBlue, 1), PlotStyle.Bar, "UpBar"));
            Add(new Plot(new Pen(Color.RoyalBlue, 1), PlotStyle.Bar, "UpBar"));
            Add(new Plot(new Pen(Color.Black, 1), PlotStyle.Bar, "DownBar"));
             
            fastEma = new DataSeries(this);
            slowEma = new DataSeries(this);
            }
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            if (CurrentBar == 0)
            {
            fastEma.Set(Input[0]);
            slowEma.Set(Input[0]);
            Value.Set(0);
            Avg.Set(0);
            Diff.Set(0);
            }
            else
            {
            fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
            slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);
            double macd = fastEma[0] - slowEma[0];
            double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1];
             
            //***** this is where the plot values are set
            Value.Set(macd);
            Avg.Set(macdAvg);
            Diff.Set(macd - macdAvg);
             
            // Condition set 1
            //***** Adding plots needs to be done in Initialize(), not here in OnBarUpdate().
            //***** This is where you set the value of the plot.
            //***** I'm not exactly sure what this condition means, but it looks like MACD > MACD one bar ago,
            //**** thus we'll set UpBar to the current value.
             
            if ( MACD(8, 18, 9)[0] > MACD(8, 18, 9)[1])
            Add(new Plot(new Pen(Color.Aqua, 2), PlotStyle.Bar, "MACD"));
            {
            UpBar.Set(MACD(8, 18, 9)[0]); 
            }
            // Condition set 2
            //***** for if MACD is falling
            if ( MACD(8, 18, 9)[0] < MACD(8, 18, 9)[1])
            Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "MACD"));
            {
            //*** need to add an associated plot for this statement to work
            DownBar.Set(MACD(8, 18, 9)[0]);
            }
             
            //Condition set 3
            if (MACD(8, 18, 9)[0]>0) 
            Add(new Plot(new Pen(Color.DarkCyan, 2), PlotStyle.Bar, "MACD"));
             
            //Condition set4
            if (MACD(8, 18, 9)[0]<0) 
            Add(new Plot(new Pen(Color.Silver, 2), PlotStyle.Bar, "MACD"));
            } 
             
             
            {
            }
             
            }
            #region Properties
            /// <summary>
            /// </summary>
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries Avg
            {
            get { return Values[1]; }
            }
            /// <summary>
            /// </summary>
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries Default
            {
            get { return Values[0]; }
            }
             
            /// <summary>
            /// </summary>
            [Browsable(false)]
            [XmlIgnore()]
            public DataSeries Diff
            {
            get { return Values[2]; }
            }
            /// <summary>
            /// </summary>
            [Description("Number of bars for fast EMA")]
            [Category("Parameters")]
            public int Fast
            {
            get { return fast; }
            set { fast = Math.Max(1, value); }
            }
            [Category("Visual")]//********************************
            private Color UpBar
            {
            get{return UpBar;}
            set {UpBar=value;}
            } //**************************************** 
            /// <summary>
            /// </summary>
            [Description("Number of bars for slow EMA")]
            [Category("Parameters")]
            public int Slow
            {
            get { return slow; }
            set { slow = Math.Max(1, value); }
            }
            /// <summary>
            /// </summary>
            [Description("Number of bars for smoothing")]
            [Category("Parameters")]
            public int Smooth
            {
            get { return smooth; }
            set { smooth = Math.Max(1, value); }
            }
            #endregion
            }
            }
            #region NinjaScript generated code. Neither change nor remove.
            // This namespace holds all indicators and is required. Do not change it.
            namespace NinjaTrader.Indicator
            {
            public partial class Indicator : IndicatorBase
            {
            private MACDhistogramBarRecolor[] cacheMACDhistogramBarRecolor = null;
            private static MACDhistogramBarRecolor checkMACDhistogramBarRecolor = new MACDhistogramBarRecolor();
            /// <summary>
            /// MACD current bar color depends on length compared to prior histogram bar
            /// </summary>
            /// <returns></returns>
            public MACDhistogramBarRecolor MACDhistogramBarRecolor(int fast, int slow, int smooth)
            {
            return MACDhistogramBarRecolor(Input, fast, slow, smooth);
            }
            /// <summary>
            /// MACD current bar color depends on length compared to prior histogram bar
            /// </summary>
            /// <returns></returns>
            public MACDhistogramBarRecolor MACDhistogramBarRecolor(Data.IDataSeries input, int fast, int slow, int smooth)
            {
            checkMACDhistogramBarRecolor.Fast = fast;
            fast = checkMACDhistogramBarRecolor.Fast;
            checkMACDhistogramBarRecolor.Slow = slow;
            slow = checkMACDhistogramBarRecolor.Slow;
            checkMACDhistogramBarRecolor.Smooth = smooth;
            smooth = checkMACDhistogramBarRecolor.Smooth;
            if (cacheMACDhistogramBarRecolor != null)
            for (int idx = 0; idx < cacheMACDhistogramBarRecolor.Length; idx++)
            if (cacheMACDhistogramBarRecolor[idx].Fast == fast && cacheMACDhistogramBarRecolor[idx].Slow == slow && cacheMACDhistogramBarRecolor[idx].Smooth == smooth && cacheMACDhistogramBarRecolor[idx].EqualsInput(input))
            return cacheMACDhistogramBarRecolor[idx];
            MACDhistogramBarRecolor indicator = new MACDhistogramBarRecolor();
            indicator.BarsRequired = BarsRequired;
            indicator.CalculateOnBarClose = CalculateOnBarClose;
            indicator.Input = input;
            indicator.Fast = fast;
            indicator.Slow = slow;
            indicator.Smooth = smooth;
            indicator.SetUp();
            MACDhistogramBarRecolor[] tmp = new MACDhistogramBarRecolor[cacheMACDhistogramBarRecolor == null ? 1 : cacheMACDhistogramBarRecolor.Length + 1];
            if (cacheMACDhistogramBarRecolor != null)
            cacheMACDhistogramBarRecolor.CopyTo(tmp, 0);
            tmp[tmp.Length - 1] = indicator;
            cacheMACDhistogramBarRecolor = tmp;
            Indicators.Add(indicator);
            return indicator;
            }
            }
            }
            // This namespace holds all market analyzer column definitions and is required. Do not change it.
            namespace NinjaTrader.MarketAnalyzer
            {
            public partial class Column : ColumnBase
            {
            /// <summary>
            /// MACD current bar color depends on length compared to prior histogram bar
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.MACDhistogramBarRecolor MACDhistogramBarRecolor(int fast, int slow, int smooth)
            {
            return _indicator.MACDhistogramBarRecolor(Input, fast, slow, smooth);
            }
            /// <summary>
            /// MACD current bar color depends on length compared to prior histogram bar
            /// </summary>
            /// <returns></returns>
            public Indicator.MACDhistogramBarRecolor MACDhistogramBarRecolor(Data.IDataSeries input, int fast, int slow, int smooth)
            {
            return _indicator.MACDhistogramBarRecolor(input, fast, slow, smooth);
            }
            }
            }
            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Strategy
            {
            public partial class Strategy : StrategyBase
            {
            /// <summary>
            /// MACD current bar color depends on length compared to prior histogram bar
            /// </summary>
            /// <returns></returns>
            [Gui.Design.WizardCondition("Indicator")]
            public Indicator.MACDhistogramBarRecolor MACDhistogramBarRecolor(int fast, int slow, int smooth)
            {
            return _indicator.MACDhistogramBarRecolor(Input, fast, slow, smooth);
            }
            /// <summary>
            /// MACD current bar color depends on length compared to prior histogram bar
            /// </summary>
            /// <returns></returns>
            public Indicator.MACDhistogramBarRecolor MACDhistogramBarRecolor(Data.IDataSeries input, int fast, int slow, int smooth)
            {
            if (InInitialize && input == null)
            throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
            return _indicator.MACDhistogramBarRecolor(input, fast, slow, smooth);
            }
            }
            }
            #endregion
            Last edited by simpletrades; 08-08-2009, 12:19 PM.

            Comment


              #7
              simpletrades,

              Step one, create an indicator you can edit..

              open MACD with indicator editor. Right click save as ....." new name".

              Edit this file.

              Put all your changes in.

              ----------------------------------------------------------

              You are missing your plot values for the new plots upbar and downbar.

              Disregard NT's caution about editing this section.

              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries Avg
              {
              get { return Values[1]; }
              }
              /// <summary>
              /// </summary>
              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries Default
              {
              get { return Values[0]; }
              }

              /// <summary>
              /// </summary>
              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries Diff
              {
              get { return Values[2]; }
              }
              ----------------------------------------------------------

              Add values 3 and 4 to match your plot values defined earlier.

              use 1,2,, and 3 as examples.

              Post your results and we'll take it from there.

              RJay
              RJay
              NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

              Comment


                #8
                Originally posted by rt6176 View Post
                simpletrades,

                Step one, create an indicator you can edit..

                open MACD with indicator editor. Right click save as ....." new name".

                Edit this file.

                Put all your changes in.

                ----------------------------------------------------------

                You are missing your plot values for the new plots upbar and downbar.

                Disregard NT's caution about editing this section.

                [Browsable(false)]
                [XmlIgnore()]
                public DataSeries Avg
                {
                get { return Values[1]; }
                }
                /// <summary>
                /// </summary>
                [Browsable(false)]
                [XmlIgnore()]
                public DataSeries Default
                {
                get { return Values[0]; }
                }

                /// <summary>
                /// </summary>
                [Browsable(false)]
                [XmlIgnore()]
                public DataSeries Diff
                {
                get { return Values[2]; }
                }
                ----------------------------------------------------------

                Add values 3 and 4 to match your plot values defined earlier.

                use 1,2,, and 3 as examples.

                Post your results and we'll take it from there.

                RJay
                Do you mean ignore attempts to edit 'properties' section by saying disregard NT's caution?

                What do you mean by Add values 3 and 4 to match your plot values
                and use 1,2,3 as examples--
                do i add
                'UpBar.Set(MACD(8, 18, 9)[0]);' and also 'DownBar.Set(MACD(8, 18, 9)[0]);' for MACD>0 and for MACD<0 ?

                Comment


                  #9
                  Originally posted by rt6176 View Post
                  simpletrades,

                  Step one, create an indicator you can edit..

                  open MACD with indicator editor. Right click save as ....." new name".

                  Edit this file.

                  Put all your changes in.

                  ----------------------------------------------------------

                  You are missing your plot values for the new plots upbar and downbar.

                  Disregard NT's caution about editing this section.

                  [Browsable(false)]
                  [XmlIgnore()]
                  public DataSeries Avg
                  {
                  get { return Values[1]; }
                  }
                  /// <summary>
                  /// </summary>
                  [Browsable(false)]
                  [XmlIgnore()]
                  public DataSeries Default
                  {
                  get { return Values[0]; }
                  }

                  /// <summary>
                  /// </summary>
                  [Browsable(false)]
                  [XmlIgnore()]
                  public DataSeries Diff
                  {
                  get { return Values[2]; }
                  }
                  ----------------------------------------------------------

                  Add values 3 and 4 to match your plot values defined earlier.

                  use 1,2,, and 3 as examples.

                  Post your results and we'll take it from there.

                  RJay
                  I ment to say use 0,1,2 as examples.

                  yes, You have to add code to # region properties
                  RJay
                  NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bmartz, 03-12-2024, 06:12 AM
                  5 responses
                  32 views
                  0 likes
                  Last Post NinjaTrader_Zachary  
                  Started by Aviram Y, Today, 05:29 AM
                  4 responses
                  13 views
                  0 likes
                  Last Post Aviram Y  
                  Started by algospoke, 04-17-2024, 06:40 PM
                  3 responses
                  28 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by gentlebenthebear, Today, 01:30 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by cls71, Today, 04:45 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X