Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
      Paul H.NinjaTrader Customer Service

      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 lorem, Yesterday, 09:18 AM
        4 responses
        13 views
        0 likes
        Last Post lorem
        by lorem
         
        Started by Spiderbird, Today, 12:15 PM
        0 responses
        5 views
        0 likes
        Last Post Spiderbird  
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        12 responses
        42 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by FrazMann, Today, 11:21 AM
        0 responses
        6 views
        0 likes
        Last Post FrazMann  
        Started by geddyisodin, Yesterday, 05:20 AM
        8 responses
        52 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X