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

How to know close price of specific instrument?

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

    How to know close price of specific instrument?

    How to know close price of specific instrument from one strategy? I mean...
    I know only names of instruments. How to get close price only from one strategy?

    I need close price of 3 diff instrument only from one strategy
    Last edited by Yevhenii; 12-21-2016, 07:54 AM.

    #2
    Hello Yevhenii,

    Thank you for your note.

    From your inquiry, you may be trying to add additional data series to a NinjaScript strategy for referencing multiple instruments.

    You can do this in NinjaTrader 7 with the Add() method.
    Add(string instrumentName, PeriodType periodType, int period)
    http://ninjatrader.com/support/helpGuides/nt7/add3.htm

    For example if I wanted to add a secondary series of the NQ 03-17 with a 5 minute bar type I could add to Initialize():
    protected override void Initialize()
    {
    Add("NQ 03-17", PeriodType.Minute, 5);
    }

    Then in OnBarUpdate I could get the price of this with the Closes (plural) collection by supplying 1 as the BarsInProgress Index and 0 as the bars ago value.
    Closes[int barSeriesIndex][int barsAgo]
    http://ninjatrader.com/support/helpG...nt7/closes.htm

    For example:
    protected override void OnBarUpdate()
    {
    Print(Closes[1][0].ToString());
    }

    Please, let me know if I have misunderstood your inquiry.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you so much. You are right.

      When I have 9 instruments and I do the following:


      protected override void Initialize()
      {
      CalculateOnBarClose = true;

      Add("6A",PeriodType.Minute, 15);
      Add("6B",PeriodType.Minute, 15);
      Add("6C",PeriodType.Minute, 15);
      Add("6E",PeriodType.Minute, 15);
      Add("6J",PeriodType.Minute, 15);
      Add("6S",PeriodType.Minute, 15);
      Add("CL",PeriodType.Minute, 15);
      Add("ES",PeriodType.Minute, 15);
      Add("GC",PeriodType.Minute, 15);
      }

      How to get number of bar in "OnBarUpdate()" by needed instrument?

      I have next logic... I check open position in the "OnBarUpdate()" and if instrument of open position == equal any instrument of bars I use closes price of needed bar. but I don't know how to look through (check all instrument from bars)

      it can be smth like

      onBarUpdate() {
      foreach( InstrumentFromBar in ALLINSTRUMENTINBAR)
      if(myInstrument == InstrumentFromBar)
      ...
      Last edited by Yevhenii; 12-21-2016, 08:34 AM.

      Comment


        #4
        Hello Yevhenii,

        You must use the full instrument name which includes the expiry.
        Add("6A 03-17", PeriodType.Minute, 15);

        Each series is found by the BarsInProgress index.

        For example, if you wanted the close of the 6J 03-17 15 minute you would use the 5th BarsInProgress index.

        Print(Closes[5][0].ToString());

        This would print the close of the 6J 03-17 as the 6J 03-17 was the 5th added series. (The primary series is BarsInProgress 0).
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks. But I have another problem...
          After choosing my strategy
          (
          with code where with ...Add("6A 03-17", PeriodType.Minute, 15)...
          )
          , when I want to add new strategy there are no changes on window form "New strategy". It happen when I add more than
          8 rows
          like this
          protected override void Initialize()
          {
          CalculateOnBarClose = true;

          Add("6A 03-17",PeriodType.Minute, 15);
          Add("6B 03-17",PeriodType.Minute, 15);
          Add("6C 03-17",PeriodType.Minute, 15);
          Add("6E 03-17",PeriodType.Minute, 15);
          Add("6J 03-17",PeriodType.Minute, 15);
          Add("6S 03-17",PeriodType.Minute, 15);
          Add("CL 03-17",PeriodType.Minute, 15);
          Add("ES 03-17",PeriodType.Minute, 15);
          Add("GC 03-17",PeriodType.Minute, 15);
          Add("ZW 03-17",PeriodType.Minute, 15);
          }

          Comment


            #6
            Hello Yevhenii,

            Not all instruments are the same. You are attempting to load invalid contracts months.

            The CL does not have an 03-17 contract month. You will need to check each instrument and ensure that this is the proper front month.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thank you so much)

              Comment


                #8
                How to get close, high, volume of previous day?

                for example
                I need to get VOLUME of previous day. How to check it?

                Comment


                  #9
                  Hello Yevhenii,

                  Add a secondary series of 1 day and call the Volumes[1][0] for that previous day.

                  http://ninjatrader.com/support/helpGuides/nt7/add3.htm

                  http://ninjatrader.com/support/helpG...t7/volumes.htm
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ezrollin, Today, 08:51 PM
                  1 response
                  19 views
                  0 likes
                  Last Post bltdavid  
                  Started by Rubix, Today, 09:31 PM
                  0 responses
                  14 views
                  0 likes
                  Last Post Rubix
                  by Rubix
                   
                  Started by ark321, Today, 05:12 PM
                  1 response
                  21 views
                  0 likes
                  Last Post NinjaTrader_EricB  
                  Started by futurenow, Today, 09:08 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post futurenow  
                  Started by fafafdenis, Today, 04:56 PM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_EricB  
                  Working...
                  X