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

Pass a property string to Add fuction

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

    Pass a property string to Add fuction

    Strange, if I add

    Add(myInstrString, PeriodType.Range, 4);

    to initialize method, after that it does not give possibilty to enter myInstrString at optimizer.. ? or actually does not show any properties at all to this strategy
    without Add ok or if I add Add directy with
    Add("ES ...", PeriodType.Range, 4);


    region Variables:
    private string myInstrString = @"ES"; // Default setting for MyInstrString

    and properties:

    [Description("test")]
    [GridCategory("Parameters")]
    public string MyInstrString
    {
    get { return myInstrString; }
    set { myInstrString = value; }
    }

    #2
    The whole program as an example:

    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// StringTest
    /// </summary>
    [Description("StringTest")]
    public class MyCustomStrategy : Strategy
    {
    #region Variables
    // Wizard generated variables
    private string myInstrString = @"ES"; // Default setting for MyInstrString
    // User defined variables (add any user defined variables below)
    #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()
    {
    Add(myInstrString, PeriodType.Minute, 1); // this will remove possibility to enter string value at optimizer
    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    PrintWithTimeStamp(myInstrString);
    }

    #region Properties
    [Description("test")]
    [GridCategory("Parameters")]
    public string MyInstrString
    {
    get { return myInstrString; }
    set { myInstrString = value; }
    }
    #endregion
    }
    }

    Comment


      #3
      Have you tried referring to your capitalized public property in the Add(....) call?
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Yes, tried it as well, no difference!?

        Could you check it as it does not take more than one minute to build from scratch.

        -

        Comment


          #5
          Raffu, sure - please see the attached - seems to work well on my end on chart and Strategy Analyzer.
          Attached Files
          BertrandNinjaTrader Customer Service

          Comment


            #6
            and if I change
            Add(myInstrString, PeriodType.Minute, 1);
            to
            Add("ES ..", PeriodType.Minute, 1);

            is it ok as it should...

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              Raffu, sure - please see the attached - seems to work well on my end on chart and Strategy Analyzer.

              Now I'm totally confused. This worked well even I cleaned it up to same level as mine.
              BUT can't get mine to work, not even with different name or anything and can't see the difference at all.


              included.
              Attached Files

              Comment


                #8
                But now I got IT!

                I had only the first part of instrument name there as a default, and thought that I could change it via optimizer but if it is not valid I don't get even so far..

                Comment


                  #9
                  Glad to hear and good spot, correct yours pointed to ES which is not a valid symbol name.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Is there a way to test a string to see if it corresponds to a valid instrument name?
                    If I passed a string that is not a valid instrument name to the Add() method, is there a trappable error that will show that there is something wrong with the new BarsArray object, or a way to check that it has not been created at all?
                    If I am able to trap the error, can I programatically call the Add method again, with a default "known good" instrument name such as the chart master instrument Instrument.FullName?

                    Comment


                      #11
                      Hi Ricam,
                      This is not currently possible but you have some nice ideas that would provide increased flexibility for this style of scripts. Thanks for the feedback, will forward your comments to our product development team. This request for dynamic series adding is assigned tracking id # 179.
                      Last edited by NinjaTrader_RyanM1; 03-21-2012, 07:03 AM.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        I think it can be done by iterating through the instrument list and looking for a match. However there is a minor bug in my code that is preventing the iteration from working.

                        See posts 3 and 4 in this thread.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by alifarahani, Today, 09:40 AM
                        2 responses
                        12 views
                        0 likes
                        Last Post alifarahani  
                        Started by junkone, Today, 11:37 AM
                        3 responses
                        15 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by pickmyonlineclass, Today, 12:23 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post pickmyonlineclass  
                        Started by frankthearm, Yesterday, 09:08 AM
                        12 responses
                        44 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by quantismo, 04-17-2024, 05:13 PM
                        5 responses
                        35 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X