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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        142 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        81 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        125 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        119 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        98 views
        0 likes
        Last Post CarlTrading  
        Working...
        X