Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Specify second BarsArray instrument at run time

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

    Specify second BarsArray instrument at run time

    Hey,

    Is it possible to set specify a second instrument in the following manner under Initialize():

    Add(myInstrument, myPeriodType, myPeriod);

    Where the three parameters would be set in the Strategy Analyzer at run time ("FGBL ##-##", PeriodType.Minute, 1) so that you can easily choose a second instrument for a strategy.

    If I can't do this then I would need to rewrite my code any time I wanted to change the second BarsArray instrument correct?

    Thanks,
    darmbk.

    #2
    Hello darmbk,

    Thank you for your inquiry.

    While unsupported, it is possible to do this. Please note, however, that attempting to optimize these values through the Strategy Analyzer would not work as the Initialize() method is only run once.

    What you could do is create three variables. Example:
    Code:
    private int period = 1;
    private string instrument = "AAPL";
    private PeriodType thePeriod = PeriodType.Minute;
    And then create three properties that will allow you to change these variables. Example:
    Code:
    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int Period
    {
         get { return period; }
         set { period = Math.Max(1, value); }
    }
    [Description("")]
    [GridCategory("Parameters")]
    public string Instrument
    {
         get { return instrument; }
         set { instrument = value; }
    }
    [Description("")]
    [GridCategory("Parameters")]
    public PeriodType ThePeriod
    {
         get { return thePeriod; }
         set { thePeriod = value; }
    }
    #endregion
    You will then be able to change these parameters through the Strategy Analyzer.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Hey ZacharyG,

      For these purposes, is it possible to reference the 'Data series' parameters that would be set manually in the Strategy Analyzer gui? Specifically, Type and Value will be the same for the second instrument so it would be efficient to simply refer to their values rather than redefine them with separate variables 'period' and 'thePeriod' as you have suggested.

      Thanks,
      darmbk.

      Comment


        #4
        Hello darmbk,

        You would be able to access the bar type and value of the primary Data Series by using BarsPeriod.Id and BarsPeriod.Value, respectively.

        Please take a look at this link in the NinjaTrader help guide for further information about BarsPeriod: http://ninjatrader.com/support/helpG...barsperiod.htm
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Hey ZacharyG,

          The page you refer to notes that these properties "should NOT be accessed within the Initialize() method". Does this simply mean both methods you have suggested are unsupported and if this is the case, is one of these methods 'less correct' than the other? If there's no difference then it would seem that using the BarsPeriod method is neater for sure.

          Cheers,
          darmbk.

          Comment


            #6
            Hello darmbk,

            The help guide says this because there may be times that the primary Bars object has not yet loaded and will return an error. This is why we recommend against this. It's not guaranteed to work 100% of the time.

            Manually specifying the period and value as I've outlined in my initial reply would be more reliable:

            Code:
            private PeriodType thePeriod = PeriodType.Minute;
            private int period = 1;
            
            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public PeriodType ThePeriod
            {
                 get { return thePeriod; }
                 set { thePeriod = value; }
            }
            
            [Description("")]
            [GridCategory("Parameters")]
            public int Period
            {
                 get { return period; }
                 set { period = Math.Max(1, value); }
            }
            #endregion
            Zachary G.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Rapine Heihei, 04-23-2024, 07:51 PM
            2 responses
            30 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by Shansen, 08-30-2019, 10:18 PM
            24 responses
            943 views
            0 likes
            Last Post spwizard  
            Started by Max238, Today, 01:28 AM
            0 responses
            9 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by rocketman7, Today, 01:00 AM
            0 responses
            5 views
            0 likes
            Last Post rocketman7  
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            28 views
            0 likes
            Last Post wzgy0920  
            Working...
            X