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

How to reference multiple instruments and their indicators for a strategy?

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

    How to reference multiple instruments and their indicators for a strategy?

    Hi there!

    My question: How do I reference indicator data from multiple data series inside a strategy using the NS editor?

    Background:
    I have about seven different securities that I track during the day. I use the same indicators on all of them.
    I'd like to reference the results from each indicator for each security, but I'm not sure about how to go about doing that.

    I've looked at a few Ninjascript help articles on multiple series and instruments and saw the examples there.
    If anyone has additional reference articles or some suggestions on how to do this, please post and let me know.

    And feel free to ask questions if I wasn't clear in this post.

    #2
    Hi Spiderbird, thanks for posting.

    You can instantiate indicators with a BarsArray[] selection e.g.

    Code:
    private SMA mySMA;
    
    State.DataLoaded:
    mySMA = SMA(BarsArray[1], 20); //20 period SMA on the second added data series. 
    
    OnBarUpdate:
    if(BarsInProgress == 1)
        Print(mySMA[0]);
    Please let me know if I can assist any further.
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Awesome Chris! . Thank you for that.

      To follow your logic that you put in, let's assume I have four different instruments I'm working with, and want to reference the same indicator in all four. Would the code look like this?

      Code:
      Code:
      private SMA_1 theFirstSMA;  // the simple moving average for the first security (SPY)
      private SMA_2 theSecondSMA;  // the simple moving average for the second security (IWM)
      private SMA_3 theThirdSMA;  // the simple moving average for the third security (APPL)
      private SMA_4 theFourthSMA;  // the simple moving average for the fourth security (SVC)
      private SMA_5 theFifthSMA;  // the simple moving average for the first security (ETC)
      
      State.DataLoaded:
      theFirstSMA = SMA(BarsArray[0], 20);  // this is the primary instrument. I assume it needs representation here
      theSecondSMA = SMA(BarsArray[1], 20);
      theThirdSMA = SMA(BarsArray[2], 20);
      theFourthSMA = SMA(BarsArray[3], 20);
      theFifthSMA = SMA(BarsArray[4], 20);
      
      
      OnBarUpdate:
      if(BarsInProgress == 1)
      Print(theFirstSMA[0]);
      Print(theSecondSMA[0]);
      Print(theThirdSMA[0]);
      Print(theFourthSMA[0]);
      Print(theFifthSMA[0]);
      Let me know if I'm following your example properly.

      Comment


        #4
        Hi Spiderbird, yes that is correct. All of those values should print to the output window.

        Best regards,
        -ChrisL

        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by GussJ, 03-04-2020, 03:11 PM
        15 responses
        3,271 views
        0 likes
        Last Post xiinteractive  
        Started by Tim-c, Today, 02:10 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Taddypole, Today, 02:47 PM
        0 responses
        2 views
        0 likes
        Last Post Taddypole  
        Started by chbruno, 04-24-2024, 04:10 PM
        4 responses
        51 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        10 responses
        403 views
        1 like
        Last Post beobast
        by beobast
         
        Working...
        X