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

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 wzgy0920, 02-22-2024, 01:11 AM
                    5 responses
                    32 views
                    0 likes
                    Last Post wzgy0920  
                    Started by wzgy0920, Yesterday, 09:53 PM
                    2 responses
                    49 views
                    0 likes
                    Last Post wzgy0920  
                    Started by Kensonprib, 04-28-2021, 10:11 AM
                    5 responses
                    191 views
                    0 likes
                    Last Post Hasadafa  
                    Started by GussJ, 03-04-2020, 03:11 PM
                    11 responses
                    3,230 views
                    0 likes
                    Last Post xiinteractive  
                    Started by andrewtrades, Today, 04:57 PM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X