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

Need a bit of NS/C# coding help

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

    Need a bit of NS/C# coding help

    Hello:

    This is primarily a request for someone to help with a C# snippet

    The code that I need is to be able to determine the value setting for non-time based bars.
    and need to extract the setting used for various types, Tick, Renko, Range, etc.

    The code below will return the desired information which is in a string format:

    if(Bars.BarsType.DisplayName == "SveRenko")
    do something


    The code:
    Print(" Period: " + Bars.BarsType.Period.ToString());

    returns:

    Period: SveRenko 10 Ticks

    which has the needed information in the string

    note: the ToString() in the above code was probably not necessary as it was a string already

    What I need is to be able to extract the numeric portion from the string and convert it to an integer. No other information is needed.

    Might it be possible for someone to develop the parsing code to extract and convert the number to an integer? The code should be as generic as possible because it will be used for other bar types

    Of course if there is a better way of getting that information I would welcome it.

    Thank you for your assistance.

    #2
    Originally posted by Cheech View Post
    Hello:

    This is primarily a request for someone to help with a C# snippet

    The code that I need is to be able to determine the value setting for non-time based bars.
    and need to extract the setting used for various types, Tick, Renko, Range, etc.

    The code below will return the desired information which is in a string format:

    if(Bars.BarsType.DisplayName == "SveRenko")
    do something


    The code:
    Print(" Period: " + Bars.BarsType.Period.ToString());

    returns:

    Period: SveRenko 10 Ticks

    which has the needed information in the string

    note: the ToString() in the above code was probably not necessary as it was a string already

    What I need is to be able to extract the numeric portion from the string and convert it to an integer. No other information is needed.

    Might it be possible for someone to develop the parsing code to extract and convert the number to an integer? The code should be as generic as possible because it will be used for other bar types

    Of course if there is a better way of getting that information I would welcome it.

    Thank you for your assistance.
    BarsPeriod.Value gives you that information directly as an int.

    ref: http://ninjatrader.com/support/helpG...barsperiod.htm

    Comment


      #3
      Works perfectly, thank you. Not sure why NT tech support couldn't answer that one?

      Comment


        #4
        Originally posted by Cheech View Post
        Works perfectly, thank you. Not sure why NT tech support couldn't answer that one?
        They were probably closed at the time that you posted your question. I happened to be awake, and figured that it was a quick answer.

        Comment


          #5
          Not quite, sent an email to them about a week ago. They responded that essentially I was pushing the envelope and outside of what was supported in NS.

          Anyway, koganam I appreciate your quick response. You seem well versed in NS/C# and I have another one that I haven't been able to solve, with my limited knowledge of both. Might I impose on you to take a look see when I post it?

          One way or the other, thanks again for solving that one for me.
          Last edited by Cheech; 07-12-2016, 08:37 AM.

          Comment


            #6
            Originally posted by Cheech View Post
            Not quite, sent an email to them about a week ago. They responded that essentially I was pushing the envelope and outside of what was supported in NS.

            Anyway, koganam I appreciate your quick response. You seem well versed in NS/C# and I have another one that I haven't been able to solve, with my limited knowledge of both. Might I impose on you to take a look see when I post it?

            One way or the other, thanks again for solving that one for me.
            Well, I am pretty active on the fora, and look at quite a few questions. After all, a trader spends most of his day waiting for something to happen, so I usually have a lot of time on my hands. You can always send me a PM once you post your query.

            Comment


              #7
              Another coding challenge

              The code snippet here is from a working indicator which has 2 MAs of which the type can be selected from about 30 choices, as defined in an Enum. A method is used to scan and setup the selected MA type for both MAs. As it is now the same MA choice is used for both MAs which is what I want to change.

              I would like to be able to specify different MA types using the defined Enums for each plot but, still be able to use the existing (albeit modified as necessary) method to do the MA setup. I know I will need to have another entry in the Properties section in order to select the MA type for the other plots, but from that point I don't know what else needs to be done.

              I've tried setting up the Enum name (dpoMAType in this example) as a reference which didn't work, and also tried setting it to a third name (similar to using a "temp" variable) prior to calling the method. Apparently Types can not be assigned either at all or there is a different way of doing it then as a simple assignment.

              The attached code is not the target indicator but is much easier to read. The target indicator has 5 MAs which would mean that if there wasn't a way of modifying the code still using a single Enum, then all of the code in the Case statements would need to be replicated 5 times because I would need a different Enum and Enum name for each, which seems inefficient.

              While I believe this to be solvable in C#I I'm lost how to do it and hope that someone would lend some assistance. Of course any other suggestions or solution would be welcomed.

              Thank you


              Code:
              #region ENUM
              public enum dpoMAType 
              {
              Median, ADXVMA, Butterworth_2, Butterworth_3, DEMA, DSMA, DTMA, DWMA, Ehlers, EMA, Gauss_2, Gauss_3, Gauss_4, HMA, HoltEMA, LinReg, SMA, SuperSmoother_2, SuperSmoother_3, TEMA, Tillson_T3, TMA, TSMA, TWMA, VWMA, WMA,  ZeroLagHATEMA, ZeroLagTEMA, ZLEMA
              }
              
                              
              #region Variables
                  private dpoMAType     maType    = dpoMAType.SMA;
              
                  private IDataSeries valueFastMA;
                  private IDataSeries valueSlowMA;
                  
                  private DataSeries    dpoFastDataSeries;
                  private DataSeries    dpoSlowDataSeries;
              
                  
              #region Methods    
                  private  void scanMA(dpoMAType maType, ref IDataSeries maValue, IDataSeries maInput, int maPeriod)
                      {
                          switch (maType)
                          {
                              case dpoMAType.Median: 
                                  maValue = anaMovingMedian(maInput, maPeriod);
                                  break;
                                  
                          //Other MAs in here    
                                  
                              case dpoMAType.ZLEMA: 
                                  maValue = ZLEMA(maInput, maPeriod);
                                  break;
                          }
                      }
              
                      
              #region Initialize
                      dpoFastDataSeries    =    new DataSeries(this);
                      dpoSlowDataSeries    =    new DataSeries(this);
              
                      
              #region OnStartup
                     //switch (xxx)
                      case dpoSpeed.Both:
                          smaSlowDPO = SMA(dpoSlowDataSeries, smooth);
                          smaFastDPO  = SMA(dpoFastDataSeries,  smooth);
              
              
              
                                      if(fastOption)
                          {
                              ...
                              
                              //prototype for method scanMA
                              //private void scanMA(dpoMAType maType, ref IDataSeries maValue, 
                                                IDataSeries maInput, int maPeriod)
                              
                                              //method call for fast period
                              scanMA(maType, ref valueFastMA, Input, fastPeriod);
                          }
              
                          if (slowOption)
                          {
                              ...
                              //method call for slow period
                              scanMA(maType, ref valueSlowMA, Input, slowPeriod);
                          }
              
                           
              #region Properties
                  [Description("Moving average type")]
                  [Category("Parameters")]
                  [Gui.Design.DisplayNameAttribute("Moving Average Type")]
                  public dpoMAType MAType
                  {
                      get { return maType; }
                      set { maType = value; }
                  }

              Comment


                #8
                Originally posted by Cheech View Post
                The code snippet here is from a working indicator which has 2 MAs of which the type can be selected from about 30 choices, as defined in an Enum. A method is used to scan and setup the selected MA type for both MAs. As it is now the same MA choice is used for both MAs which is what I want to change.

                I would like to be able to specify different MA types using the defined Enums for each plot but, still be able to use the existing (albeit modified as necessary) method to do the MA setup. I know I will need to have another entry in the Properties section in order to select the MA type for the other plots, but from that point I don't know what else needs to be done.

                I've tried setting up the Enum name (dpoMAType in this example) as a reference which didn't work, and also tried setting it to a third name (similar to using a "temp" variable) prior to calling the method. Apparently Types can not be assigned either at all or there is a different way of doing it then as a simple assignment.

                The attached code is not the target indicator but is much easier to read. The target indicator has 5 MAs which would mean that if there wasn't a way of modifying the code still using a single Enum, then all of the code in the Case statements would need to be replicated 5 times because I would need a different Enum and Enum name for each, which seems inefficient.

                While I believe this to be solvable in C#I I'm lost how to do it and hope that someone would lend some assistance. Of course any other suggestions or solution would be welcomed.

                Thank you


                Code:
                #region ENUM
                public enum dpoMAType 
                {
                Median, ADXVMA, Butterworth_2, Butterworth_3, DEMA, DSMA, DTMA, DWMA, Ehlers, EMA, Gauss_2, Gauss_3, Gauss_4, HMA, HoltEMA, LinReg, SMA, SuperSmoother_2, SuperSmoother_3, TEMA, Tillson_T3, TMA, TSMA, TWMA, VWMA, WMA,  ZeroLagHATEMA, ZeroLagTEMA, ZLEMA
                }
                
                                
                #region Variables
                    private dpoMAType     maType    = dpoMAType.SMA;
                
                    private IDataSeries valueFastMA;
                    private IDataSeries valueSlowMA;
                    
                    private DataSeries    dpoFastDataSeries;
                    private DataSeries    dpoSlowDataSeries;
                
                    
                #region Methods    
                    private  void scanMA(dpoMAType maType, ref IDataSeries maValue, IDataSeries maInput, int maPeriod)
                        {
                            switch (maType)
                            {
                                case dpoMAType.Median: 
                                    maValue = anaMovingMedian(maInput, maPeriod);
                                    break;
                                    
                            //Other MAs in here    
                                    
                                case dpoMAType.ZLEMA: 
                                    maValue = ZLEMA(maInput, maPeriod);
                                    break;
                            }
                        }
                
                        
                #region Initialize
                        dpoFastDataSeries    =    new DataSeries(this);
                        dpoSlowDataSeries    =    new DataSeries(this);
                
                        
                #region OnStartup
                       //switch (xxx)
                        case dpoSpeed.Both:
                            smaSlowDPO = SMA(dpoSlowDataSeries, smooth);
                            smaFastDPO  = SMA(dpoFastDataSeries,  smooth);
                
                
                
                                        if(fastOption)
                            {
                                ...
                                
                                //prototype for method scanMA
                                //private void scanMA(dpoMAType maType, ref IDataSeries maValue, 
                                                  IDataSeries maInput, int maPeriod)
                                
                                                //method call for fast period
                                scanMA(maType, ref valueFastMA, Input, fastPeriod);
                            }
                
                            if (slowOption)
                            {
                                ...
                                //method call for slow period
                                scanMA(maType, ref valueSlowMA, Input, slowPeriod);
                            }
                
                             
                #region Properties
                    [Description("Moving average type")]
                    [Category("Parameters")]
                    [Gui.Design.DisplayNameAttribute("Moving Average Type")]
                    public dpoMAType MAType
                    {
                        get { return maType; }
                        set { maType = value; }
                    }
                If you want to specify a different dpoMAType for different moving averages, then you need to declare different dpoMAType variables for holding said moving averages. Is there something else that I am not understanding?

                Comment


                  #9
                  Originally posted by koganam View Post
                  If you want to specify a different dpoMAType for different moving averages, then you need to declare different dpoMAType variables for holding said moving averages. Is there something else that I am not understanding?
                  I probably wasn't clear in my description of what I want to be able to do.

                  The "scan" method defaults to the "dpoMaType" which is used for the 2 MAs in the code. I have a different indicator that I'm working that has 5 MAs and I want to be able to use the same method for all of them but don't know how to set up the method to accept passing it a different Type.

                  I am probably not using the correct terminology here which is adding to the confusion. The first parameter of the method is a IDataSeries that defaults to dpoMaType and I don't know how to override it to pass in a different one.

                  What I failed to explain in the sample both MAs automatically use the same user selected MA, In my new indicator what I would want is for the user to be able to select different MA Types for each one of the MAs. I believe that requires being able to pass a different IDataSeries into the method which I can't do now.

                  Hopefully that makes things a bit clearer.
                  Last edited by Cheech; 07-13-2016, 09:27 AM.

                  Comment


                    #10
                    Originally posted by Cheech View Post
                    I probably wasn't clear in my description of what I want to be able to do.

                    The "scan" method defaults to the "dpoMaType" which is used for the 2 MAs in the code. I have a different indicator that I'm working that has 5 MAs and I want to be able to use the same method for all of them but don't know how to set up the method to accept passing it a different Type.

                    I am probably not using the correct terminology here which is adding to the confusion. The first parameter of the method is a IDataSeries that defaults to dpoMaType and I don't know how to override it to pass in a different one.

                    What I failed to explain in the sample both MAs automatically use the same user selected MA, In my new indicator what I would want is for the user to be able to select different MA Types for each one of the MAs. I believe that requires being able to pass a different IDataSeries into the method which I can't do now.

                    Hopefully that makes things a bit clearer.
                    I believe that is what I understood you to mean. My answer is still the same.

                    You declare, and expose as public as many dpoMaType as you need, then pass each to the scan() method as needed.
                    Code:
                    private dpoMAType     maType1    = dpoMAType.SMA; //SMA will be the default for maType1. You can choose any type to be the default.
                    private dpoMAType     maType2    = dpoMAType.EMA; //EMA will be the default for maType1.
                    private dpoMAType     maType3    = dpoMAType.HMA;
                    private dpoMAType     maType4    = dpoMAType.HMA;
                    ...
                    Now, declare public properties to expose the private backing stores, using what you already have for your single MAType as a template, one public property per backing store.

                    In the code, you will pass maType1 and/or maType2 et.c to the scan() method. Better yet, pass the public properties directly.

                    Comment


                      #11
                      Hi koganam:

                      Thank you for you response and the directions

                      Unfortunately the only thing I will be able to "declare and expose" is my complete lack of understanding of what you described. As a retired programmer (for 10+ years now so you can get a good estimate of my age and metal capabilities at this time) and while I was a pretty good IBM 360/370 mainframe Assembler Language programmer that language is completely on the other side of the spectrum of today's OO languages and my ability to understand the principles behind them.

                      While I have written a number of indicators when it come to something outside of C# logical and math instructions (which I can lookup), to write the NS portions I depend on looking at the code written by others and follow their lead. I've managed to get things to work without understanding the "whats" and "whys" of the code. In short, you lost me.


                      Allow me to propose the following:

                      The code in the snippet was from an indicator I wrote over a year ago (it's been posted on Big Mikes and downloaded about 1100 times if I recall). The theory was from an article in S&C magazine and NT wrote the indicator on which mine is based. As I mentioned earlier it has 2 MAs of which the type used is user select-able, however the same type is used for both plots.

                      This is not the indicator that I intend to modify as per the code request. However, if you could modify it such that 2 different MA types can be selected (using the method, ENUM, and associated MA Type entries) I would be able to review what you have done and use it in the target indicator.

                      If you decide to do so I have attached the complete code for the.DetrendedPriceOscillator (as a .cs file) . In either event I do appreciate your guidance and responses.
                      Attached Files

                      Comment


                        #12
                        Originally posted by Cheech View Post
                        Hi koganam:

                        Thank you for you response and the directions

                        Unfortunately the only thing I will be able to "declare and expose" is my complete lack of understanding of what you described. As a retired programmer (for 10+ years now so you can get a good estimate of my age and metal capabilities at this time) and while I was a pretty good IBM 360/370 mainframe Assembler Language programmer that language is completely on the other side of the spectrum of today's OO languages and my ability to understand the principles behind them.

                        While I have written a number of indicators when it come to something outside of C# logical and math instructions (which I can lookup), to write the NS portions I depend on looking at the code written by others and follow their lead. I've managed to get things to work without understanding the "whats" and "whys" of the code. In short, you lost me.


                        Allow me to propose the following:

                        The code in the snippet was from an indicator I wrote over a year ago (it's been posted on Big Mikes and downloaded about 1100 times if I recall). The theory was from an article in S&C magazine and NT wrote the indicator on which mine is based. As I mentioned earlier it has 2 MAs of which the type used is user select-able, however the same type is used for both plots.

                        This is not the indicator that I intend to modify as per the code request. However, if you could modify it such that 2 different MA types can be selected (using the method, ENUM, and associated MA Type entries) I would be able to review what you have done and use it in the target indicator.

                        If you decide to do so I have attached the complete code for the.DetrendedPriceOscillator (as a .cs file) . In either event I do appreciate your guidance and responses.
                        That is one of Harry's works, and it was not designed to be used with mixed moving averages, so I cannot really make sense of any such modification.

                        I shall see if I have some time, and write a simple MA crossover skeleton for you, which allows you to use an enum and different types of moving averages in a mixed manner.

                        Comment


                          #13
                          Originally posted by koganam View Post
                          That is one of Harry's works, and it was not designed to be used with mixed moving averages, so I cannot really make sense of any such modification.

                          I shall see if I have some time, and write a simple MA crossover skeleton for you, which allows you to use an enum and different types of moving averages in a mixed manner.
                          Great, thank you koganmen. Best that I can ask for.

                          Also actually that is not Harry's work, It is exactly how I stated (see screen shot) Granted, and as I had mentioned, much of my coding was learned by reading code written by others, and Harry is definitely one of those. And I do use his coding concepts and sometimes directly copy his code and tweak it to meet my needs Many of the MA Types were written by Harry.

                          However If I embed or directly use any of his or any one else's indicators in my code I always acknowledge it in the write up when I post the indicator.. If you notice in the write up (in the SS) I acknowledged Zondor for his instructing me on how to make it more efficient which I did in a later version.

                          You are correct that the DPO indicator is not designed or intended to be used with mixed MA types, I followed what Barbara Starr, the author of the article, states on it's use. In her example she used 2 instances of the DPO with different periods and showed them in different panels. I combined then into one indicator, added the region coloring, and allowed for the selection of different MA Types, and a few other minor enhancements.

                          I only picked it as a test case because if it were modified to do mixed MAs that is exactly what I need for the one I am now writing. I have no intention of posting the modified one. My only purpose in suggesting that you use it was only so I could see how it's done and I am familiar with the code. Of course your way will work too, that's your call.

                          I will do the same for your contribution when I post it.
                          Last edited by Cheech; 07-14-2016, 10:49 PM.

                          Comment


                            #14
                            Originally posted by Cheech View Post
                            Great, thank you koganmen. Best that I can ask for.

                            Also actually that is not Harry's work, ...
                            I apologize for jumping to a conclusion. I saw the telltale of how he names his variables, and I jumped to the wrong conclusion.

                            I have posted the sections of a demo indicator in here, so that I can use your request as a teaching tool for any who want to see some of the ideas involved.

                            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.Gui.Chart;
                            #endregion
                            using CheechMixedAveragesDemoNS; 
                            //We isolate our primitive into its own namespace, so that 
                            //we do not have name clashes, even if someone has, as 
                            //instructed by NT, polluted the global namespace with the 
                            //same type name.
                            //We bring the namespace into scope with the immediate antecedent 
                            //'using' declaration.
                            namespace CheechMixedAveragesDemoNS
                            {
                                public enum MovAvgType
                                    {
                                        Median, 
                                        ADXVMA, 
                                        Butterworth_2, 
                                        Butterworth_3, 
                                        DEMA, 
                                        DSMA, 
                                        DTMA, 
                                        DWMA, 
                                        Ehlers, 
                                        EMA, 
                                        Gauss_2, 
                                        Gauss_3, 
                                        Gauss_4, 
                                        HMA, 
                                        HoltEMA, 
                                        LinReg, 
                                        SMA, 
                                        SuperSmoother_2, 
                                        SuperSmoother_3, 
                                        TEMA, 
                                        Tillson_T3, 
                                        TMA, 
                                        TSMA, 
                                        TWMA, 
                                        VWMA, 
                                        WMA,  
                                        ZeroLagHATEMA, 
                                        ZeroLagTEMA, 
                                        ZLEMA
                                    }
                            }
                            
                            // This namespace holds all indicators and is required. Do not change it.
                            namespace NinjaTrader.Indicator
                            {
                                /// <summary>
                                /// Demonstrate using different moving averages as user choices.
                                /// </summary>
                                [Description("Demonstrate using different moving averages as user choices.")]
                                public class CheechMixedAveragesDemo : Indicator
                                {
                                    #region Variables
                                    //Define as many MovAvgType objects as you need. Here we need 2.
                                    private MovAvgType maFastType = MovAvgType.HMA; // Default setting for FastMA
                                    private MovAvgType maSlowType = MovAvgType.SMA; // Default setting for SlowMA
                                    
                                    private int maFastPeriod = 5; // Default setting for maFastPeriod
                                    private int maSlowPeriod = 13; // Default setting for maSlowPeriod
                                    
                                    private PriceType maFastInput = PriceType.Close; //default PriceType
                                    private PriceType maSlowInput = PriceType.Close;
                                    
                                    //Declare Indicator objects that will be assigned as moving average types
                                    private Indicator maFast = null;
                                    private Indicator maSlow = null;
                            
                                    #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()
                                    {
                                        //Remove these next 2 lines if you do not need to see the Plots
                                        //Also remove the corresponding public properties, as marked. q.v.
                                        Add(new Plot(Color.FromKnownColor(KnownColor.RoyalBlue), PlotStyle.Line, "FastMA"));
                                        Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "SlowMA"));
                                        Overlay                = true;
                                        
                                        maFast = SMA(this.maFastPeriod); //can be any indicator. It is just used to initialize the indicator holder
                                        maSlow = SMA(this.maSlowPeriod); //can be any indicator. It is just used to initialize the indicator holder
                                    }
                                    
                                    protected override void OnStartUp()
                                    {
                                        //We reassign our indicators to the desired moving average
                                        SetMovAvg(this.MaFastType, ref this.maFast, this.MaFastInput, this.MaFastPeriod);
                                        SetMovAvg(this.MaSlowType, ref this.maSlow, this.MaSlowInput, this.MaSlowPeriod);
                                    }
                            
                                    /// <summary>
                                    /// Called on each bar update event (incoming tick)
                                    /// </summary>
                                    protected override void OnBarUpdate()
                                    {
                                        //Assign our Plots values from the moving averages, 
                                        //so that we can see them on the chart
                                        //You do not need to have created the Plots if you
                                        //do not need to see them on a chart.
                                        //**** In which case, remove all the Plot semantics, 
                                        //and these next 2 lines.
                                        FastMA.Set(maFast[0]);
                                        SlowMA.Set(maSlow[0]);
                            
                                        //Do something with all that. You can use the moving averages, or you can use the Plots.
                                        //Here we use the moving averages.
                                        if (CrossAbove(this.maFast, this.maSlow, 1))
                                        {
                                            DrawArrowUp("AU" + CurrentBar.ToString(), 0, Low[0] - 5 * TickSize, Color.Blue);
                                        }
                                        else if (CrossBelow(this.maFast, this.maSlow, 1))
                                        {
                                            DrawArrowDown("AD" + CurrentBar.ToString(), 0, High[0] + 5 * TickSize, Color.Purple);
                                        }
                                    }
                            
                                    #region Private Methods    
                                    private void SetMovAvg(MovAvgType maType, ref Indicator maValue, PriceType maInput, int maPeriod)
                                    {
                                        IDataSeries inputPrice = null;
                                        switch (maInput) 
                                        {
                                            case PriceType.High:
                                                inputPrice = High;
                                                break;
                                            case PriceType.Low:
                                                inputPrice = Low;
                                                break;
                                            case PriceType.Median:
                                                inputPrice = Median;
                                                break;
                                            case PriceType.Open:
                                                inputPrice = Open;
                                                break;
                                            case PriceType.Typical:
                                                inputPrice = Typical;
                                                break;
                                            case PriceType.Weighted:
                                                inputPrice = Weighted;
                                                break;
                                            default:
                                            case PriceType.Close:
                                                inputPrice = Close;
                                                break;
                                        }
                                        
                                        switch (maType)
                                        {
                                            case MovAvgType.EMA: 
                                                maValue = EMA(inputPrice, maPeriod);
                                                break;
                                            case MovAvgType.HMA: 
                                                maValue = HMA(inputPrice, maPeriod);
                                                break;
                                                
                                        //Other MAs in here    
                                                
                                            case MovAvgType.ZLEMA: 
                                                maValue = ZLEMA(inputPrice, maPeriod);
                                                break;
                                            default: 
                                                maValue = ZLEMA(inputPrice, maPeriod);
                                                break;
                                        }
                                    }
                                    
                                    #endregion
                                    
                                    #region Public Properties
                                    //***** Remove these next 2 properties if you do not need to see the Plots
                                    [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 FastMA
                                    {
                                        get { return Values[0]; }
                                    }
                            
                                    [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 SlowMA
                                    {
                                        get { return Values[1]; }
                                    }
                                    //**** end of declarations to remove, if necessary to not show Plots.
                            
                                    [Browsable(true)]
                                    [GridCategory("Parameters")]
                                    public PriceType MaFastInput
                                    {
                                        get { return maFastInput; }
                                        set { maFastInput = value; }
                                    }
                                    
                                    [Browsable(true)]
                                    [GridCategory("Parameters")]
                                    public PriceType MaSlowInput
                                    {
                                        get { return maSlowInput; }
                                        set { maSlowInput = value; }
                                    }
                            
                                    [Description("")]
                                    [GridCategory("Parameters")]
                                    //by using the FQPN, we ensure that we reference the correct type, 
                                    //even if someone has, as instructed by NT, polluted the global 
                                    //namespace with the same type name.
                                    public CheechMixedAveragesDemoNS.MovAvgType MaFastType
                                    {
                                        get { return maFastType; }
                                        set { maFastType = value; }
                                    }
                            
                                    [Description("")]
                                    [GridCategory("Parameters")]
                                    public CheechMixedAveragesDemoNS.MovAvgType MaSlowType
                                    {
                                        get { return maSlowType; }
                                        set { maSlowType = value; }
                                    }
                            
                                    [Description("")]
                                    [GridCategory("Parameters")]
                                    public int MaFastPeriod
                                    {
                                        get { return maFastPeriod; }
                                        set { maFastPeriod = Math.Max(1, value); }
                                    }
                            
                                    [Description("")]
                                    [GridCategory("Parameters")]
                                    public int MaSlowPeriod
                                    {
                                        get { return maSlowPeriod; }
                                        set { maSlowPeriod = Math.Max(1, value); }
                                    }
                                    #endregion
                                }
                            }
                            Enjoy!
                            Last edited by koganam; 09-11-2017, 04:45 PM. Reason: Corrected spelling and used public properties instead of the backing stores.

                            Comment


                              #15
                              Originally posted by koganam View Post
                              I apologize for jumping to a conclusion. I saw the telltale of how he names his variables, and I jumped to the wrong conclusion.

                              I have posted the sections of a demo indicator in here, so that I can use your request as a teaching tool for any who want to see some of the ideas involved.
                              Certainly no apologies are necessary.

                              That is very cool code sir.

                              I was surprised how close I got to it,albeit nowhere near as sophisticated. I only had four declarations missing. Of course I never would have figured out what was missing and how to code them without your very kind assistance, thank you.

                              I think I will use your code as a base and see if I can correctly fit in all of the MA plots I'm using without the rest of the logic. Once I get that working I'll copy and paste it into my indi (copy/paste??? kind of a neat pair of words to replace "plagiarize").

                              Thank you so much.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,602 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X