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

Extract indicator from a strategy

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

    Extract indicator from a strategy

    Dear NT team,

    I am using sharkindicators/bloodhound very extensively and tried to "avoid" coding in Ninjascript so far.

    Currently I try to rebuild the following strategy in bloodhound
    www.ninjatrader.com/SC/October2014SC.zip

    Therefore I would like to "extract" the indicator code in the strategy into an separate indicator.

    Please find attached:
    a) Original code of the strategy SveRenkoCross
    and
    b) the extracted indicator code. The changes are highlighted with //

    The indicators are not plot on the chart when the indicator is selected.

    What am I doing wrong?

    Any help is highly appreciated.

    guw75
    Attached Files

    #2
    Hello guw75,

    Thank you for writing in.

    I am not clear by what you mean by extracting the indicator code in the strategy.

    Indicators and strategies are two different types of NinjaScript objects. I see you have commented out strategy methods and other strategy syntax in your indicator. You cannot use strategy methods and syntax in an indicator.

    The strategy code provided does not contain any logic of how the indicator plots its values. In order to look at the logic of the indicator, you would need to open the indicator's .cs file. To take a look at SVEhaClose's source code, click on Tools -> Edit NinjaScript -> Indicator in the Control Center.

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Hi Zachary,

      ok.

      I have copied the strategy code into an indicator.cs file and have excluded the strategy syntax via //.

      The indicator code SVEhaClose please find enclosed.
      How do I add an SMA based on typical prices?

      Instead of three separate indicators, I would like to have one indicator with
      SVEhaClose,
      SMA (8) based on typical prices and
      SMA (21) based on closed prices.
      Attached Files

      Comment


        #4
        Hello guw75,

        You would need to add two additional plots to the SVEhaClose indicator and assign each of these plots to the current value of SMA(Typical, 8) and SMA(21).

        For example:
        Code:
        protected override void Initialize()
        {
             // previous added plots
             Add(new Plot(Color.Blue, PlotStyle.Line, "SMA1"));
             Add(new Plot(Color.Green, PlotStyle.Line, "SMA2"));
        }
        
        protected override void OnBarUpdate()
        {
             // previous OnBarUpdate() logic
             Values[2].Set(SMA(Typical, 8)[0]);
             Values[3].Set(SMA(21)[0]);
        }
        For more information about Add(), please take a look at this link: http://ninjatrader.com/support/helpGuides/nt7/?add.htm

        For more information about Values, please take a look at this link: http://ninjatrader.com/support/helpG...t7/?values.htm
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Hi Zachary,

          I have done as suggested. It works fine. Thank you very much.

          Furthermore I have experimented with ENUM/SWITCH function today
          as described here



          in order to select the price type data per drop down in the parameter section of the indicator for calculating the SMA.

          I am able to compile the file. The code should be working.

          But I am missing the dropdown menue in the parameter section of the indicator in order to select the price type.
          I have verified the code now several times. Could you please check where the issue could be?
          Thank you very much in advance
          Attached Files

          Comment


            #6
            Hello guw75,

            This is occurring because PriceType is an already existing property: http://ninjatrader.com/support/helpG...?pricetype.htm

            You will need to change the name of your enum's public property to something other than PriceType.

            Please, let us know if we may be of further assistance.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Hi Zachary,

              thanks. It works now as intended. Very good.

              If I want to define a individual pricetype for each of the three sma's. More specifically:
              The list of pricetypes to select from would be identical for each of the sma's (High, Low, Close etc). E.g. I want to be able to select pricetype 1 for sma 1, pricetype 4 for sma 2 and pricetype 2 for sma 3)

              1) Do I have to define 3 different enums and 3 different switch statements for that?
              2) or is there a way to use only 1 public enum?

              Comment


                #8
                Hello guw75,

                You'll just want to create two other variables of type SVERenkoCrossInput (your already created enum). You'll also need two other public properties for these variables so the user can select which enum value to use.

                I would suggest taking a look at this link on Dot Net Perls for further information on utilizing enums: http://www.dotnetperls.com/enum

                Please, let us know if we may be of further assistance.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Zacary,

                  thank you very much for your patience. I am not yet a coder.

                  do you mean changes like this:

                  for the variables:

                  Code:
                   
                   #region Variables
                   ...
                  
                   private SVERenkoCrossInput typeofprice1 = fastMA.Typical;
                   private SVERenkoCrossInput typeofprice2 = longMA.Close;
                   private SVERenkoCrossInput typeofprice3 = slowMA.High;
                    
                   ...
                   #endregion
                  and

                  for the properties:
                  Code:
                   
                   /// <summary>
                   /// </summary>
                   [Description("Price type used for calculating MA's")]
                   [GridCategory("Parameters for calculating MA'S")]
                   [Gui.Design.DisplayNameAttribute("Price type of fast MA")]
                   public SVERenkoCrossInput TypeofPrice1
                   {1
                   get { return typeofprice1; }
                   set { typeofprice1 = value; }
                   }
                   
                   [Description("Price type used for calculating MA's")]
                   [GridCategory("Parameters for calculating MA'S")]
                   [Gui.Design.DisplayNameAttribute("Price type of long MA")]
                   public SVERenkoCrossInput TypeofPrice2
                   {
                   get { return typeofprice2; }
                   set { typeofprice2 = value; }
                   }
                   
                   
                   [Description("Price type used for calculating MA's")]
                   [GridCategory("Parameters for calculating MA'S")]
                   [Gui.Design.DisplayNameAttribute("Price type of slow MA")]
                   public SVERenkoCrossInput  TypeofPrice3
                   {
                   get { return typeofprice3; }
                   set { typeofprice3 = value; }
                   }
                   
                   
                   #endregion
                  Are there any changes necessary to the switch statement?

                  Comment


                    #10
                    Hello guw75,

                    Yes, this is correct.

                    You'll need to add additional switch statements to correspond to each of the variables as well.

                    Please, let us know if we may be of further assistance.
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Zachary,

                      it works now. I had to add 2 additional idataseries as well.

                      Thank you very much for support.

                      Please find attached the last version. I have reworked the syntax of the variables to make it somewhat easier to reconcile the workflow.

                      Is the code ok for this purpose or is there anything what can be done more efficiently?

                      My last questions for today: Where can I change the yellow marked plots in the screenshot?
                      1) CalculateOnBarClose: is set to false in the code but here it will be shown as true
                      2) Panel: Standard should be set to "same as input series".
                      3) Plots: Where do I change the names of the dataseries in the code? in the code I have changed it actually to "fast MA", "long MA", "slow MA"

                      Best regards and a happy weekend

                      guw75
                      Attached Files

                      Comment


                        #12
                        Hello guw75,

                        To answer your questions:
                        1. Please ensure that you have removed your indicator, selected OK, and reopen the Indicators window and add the indicator again. CalculateOnBarClose should be set to false now as set in the code.

                        2. Change the Overlay property in Initialize() to true. This update will not take effect until you have followed the instructions above.

                          For more information about the Overlay propertly, please take a look at this help guide link: https://ninjatrader.com/support/help...7/?overlay.htm

                        3. It looks like you have already done the modification of names:
                          Code:
                          Add(new Plot(Color.Cyan, PlotStyle.Line, "Fast MA"));
                          Add(new Plot(Color.Green, PlotStyle.Line, "Long MA"));
                          Add(new Plot(Color.Gold, PlotStyle.Line, "Slow MA"));
                          You'll need to follow the instructions in the first answer.


                        When making any changes in Initialize(), you'll need to follow the instructions of answer 1.

                        Please, let us know if we may be of further assistance.
                        Zachary G.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by elirion, Today, 01:36 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post elirion
                        by elirion
                         
                        Started by gentlebenthebear, Today, 01:30 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post gentlebenthebear  
                        Started by samish18, Yesterday, 08:31 AM
                        2 responses
                        9 views
                        0 likes
                        Last Post elirion
                        by elirion
                         
                        Started by Mestor, 03-10-2023, 01:50 AM
                        16 responses
                        391 views
                        0 likes
                        Last Post z.franck  
                        Started by rtwave, 04-12-2024, 09:30 AM
                        4 responses
                        34 views
                        0 likes
                        Last Post rtwave
                        by rtwave
                         
                        Working...
                        X