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

First indicator

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

    First indicator

    Hey all,

    I'm not a programmer but I'm trying to learn. I'm making a simple ema cross over that plots an up arrow when the fast EMA crosses above the slow EMA and vice-versa. Here is my code. I keep getting an error on line 59 CS0102. I've highlight the error in red "inputfast" Please help.

    #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.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Ema arrow test indicator
    /// </summary>
    [Description("Ema arrow test indicator")]
    public class EMAarrowtest : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int Inputfast = 3; // Default setting for fastema
    private int Inputslow = 14; //Default setting for slowema
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(EMA(Inputfast), EMA(InputSlow), 1))
    {
    DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
    }

    // Condition set 2
    if (CrossBelow(EMA(Inputfast), EMA(InputSlow), 1))
    {
    DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Red);
    }
    }

    #region Properties
    [Description("Fast description input")]
    [Category("Parameters")]
    public int Inputfast
    {
    get { return inputfast; }
    set { inputfast = Math.Max(1, value); }
    }

    [Description("Slow description input")]
    [Category("Parameters")]
    public int InputSlow
    {
    get { return inputSlow; }
    set { inputSlow = 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 EMAarrowtest[] cacheEMAarrowtest = null;

    private static EMAarrowtest checkEMAarrowtest = new EMAarrowtest();

    /// <summary>
    /// Ema arrow test indicator
    /// </summary>
    /// <returns></returns>
    public EMAarrowtest EMAarrowtest(int inputfast, int inputSlow)
    {
    return EMAarrowtest(Input, inputfast, inputSlow);
    }

    /// <summary>
    /// Ema arrow test indicator
    /// </summary>
    /// <returns></returns>
    public EMAarrowtest EMAarrowtest(Data.IDataSeries input, int inputfast, int inputSlow)
    {
    checkEMAarrowtest.Inputfast = inputfast;
    inputfast = checkEMAarrowtest.Inputfast;
    checkEMAarrowtest.InputSlow = inputSlow;
    inputSlow = checkEMAarrowtest.InputSlow;

    if (cacheEMAarrowtest != null)
    for (int idx = 0; idx < cacheEMAarrowtest.Length; idx++)
    if (cacheEMAarrowtest[idx].Inputfast == inputfast && cacheEMAarrowtest[idx].InputSlow == inputSlow && cacheEMAarrowtest[idx].EqualsInput(input))
    return cacheEMAarrowtest[idx];

    EMAarrowtest indicator = new EMAarrowtest();
    indicator.BarsRequired = BarsRequired;
    indicator.CalculateOnBarClose = CalculateOnBarClose;
    indicator.Input = input;
    indicator.Inputfast = inputfast;
    indicator.InputSlow = inputSlow;
    indicator.SetUp();

    EMAarrowtest[] tmp = new EMAarrowtest[cacheEMAarrowtest == null ? 1 : cacheEMAarrowtest.Length + 1];
    if (cacheEMAarrowtest != null)
    cacheEMAarrowtest.CopyTo(tmp, 0);
    tmp[tmp.Length - 1] = indicator;
    cacheEMAarrowtest = 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>
    /// Ema arrow test indicator
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.EMAarrowtest EMAarrowtest(int inputfast, int inputSlow)
    {
    return _indicator.EMAarrowtest(Input, inputfast, inputSlow);
    }

    /// <summary>
    /// Ema arrow test indicator
    /// </summary>
    /// <returns></returns>
    public Indicator.EMAarrowtest EMAarrowtest(Data.IDataSeries input, int inputfast, int inputSlow)
    {
    return _indicator.EMAarrowtest(input, inputfast, inputSlow);
    }

    }
    }

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    public partial class Strategy : StrategyBase
    {
    /// <summary>
    /// Ema arrow test indicator
    /// </summary>
    /// <returns></returns>
    [Gui.Design.WizardCondition("Indicator")]
    public Indicator.EMAarrowtest EMAarrowtest(int inputfast, int inputSlow)
    {
    return _indicator.EMAarrowtest(Input, inputfast, inputSlow);
    }

    /// <summary>
    /// Ema arrow test indicator
    /// </summary>
    /// <returns></returns>
    public Indicator.EMAarrowtest EMAarrowtest(Data.IDataSeries input, int inputfast, int inputSlow)
    {
    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.EMAarrowtest(input, inputfast, inputSlow);
    }

    }
    }
    #endregion

    #2
    You define the variable:
    private int Inputfast = 3; // Default setting for fastema

    But Inputfast is the name of one of your properties already, that is a conflict for the compiler.
    I guess you want to define the variable used by the property and therefore the name of your variable should be "inputfast".

    Regards
    Ralph

    Comment


      #3
      Same for the variable Inputslow. It should be inputslow.
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        Thanks all,

        I got the code to compile but nothing plots on my chart. No up arrow or down arrow. I'm having a hard time understanding the plot functions with Ninja.

        Comment


          #5
          Thanks for the input guys -

          skikg, please define a valid Y axis value for the DrawArrows call -



          Yours is currently at 0, so not visible at all.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            In your DrawArrowUp() and DrawArrowDown() you are drawing the arrow at zero, way off your chart. Try something like this:

            DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0], Color.Lime);
            }

            Edit - oops. Bertrand beat me to it while I was typing.
            eDanny
            NinjaTrader Ecosystem Vendor - Integrity Traders

            Comment


              #7
              AWESOME...

              Got it thanks guys.

              Comment


                #8
                Not to beat a dead horse here but I have two more questions. How do I assign the arrow color from the Plots Menu without going into the indicator and changing it everytime? I've added the Add(new Plot (Color... but how do I set each value to the arrows? Also I've added a wav file sound, but would like to do the same thing and have it come up in the Parameters window for changing files, instead of changing it in the script code.

                Thanks for all the help again,

                #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.Gui.Chart;
                #endregion

                // This namespace holds all indicators and is required. Do not change it.
                namespace NinjaTrader.Indicator
                {
                /// <summary>
                /// Ema arrow test indicator
                /// </summary>
                [Description("Ema arrow test indicator")]
                public class EMAarrowtest : Indicator
                {
                #region Variables
                // Wizard generated variables
                private int inputfast = 3; // Default setting for fastema
                private int inputslow = 14; //Default setting for slowema
                // User defined variables (add any user defined variables below)
                #endregion

                /// <summary>
                /// This method is used to configure the indicator and is called once before any bar data is loaded.
                /// </summary>
                protected override void Initialize()
                {
                Add(new Plot (Color.Lime, "UpArrow"));
                Add(new Plot (Color.Red, "DnArrow"));

                Overlay = true;
                CalculateOnBarClose = true;

                }

                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
                // Condition set 1
                if (CrossAbove(EMA(Inputfast), EMA(Inputslow), 1))
                {
                DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0]- 1 * TickSize, Color.Lime);
                PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");
                }

                // Condition set 2
                if (CrossBelow(EMA(Inputfast), EMA(Inputslow), 1))
                {
                DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0]+1*TickSize, Color.Red);
                PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert2.wav");
                }
                }

                #region Properties
                [Description("Fast description input")]
                [Category("Parameters")]
                public int Inputfast
                {
                get { return inputfast; }
                set { inputfast = Math.Max(1, value); }
                }

                [Description("Slow description input")]
                [Category("Parameters")]
                public int Inputslow
                {
                get { return inputslow; }
                set { inputslow = 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 EMAarrowtest[] cacheEMAarrowtest = null;

                private static EMAarrowtest checkEMAarrowtest = new EMAarrowtest();

                /// <summary>
                /// Ema arrow test indicator
                /// </summary>
                /// <returns></returns>
                public EMAarrowtest EMAarrowtest(int inputfast, int inputslow)
                {
                return EMAarrowtest(Input, inputfast, inputslow);
                }

                /// <summary>
                /// Ema arrow test indicator
                /// </summary>
                /// <returns></returns>
                public EMAarrowtest EMAarrowtest(Data.IDataSeries input, int inputfast, int inputslow)
                {
                checkEMAarrowtest.Inputfast = inputfast;
                inputfast = checkEMAarrowtest.Inputfast;
                checkEMAarrowtest.Inputslow = inputslow;
                inputslow = checkEMAarrowtest.Inputslow;

                if (cacheEMAarrowtest != null)
                for (int idx = 0; idx < cacheEMAarrowtest.Length; idx++)
                if (cacheEMAarrowtest[idx].Inputfast == inputfast && cacheEMAarrowtest[idx].Inputslow == inputslow && cacheEMAarrowtest[idx].EqualsInput(input))
                return cacheEMAarrowtest[idx];

                EMAarrowtest indicator = new EMAarrowtest();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
                indicator.Input = input;
                indicator.Inputfast = inputfast;
                indicator.Inputslow = inputslow;
                indicator.SetUp();

                EMAarrowtest[] tmp = new EMAarrowtest[cacheEMAarrowtest == null ? 1 : cacheEMAarrowtest.Length + 1];
                if (cacheEMAarrowtest != null)
                cacheEMAarrowtest.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheEMAarrowtest = 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>
                /// Ema arrow test indicator
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.EMAarrowtest EMAarrowtest(int inputfast, int inputslow)
                {
                return _indicator.EMAarrowtest(Input, inputfast, inputslow);
                }

                /// <summary>
                /// Ema arrow test indicator
                /// </summary>
                /// <returns></returns>
                public Indicator.EMAarrowtest EMAarrowtest(Data.IDataSeries input, int inputfast, int inputslow)
                {
                return _indicator.EMAarrowtest(input, inputfast, inputslow);
                }

                }
                }

                // This namespace holds all strategies and is required. Do not change it.
                namespace NinjaTrader.Strategy
                {
                public partial class Strategy : StrategyBase
                {
                /// <summary>
                /// Ema arrow test indicator
                /// </summary>
                /// <returns></returns>
                [Gui.Design.WizardCondition("Indicator")]
                public Indicator.EMAarrowtest EMAarrowtest(int inputfast, int inputslow)
                {
                return _indicator.EMAarrowtest(Input, inputfast, inputslow);
                }

                /// <summary>
                /// Ema arrow test indicator
                /// </summary>
                /// <returns></returns>
                public Indicator.EMAarrowtest EMAarrowtest(Data.IDataSeries input, int inputfast, int inputslow)
                {
                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.EMAarrowtest(input, inputfast, inputslow);
                }

                }
                }
                #endregion

                Comment


                  #9
                  You would need add user inputs for the sound file and the colors to be used -



                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, I got the colors to work perfect, but I'm still having a hard time with the play sound.

                    Under Variable I put

                    private int audiofile = NONE;

                    then under properties I put

                    [Description("Plays sound on arrow")]
                    [Category("Parameters")]
                    public int Audiofile
                    {
                    get { return audiofile; }
                    set { audiofile = value; }
                    }
                    but I believe i need something like the string from the color example you gave me

                    get { return NinjaTrader.Gui.Design.SerializableColor.ToString( dnColor); }
                    set { dnColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }

                    then under conditon 1 and 2 I put
                    PlaySound(Audiofile);

                    where can I find the Ninjatrader string for the playsound function?

                    Thanks for all your help once again.

                    Comment


                      #11
                      skikg,

                      Jumping in here, I believe the issue is that you made the parameter as a public int. You want that as a string.

                      [Description("Plays sound on arrow")]
                      [Category("Parameters")]
                      public int Audiofile
                      {
                      get { return audiofile; }
                      set { audiofile = value; }
                      }
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Got it working.

                        Thanks for the help.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by GussJ, 03-04-2020, 03:11 PM
                        15 responses
                        3,270 views
                        0 likes
                        Last Post xiinteractive  
                        Started by Tim-c, Today, 02:10 PM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by Taddypole, Today, 02:47 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post Taddypole  
                        Started by chbruno, 04-24-2024, 04:10 PM
                        4 responses
                        51 views
                        0 likes
                        Last Post chbruno
                        by chbruno
                         
                        Started by TraderG23, 12-08-2023, 07:56 AM
                        10 responses
                        403 views
                        1 like
                        Last Post beobast
                        by beobast
                         
                        Working...
                        X