Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Adding/Attaching an indicator to a multi-time series BarsArray data series

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

    Adding/Attaching an indicator to a multi-time series BarsArray data series

    I am trying to add indicators to multi-time data series (BarsArray[]) in a strategy.

    First I tried to do this via Add() in Initialize(), only to find out that the object is not fully constructed at that point and therefore not accessible. However, I do not want to call the indicators on every OnBarUpdate() as I have seen proposed in other threads. The indicators I am using have a huge number of parameters and are unwieldy. They are not as simple as calling SMA(BarsArray[1],10). More like CustomIndi(BarsArray[1],param1, param2.... param50!).

    I have in Initialize() :

    Code:
    Add( PeriodType.Minute, timeframePeriodHTF1 );
    Add( PeriodType.Minute, timeframePeriodHTF2 );
    Add( PeriodType.Minute, timeframePeriodHTF3 );
    Add( PeriodType.Minute, timeframePeriodHTF4 );
    Ideally I would like to do something like this in Initialize() :

    Code:
    // Attach multiple indicators to the first time series:
    Add( BarsArray[1], CustomIndi1( param1, param2, ... param50 ) );
    Add( BarsArray[1], CustomIndi2( param1, param2, ... param50 ) );
    But the compiler complains that I cannot reference BarsArray[] in Initialize(). So I tried calling Add() in OnStartUp() and the compiler complained that I cannot call Add() in there.

    I want to attach various indicators to each of these BarsArray[] data series so that I don't have to resort to calling every indicator for every BarsArray[] in OnBarUpdate().

    How can I do that?

    #2
    Hi risingfire,

    When it comes to visual stuff on a chart, it is not possible to use a secondary dataseries for adding an indicator. This is because the primary dataseries is what creates the price points on the chart. Similarly, if you try and add an indicator on a chart using a dataseries that is not on the chart, this is not possible and there is no way to do it.

    Thus, you will only be able to add indicators and draw objects using the primary dataseries.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by risingfire View Post
      I am trying to add indicators to multi-time data series (BarsArray[]) in a strategy.

      First I tried to do this via Add() in Initialize(), only to find out that the object is not fully constructed at that point and therefore not accessible. However, I do not want to call the indicators on every OnBarUpdate() as I have seen proposed in other threads. The indicators I am using have a huge number of parameters and are unwieldy. They are not as simple as calling SMA(BarsArray[1],10). More like CustomIndi(BarsArray[1],param1, param2.... param50!).

      I have in Initialize() :

      Code:
      Add( PeriodType.Minute, timeframePeriodHTF1 );
      Add( PeriodType.Minute, timeframePeriodHTF2 );
      Add( PeriodType.Minute, timeframePeriodHTF3 );
      Add( PeriodType.Minute, timeframePeriodHTF4 );
      Ideally I would like to do something like this in Initialize() :

      Code:
      // Attach multiple indicators to the first time series:
      Add( BarsArray[1], CustomIndi1( param1, param2, ... param50 ) );
      Add( BarsArray[1], CustomIndi2( param1, param2, ... param50 ) );
      But the compiler complains that I cannot reference BarsArray[] in Initialize(). So I tried calling Add() in OnStartUp() and the compiler complained that I cannot call Add() in there.

      I want to attach various indicators to each of these BarsArray[] data series so that I don't have to resort to calling every indicator for every BarsArray[] in OnBarUpdate().

      How can I do that?
      Use named instances. Declare them as class objects, then initialize them in OnStartUp() or with an escape on (CurrentBars == 0). Every indicator can take a price series as an input, so specify it as part of the calling signature when you initialize your named instances.

      Comment


        #4
        Originally posted by koganam View Post
        Use named instances. Declare them as class objects, then initialize them in OnStartUp() or with an escape on (CurrentBars == 0). Every indicator can take a price series as an input, so specify it as part of the calling signature when you initialize your named instances.
        Ah, sure. *Thank you*, that's exactly what I was aiming for. I don't need these to plot on the chart, just need them to calculate on each bar.

        Comment


          #5
          Hi risingfire,

          If you do not need the indicators to plot on the chart then you do not need to add them to your script.

          Instead, you can just call the indicator any time you would like.

          The Add() method for strategies is only to have the added indicator plot on the chart.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hi risingfire,
            The Add() method for strategies is only to have the added indicator plot on the chart.
            Thanks, that just became clear to me. I was thinking that Add() was simply a method to add the dataseries/indicator to the analysis engine. But now I understand that it is really intended to both perform calculations AND make it available to the chart. So great... much appreciated for the clarification to both you and @koganam.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            21 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X