Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

get current price of instruments

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

    get current price of instruments

    Hi there,

    I have a strategy I am developing and there are times I need to calculate the current (or last close) price of an instrument of which my strategy is not running on. Is there any way to get the current price of a stock without Add(instrument) to the BarsArray?

    If I have to add instruments to BarsArray (and if theres no way to remove it later?) is there a way to determine which instrument is in which index?

    For example, throughout my strategy a series of events such as:

    do something...
    Add("GOOG", PeriodType.Minute, 1);
    do something...
    Add("AAPL", PeriodType.Minute, 1);
    do something...
    Add("NFLX", PeriodType.Minute, 1);
    do something...

    but on my fourth iteration lets say I need to use AAPL again, is there a way i can determine through code that AAPL was added already in Bars[2]?

    Bars[2].toString() perhaps?


    Thanks!

    #2
    Are those Add's in OnBarUpdate?

    Why wouldn't you add that in :

    Code:
    protected override void Initialize()




    Originally posted by slocumtrader View Post
    Hi there,

    I have a strategy I am developing and there are times I need to calculate the current (or last close) price of an instrument of which my strategy is not running on. Is there any way to get the current price of a stock without Add(instrument) to the BarsArray?

    If I have to add instruments to BarsArray (and if theres no way to remove it later?) is there a way to determine which instrument is in which index?

    For example, throughout my strategy a series of events such as:

    do something...
    Add("GOOG", PeriodType.Minute, 1);
    do something...
    Add("AAPL", PeriodType.Minute, 1);
    do something...
    Add("NFLX", PeriodType.Minute, 1);
    do something...

    but on my fourth iteration lets say I need to use AAPL again, is there a way i can determine through code that AAPL was added already in Bars[2]?

    Bars[2].toString() perhaps?


    Thanks!

    Comment


      #3
      slocumtrader, to access other instrument data you would first need to Add() those in your script Initialize() method, here they also would get a permanent index assigned so you would know exact which BarsInProgress / OnBarUpdate() call comes from which instrument.

      Your primary series will always be at BarsInProgress / BarsArray 0, and then the others are added in the sequence you have them in Initialize(). So following your example -

      Add("GOOG", PeriodType.Minute, 1); // at Bar index 1
      Add("AAPL", PeriodType.Minute, 1); // at Bar index 2
      Add("NFLX", PeriodType.Minute, 1); // at Bar index 3

      The full framework is documented and explained with examples here - http://www.ninjatrader.com/support/h...nstruments.htm

      A good starting point in MultiSeries would also be our SampleMultiInstrument and SampelMultiTimeFrame scripts preinstalled with each NinjaTrader setup.

      Comment


        #4
        Hi Bertrand,
        We meet again! Thanks for your response.

        The distinction I need to make in my strategy is that I do not know ahead of time (at strategy initialize) which instruments I will need. I could theoretically add a bunch but seems I would eat up alot of resources memory wise that way.

        Is there no way I can add instruments dynamically throughout the strategy? Outside of Initialize method?

        Thanks!

        Comment


          #5
          Surething - dynamic adding is unfortunately something we could not support, you could have a look into the Pivots indicator and how it would async load bars data in the misc section for it's use however I would not docs or support for this approach.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          662 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          376 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X