Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem adding 2:nd instrument

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

    Problem adding 2:nd instrument

    Appreciate help on why the custom indicator "VolRATIO" uses the primary data series in this strategy.

    The indicator is a multi instrument indicator that uses the same primary data series as the strategy and adds the "NAVOL" instrument as a second data series. So two questions:

    1. Where do I go wrong?

    2. When a multi instrument indicator adds a second instrument, does this second instrument has to be added once again in the strategy (as bellow), or is it allready added/called by the indicator?


    protectedoverridevoid Initialize()
    {
    Add("NAVOL", PeriodType.Minute, 30);
    Add(SMA(Fast));
    Add(SMA(Slow));
    Add(VolRATIO(2, 65));
    Add(SMA(Fast));
    Add(SMA(Slow));
    Add(VolRATIO(2, 65));
    CalculateOnBarClose = true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(SMA(Fast), SMA(Slow), 29)
    && CrossAbove(VolRATIO(BarsArray[1], 2, 65).Plot0, Vol, 29))
    {
    EnterLong(DefaultQuantity, "");
    }
    // Condition set 2
    if (CrossBelow(SMA(Fast), SMA(Slow), 29)
    && CrossAbove(VolRATIO(BarsArray[1], 2, 65).Plot0, Vol, 29))
    {
    EnterShort(DefaultQuantity, "");
    }
    }

    //Thanks!
    Last edited by FREEN; 05-25-2010, 04:26 PM.

    #2
    Hello Freen,

    You will have to add the series in the strategy as well. For your strategy, BarsArray[1] should refer to the second series (NAVOL, 30 Minute).
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      So, the second data series of the strategy will be used as the primary data series in the indicator in my code?

      What defines which of the dataseries in the strategy is primary and secondary for the indicator? Should I do something like this:

      CrossAbove(VolRATIO(BarsArray[0], BarsArray[1], 2, 65).Plot0, Vol, 29))

      Comment


        #4
        FREEN, the MultiSeries indicator would add / load whatever series were coded in there by you - it would use the dataseries as it's primary series that you run it on in your strategy, so with pointing to BarsArray[1] for the indicator, it would use the NAVOL instrument of your strategy as it's primary one.

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          FREEN, the MultiSeries indicator would add / load whatever series were coded in there by you - it would use the dataseries as it's primary series that you run it on in your strategy, so with pointing to BarsArray[1] for the indicator, it would use the NAVOL instrument of your strategy as it's primary one.
          So, since the primary instrument is (should be) the same for the strategy and the indicator in the strategy, I don´t need to add the secondary instrument of the indicator in the strategy code? Did I get that right?

          Originally posted by NinjaTrader_RyanM View Post
          Hello Freen,

          You will have to add the series in the strategy as well. For your strategy, BarsArray[1] should refer to the second series (NAVOL, 30 Minute).
          Sorry, I´m confused here. The strategy and the indicator runs (should run) on the same primary instrument. My question was refering to if I need to add the secondary instrument of the indicator into the strategy and, if so, how does the the indicator know wich one is primary and secondary.
          Last edited by FREEN; 05-26-2010, 02:55 PM.

          Comment


            #6
            Hello Freen,

            You would need to add the secondary series to the strategy if you use the convention VolRATIO(BarsArray[1]) when evaluating your conditions for entry. BarsArray[1] does not exist in the context of the strategy unless you Add the series.

            If your indicator plots use the secondary series, then you do not have to add to the strategy to reference this. It's not enough to add the series to the indicator, the secondary series must set plots based from it.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Sorry for all these rookie questions. I guess I´m confused by the fact that the indicator intended for the second instrument plots the primary instrument in the backtest panel. Could you point me to the instructions how this is done?

              I thought it simply could be done like this;

              protectedoverridevoid Initialize()
              {
              Add("NAVOL", PeriodType.Minute, 30);
              Add(SMA(Fast));
              Add(SMA(Slow));
              Add(VolRATIO(BarsArray[1], 2, 65));
              Add(SMA(Fast));
              Add(SMA(Slow));
              Add(VolRATIO(BarsArray[1], 2, 65));
              CalculateOnBarClose = true;
              }

              But that code won´t run. (The VolRatio indicator is a single instrument indicator intended for "NAVOL", hence no instrument is added in the indicator code.)
              Last edited by FREEN; 05-30-2010, 07:14 PM.

              Comment


                #8
                FREEN, this will unfortunately not work as you can't access the BarsArray object in the Initialize() method. You could calculate the indicator in the OnBarUpdate() on the the various BarsArrays and then enter trades based on those.

                Comment


                  #9
                  Ok, thanks. But how do I display the indicator plots for the second, third... instruments in the backtest panels?

                  It´s kind of nice to eyeball how all intrument indicators in the strategy are behaving.

                  Comment


                    #10
                    You could for example use the strategy plot technique for this task -

                    When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability

                    Comment


                      #11
                      Thanks Bertrand! The instructions you point to is for "internal strategy calculations that are difficult to migrate to an indicator". What I want is to plot the indicators for the second instrument, just as in a chart. Is this concidered "internal strategy calculations that are difficult to migrate to an indicator"?

                      Is there a way to do this in the strategy analyzer or is this plot setup only possible in the charts?

                      Comment


                        #12
                        FREEN, yes you could use this approach to visualize MultiSeries indicator on the charts (however that would require extra coding as per the sample approach), for NT7 just create a MultiSeries indicator and then just add this to your strategy - this would not require the passing in of the BarsArray dataseries paramter in the strategy, as the indicator itself would add the series and do the necessary MultiSeries calculations needed.

                        MTFIndicator is your indicator running on for example three series in NT7 and plots those.

                        In the strategy Initialize() just go -

                        Add(MTFIndicator(Close)) > this will pass just the primary series to the indicator to use it, the added ones would be taken care of by the indicator internally.

                        Comment


                          #13
                          Originally posted by NinjaTrader_Bertrand View Post
                          FREEN, yes you could use this approach to visualize MultiSeries indicator on the charts (however that would require extra coding as per the sample approach), for NT7 just create a MultiSeries indicator and then just add this to your strategy - this would not require the passing in of the BarsArray dataseries paramter in the strategy, as the indicator itself would add the series and do the necessary MultiSeries calculations needed.
                          The indicator used for the second instrument in the strategy is a single instrument indicator. Do you mean that I could code this indicator as a multi instrument indicator, just not use the primary series in the indicator calculation?
                          Last edited by FREEN; 05-31-2010, 02:06 PM.

                          Comment


                            #14
                            Well, HURRAY! This worked:

                            Originally posted by FREEN View Post
                            The indicator used for the second instrument in the strategy is a single instrument indicator. Do you mean that I could code this indicator as a multi instrument indicator, just not use the primary series in the indicator calculation?
                            It´s just that I have to have one indicator for chart plotting and another for strategy/backtest plotting, however doing the same thing.

                            Thanks lots and sorry for all my confusion in this.

                            Comment


                              #15
                              You're welcome no worries, great you got it worked out.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              630 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              566 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X