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 Hwop38, 05-04-2026, 07:02 PM
        0 responses
        152 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        305 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        244 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        345 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        176 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Working...
        X