Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

example of working with two existing data series in the chart

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

    example of working with two existing data series in the chart

    My use case is to compare the two data series I added to the chart, and highlight when some correlation status breaks.

    How do I make the indicator to dynamically get the references or names of the two series in the code?

    Or, any example indicator that works with two data series on the chart?



    Click image for larger version

Name:	image.png
Views:	367
Size:	68.3 KB
ID:	1234192

    #2
    Hello leontancfa,

    Thanks for your post.

    A NinjaScript indicator is only able to get the values of the primary data series the script is enabled on when adding the indicator to a chart.

    To get values from a second data series, you must add a secondary data series to the indicator script by using the AddDataSeries() method.

    AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm

    You could then use the PriceSeries collection to access price values from the primary or secondary added series. For example, Close[0] would get the current close price from the primary data series the script is running on. Closes[1][0] would get the current close price from the added secondary data series.

    PriceSeries: https://ninjatrader.com/support/help...riceseries.htm

    It is important to review this help guide page to understand how to work with Multi-Timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm

    Please let me know if I may assist you further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      thanks. do you have example of getting the name of the Data Series 0? so that I can use the name into the AddDataseries block.

      Comment


        #4
        Hello leontancfa,

        Thanks for your note.

        The name of the instrument does not have to be specified when calling AddDataSeries() if you want to use the same instrument for the added series but a different timeframe. In this case the syntax for AddDataSeries() would look something like this.

        AddDataSeries(BarsPeriodType periodType, int period)

        Note that you only have to pass in a 'BarsPeriodType periodType' argument and 'int period' argument,. The instrument will use the same instrument as the primary data series.

        An example of this could be seen in the sample code of the AddDataSeries() help guide page linked in post # 2.

        Let me know if I may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 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
        567 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