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 terofs, Today, 04:18 PM
        0 responses
        3 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        4 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by GwFutures1988, Today, 02:48 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        6 responses
        33 views
        0 likes
        Last Post ScottWalsh  
        Working...
        X