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 egordleo, Today, 05:50 AM
            0 responses
            4 views
            0 likes
            Last Post egordleo  
            Started by kevinenergy, 02-17-2023, 12:42 PM
            118 responses
            2,778 views
            1 like
            Last Post kevinenergy  
            Started by briansaul, Today, 05:31 AM
            0 responses
            9 views
            0 likes
            Last Post briansaul  
            Started by fwendolynlpxz, Today, 05:19 AM
            0 responses
            4 views
            0 likes
            Last Post fwendolynlpxz  
            Started by traderqz, Yesterday, 12:06 AM
            11 responses
            28 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X