Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

General program for multi instrument

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

    General program for multi instrument

    Hi

    Initialize:
    Add(FirstInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value);
    Add(SecondInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value);
    OBU:

    a= GetCurrentBid(1);// bid of second instrument
    B= GetCurrentBid(0);// bid of first instrument

    OR

    a= GetCurrentBid(1);// bid of first instrument
    B= GetCurrentBid(2);// bid of second instrument

    Hi which one is the correct way to access the data series under initialize?

    #2
    My vote:

    Initialize:
    Add(FirstInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value);
    Add(SecondInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value);
    namespace
    {
    class
    {
    private const int idxPrimary = 0;
    private const int idxFirstInstrument = 1;
    private const int idxSecondInstrument = 2;

    Initialize()
    {
    Add(FirstInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value); // idxFirstInstrument
    Add(SecondInstrument, BarsPeriods[0].Id, BarsPeriods[0].Value); // idxSecondInstrument
    }

    OnBarUpdate()
    {
    a= GetCurrentBid(idxSecondInstrument);
    B= GetCurrentBid(idxFirstInstrument);
    }
    }
    }

    Comment


      #3
      Hello calhawk01,

      Thanks for your post.

      Using BarsPeriods or BarsPeriod in the initialize section is not supported. You can hard code the ID and type or use an input.

      However if you are stuck with using BarsPeriod, you would want to use BarsPeriod (as opposed to BarsPeriods) to accomplish your goals.

      In the OBU section:

      a= GetCurrentBid(1);// bid of first instrument added
      b= GetCurrentBid(2);// bid of second instrument added.

      Comment


        #4
        Hello calhawk01,

        Try:

        protected override void Initialize()
        {
        // the primary series will be BarsInProgress 0
        // this will be BarsInProgress 1
        Add(FirstInstrument, BarsPeriod.Id, BarsPeriod.Value);
        // this will be BarsInProgress 2
        Add(SecondInstrument, BarsPeriod.Id, BarsPeriod.Value);
        }

        protected override void OnBarUpdate()
        {
        if (BarsInProgress == 0)
        {
        Print(GetCurrentAsk(1));
        Print(GetCurrentAsk(2)):
        }
        }
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

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