Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access to historical price in multi instrumets strategy

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

    Access to historical price in multi instrumets strategy

    Hello.
    Do we have an access to historical prices in to BarsInProgress == 1 instrument??
    I would like to GetCurrentBid(); few minutes ago prezent time and I can't get it.
    The same code works in BarsInProgress == 0
    Rgds
    Czarek

    #2
    Hi Czarek, you sure can access historical prices. Closes[] is an array that holds all close prices, and there are similar arrays for Highs and Lows and everything else. Please see this help guide entry for Closes to get an idea for how it works.

    Keep in mind that GetCurrentBid() is a real-time only function. If you call GetCurrentBid for historical data, it will just return the close price for that bar.
    AustinNinjaTrader Customer Service

    Comment


      #3
      I use the wrong word. I do not mean historical data on the back test.
      I mean the price in the past durring the open session.
      For exaple now is 150000 but i want to get the price 145000 on BarsInProgress == 1 instrument.
      Code:
      if (BarsInProgress == 0)
      {
      if (ToTime(Time[0]) <= 145900 && (ToDay(Time[0]) >= 20090807)
      {
      formerBidNQ = GetCurrentBid();
      formerAskNQ = GetCurrentAsk();
      }
      Does not work, but in BarsInProgress == 0 works
      Where the problem could be???
      Czarek

      Comment


        #4
        Does the code not execute? Is there an error? The code you posted doesn't have anything to do with getting the price at 145000.. I'm not sure I understand what your question is.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Sorry, anotherm my mistake.
          Code is:
          Code:
          if (BarsInProgress == 1)
          {
          if (ToTime(Time[0]) <= 145000 && (ToDay(Time[0]) >= 20090807)
          {
          formerBidNQ = GetCurrentBid();
          formerAskNQ = GetCurrentAsk();
          }
          Variable formerBidNQ and formerAskNQ = 0; and shows 0 in output window.
          The same code, but BarsInProgress == 0 works at the same time.
          Czarek

          Comment


            #6
            Sorry for not responding with this earlier, but there is an overload for GetCurrentBid/Ask() that includes the BarsInProgress index:
            Code:
            GetCurrentAsk(int barSeriesIndex)
            So for your situation, maybe this will work:
            Code:
            formerBidNQ = GetCurrentBid(1);	
            formerAskNQ = GetCurrentAsk(1);
            AustinNinjaTrader Customer Service

            Comment


              #7
              Hi.
              Unfortunately GetCurrentBid(1); does not work too. I changed all strategy code under BarsInProgress == 1 with BarsInProgress == 0 and BarsInProgress == 0 works , BarsInProgress == 1 does not.
              Czarek.

              Comment


                #8
                Czarek, I can't reproduce this on my end. I just whipped up a quick test and everything performs as expected. This is the code I ran:
                Code:
                protected override void Initialize()
                {
                    Add("YM 09-09", PeriodType.Minute, 10);
                    CalculateOnBarClose = true;
                }
                protected override void OnBarUpdate()
                {
                    if (BarsInProgress == 1)
                    {
                        double bid = GetCurrentBid();
                        double bid1 = GetCurrentBid(1);
                        Print("bid:\t" + bid);
                        Print("bid1:\t" + bid1);
                    }
                }
                The output was closing prices, just like it should be:
                Code:
                bid:    9215
                bid1:    9215
                bid:    9218
                bid1:    9218
                bid:    9221
                bid1:    9221
                bid:    9223
                bid1:    9223
                bid:    9225
                ...
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Austin.
                  Your code works but this is access for current prices I mean in present. I would like to get the price from past. E.g. if now is 140000 i would like to get bid price from 135500. And this is my problem.
                  Rgds
                  Czarek

                  Comment


                    #10
                    Czarek,

                    Unfortunately there is no stored historical bid/ask. If you wanted these you would have to store them in your own collection somewhere.
                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    574 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    332 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    553 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    551 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X