• 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

Initializing indicator w/alternative time frame

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

    Initializing indicator w/alternative time frame

    Hi:

    I'm getting an exception when I attempt the following:

    Code:
            protected override void Initialize()
            {
                try
                {
                    CalculateOnBarClose = true;
                    EntriesPerDirection = 20;
                    EntryHandling = EntryHandling.AllEntries;
                    ExitOnClose = true;
                    TraceOrders = true;
                    SyncAccountPosition = true;
                    Unmanaged = true;
                    
                    myIndicator1 = Indicator1(parameters);
                    myIndicator2 = Indicator2(BarsArray[1]);
                    
                    Add(PeriodType.Tick, BarsPeriod.Value * this.HigherTimeframeMultiple);
    
                    Add(myIndicator1);
                }
                
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
    The exception is thrown when creating myIndicator2 with the higher time frame value:

    "'BarsArray' property can't be accessed from within 'Initialize' method"

    So my question is, where can I instantiate this indicator once? The alternative is calling it on every bar update -

    Second question, somewhat of a derivative of this, is how do I display this higher time frame indicator on the same chart as the base time frame indicator?

    #2
    Hi cgeorgan,

    The BarsArray does not exist in Initialize(), so should be set in OnBarUpdate()

    Please see the following page for details on properly created a Multi-Time series indicator
    http://www.ninjatrader-support.com/H...ameInstruments

    From there, you can set the plot under the appropriate BarsInProgress, for example...

    if (BarsInProgress == 0)
    {
    Plot1.Set(CCI(BarsArray[1], 20)[0]);

    }
    TimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Tim View Post
      Hi cgeorgan,

      The BarsArray does not exist in Initialize(), so should be set in OnBarUpdate()

      Please see the following page for details on properly created a Multi-Time series indicator
      http://www.ninjatrader-support.com/H...ameInstruments

      From there, you can set the plot under the appropriate BarsInProgress, for example...

      if (BarsInProgress == 0)
      {
      Plot1.Set(CCI(BarsArray[1], 20)[0]);

      }
      Yes, this part I follow - However, what this involves is creating a brand new indicator every time (I presume you're making this set call under "BarUpdate").

      So, instead of merely creating an indicator once with the correct "BarsInProgress", then referring to values within that indicator by calling Update() on it, you're saying I need to create a brand new indicator every time a bar is updated.

      Is this the most efficient way of doing this?

      Comment


        #4
        Hi cgeorgan,

        With each OnBarUpdate, the indicator plot value is attached to the bar object, this way you have as many Plot values as you do bars, and can access the plot values by referring to the bar.

        If you are setting this to a variable, the value needs to be placed under OnBarUpdate, as the value would be continually changing.

        If you want to set a variable less often, depending on what you are trying to do, you can use FirstBarOfSession, for example.
        More info at - http://www.ninjatrader-support.com/H...stBarOfSession
        TimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by wishing, Today, 03:21 PM
        0 responses
        2 views
        0 likes
        Last Post wishing
        by wishing
         
        Started by crazyhorse2393, Today, 03:09 PM
        0 responses
        7 views
        0 likes
        Last Post crazyhorse2393  
        Started by forextrader2003, Today, 02:55 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by Sank1, Today, 01:58 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by GARZONJ, Today, 12:50 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Jim  
        Working...
        X