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 llanqui, Today, 03:53 AM
        0 responses
        6 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        10 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        15 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        14 views
        0 likes
        Last Post strategist007  
        Working...
        X