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 call my indicator and change parameters

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

    how to call my indicator and change parameters

    Hi,

    i have this problem : I have myIndicator with 2 parameters that can change in gui, but when i try to recall myIndicator(3,8)[0] in another myindicator2 an error appears .

    For example : if i want to call RSI in my indicator simply i write RSI(14,3)[0] . Is possible to do the same with myindicator ?

    thanks in advance.

    Luca

    #2
    Hello sniper,

    Thank you for your inquiry. The default format when calling one indicator from another indicator is as follows: indicator_name(parameter1, parameter2, etc.) [barsAgo]. The user defined indicator parameters are in parenthesis.

    For example, the RSI indicator uses two parameters (period and bar smoothing) which is why you call it like this:
    Code:
    RSI(14, 3)[0]
    This calls RSI on the current bar with a period of 14 and a smoothing of 3.

    For more information on setting up your user defined parameters correctly, please see this thread: http://www.ninjatrader.com/support/f...ead.php?t=5782

    You can find how the RSI parameters are setup by opening up the RSI indicator and going down to the section beginning with
    Code:
    #region Properties
    If you have any additional questions, please feel free to ask.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      If try myindicator()[0] it works fine, but when i digit for example myindicator(3,8)[0] a compling error appear in NT.

      Comment


        #4
        Originally posted by sniper View Post
        If try myindicator()[0] it works fine, but when i digit for example myindicator(3,8)[0] a compling error appear in NT.
        That means that you do not have an overload of your indicator that uses 2 parameters. Check that you have defined your public properties properly. Why not post the code for those properties, so that we can take a look?

        Comment


          #5
          Sure, my indicator is like abraham indicator :
          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          [Description("Enter the description of your new custom indicator here")]
          public class SNIPERabrahm : Indicator
          {
          #region Variables
          private int t = 13; // Periodo dell'ATR
          private double m = 3.5; // Moltiplicatore dell'ATR
          private double sto = 0;
          private double vola = 0 ;
          private double hclose = 0 ;
          private double lclose = 0 ;
          #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.FromKnownColor(KnownColor.Orange), PlotStyle.Dot, "STOPatr"));

          Overlay = true;
          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          if (CurrentBar < t)
          return;
          // Inizio codice
          if (
          High[0] > hclose
          )
          {
          hclose = High[0];
          }

          if (
          Low[0] < lclose
          )
          {
          lclose = Low[0];
          }

          if (
          Close[0] >= sto
          )
          {
          vola = (ATR(t)[0])*m;
          //Print(ATR(t)[0]);
          sto = Instrument.MasterInstrument.Round2TickSize(hclose - vola );
          lclose = Low[0];
          STOPatr.Set(sto);

          }
          if (
          Close[0] <= sto
          )
          {
          vola = (ATR(t)[0])*m;
          //Print(ATR(t)[0]);
          sto = Instrument.MasterInstrument.Round2TickSize(lclose + vola );
          hclose = High[0];
          STOPatr.Set(sto);

          }
          }

          #region Properties
          [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
          public DataSeries STOPatr
          {
          get { return Values[0]; }
          }


          [Description("Periodo dell'ATR e EMA")]
          [Category("Parametri")]
          public int Periodo_dell_ATR
          {
          get { return t; }
          set { t = Math.Max(1, value); }
          }
          [Description("Moltiplicatore dell'ATR")]
          [Category("Parametri")]
          public double Moltiplicatore_dell_ATR
          {
          get { return m; }
          set { m = Math.Max(0.1, value); }
          }
          #endregion

          Comment


            #6
            Originally posted by sniper View Post
            Sure, my indicator is like abraham indicator :
            // This namespace holds all indicators and is required. Do not change it.
            namespace NinjaTrader.Indicator
            {
            /// <summary>
            /// Enter the description of your new custom indicator here
            /// </summary>
            [Description("Enter the description of your new custom indicator here")]
            public class SNIPERabrahm : Indicator
            {
            #region Variables
            private int t = 13; // Periodo dell'ATR
            private double m = 3.5; // Moltiplicatore dell'ATR
            private double sto = 0;
            private double vola = 0 ;
            private double hclose = 0 ;
            private double lclose = 0 ;
            #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.FromKnownColor(KnownColor.Orange), PlotStyle.Dot, "STOPatr"));

            Overlay = true;
            CalculateOnBarClose = true;
            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            if (CurrentBar < t)
            return;
            // Inizio codice
            if (
            High[0] > hclose
            )
            {
            hclose = High[0];
            }

            if (
            Low[0] < lclose
            )
            {
            lclose = Low[0];
            }

            if (
            Close[0] >= sto
            )
            {
            vola = (ATR(t)[0])*m;
            //Print(ATR(t)[0]);
            sto = Instrument.MasterInstrument.Round2TickSize(hclose - vola );
            lclose = Low[0];
            STOPatr.Set(sto);

            }
            if (
            Close[0] <= sto
            )
            {
            vola = (ATR(t)[0])*m;
            //Print(ATR(t)[0]);
            sto = Instrument.MasterInstrument.Round2TickSize(lclose + vola );
            hclose = High[0];
            STOPatr.Set(sto);

            }
            }

            #region Properties
            [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries STOPatr
            {
            get { return Values[0]; }
            }


            [Description("Periodo dell'ATR e EMA")]
            [Category("Parametri")]
            public int Periodo_dell_ATR
            {
            get { return t; }
            set { t = Math.Max(1, value); }
            }
            [Description("Moltiplicatore dell'ATR")]
            [Category("Parametri")]
            public double Moltiplicatore_dell_ATR
            {
            get { return m; }
            set { m = Math.Max(0.1, value); }
            }
            #endregion
            That actually looks correct, but try using GridCategory instead of Category.

            Edit: Maybe not. It is possible that Category("Parameters") must be in English for it to work correctly as a publicly exposed parameter in the instance constructor. Not really sure: just speculating here.
            Last edited by koganam; 05-20-2015, 11:02 AM.

            Comment


              #7
              Hello,

              Thank you for your assistance koganam. Just to clarify:
              Code:
              [GridCategory("Parametri")]
              is the correct adjustment.

              The quotes after GridCategory simply allow for categorizing parameters within the indicator properties popup and do not affect compilation. You can put letters, numbers, etc. between the quotations, just not characters that need to be escaped.

              If we can be of further assistance, please let us know.
              Last edited by NinjaTrader_MichaelM; 05-20-2015, 11:24 AM.
              Michael M.NinjaTrader Quality Assurance

              Comment


                #8
                With GridCategory i recive an NT error CS1501 olso on other my indicator...

                Comment


                  #9
                  Sorry, now it works fine !!

                  The errors was becouse i forgot to change parameters in other strategy file.

                  Thanks a lot.
                  Last edited by sniper; 05-20-2015, 11:57 AM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Mestor, 03-10-2023, 01:50 AM
                  16 responses
                  388 views
                  0 likes
                  Last Post z.franck  
                  Started by rtwave, 04-12-2024, 09:30 AM
                  4 responses
                  31 views
                  0 likes
                  Last Post rtwave
                  by rtwave
                   
                  Started by yertle, Yesterday, 08:38 AM
                  7 responses
                  29 views
                  0 likes
                  Last Post yertle
                  by yertle
                   
                  Started by bmartz, 03-12-2024, 06:12 AM
                  2 responses
                  22 views
                  0 likes
                  Last Post bmartz
                  by bmartz
                   
                  Started by funk10101, Today, 12:02 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post funk10101  
                  Working...
                  X