• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.

                        http://www.ninjatrader.com/support/f...ghlight=upshon

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by guvenators, Today, 05:18 PM
                        1 response
                        13 views
                        0 likes
                        Last Post NinjaTrader_ShawnB  
                        Started by LANwarr1or, Today, 03:00 PM
                        2 responses
                        8 views
                        0 likes
                        Last Post LANwarr1or  
                        Started by Newtrader101, Today, 02:53 PM
                        2 responses
                        10 views
                        0 likes
                        Last Post Newtrader101  
                        Started by JuanPabloQuevedo, Today, 02:53 PM
                        2 responses
                        9 views
                        0 likes
                        Last Post JuanPabloQuevedo  
                        Started by samir, Today, 03:16 PM
                        2 responses
                        14 views
                        0 likes
                        Last Post samir
                        by samir
                         
                        Working...
                        X