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:	378
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 cmoran13, 04-16-2026, 01:02 PM
        0 responses
        51 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        31 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        165 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        100 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        160 views
        2 likes
        Last Post CaptainJack  
        Working...
        X