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 get Ask/Bid for historical bars

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

    How to get Ask/Bid for historical bars

    In forex, there are really two bar series, one is the bars of the Ask prices, and one is the bars of the Bids.

    So if I wanted to get the High[x] of the Asks for a historical bar, how do I get that? I assume I have to first test if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Currency). Would I just use GetCurrentAsk(x), or does that look at the Bids bar series (the default series on the chart)?

    Thanks!
    Bryan
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    #2
    Hello Bryan,
    You have to Add an additional bar series to refer to the ask bar series.

    Please use the below overload to Add an additional bas array and please make sure to assign the MarketDataType as Ask.

    Add(string instrumentName, PeriodType periodType, int period, MarketDataType marketDataType)


    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Joydeep View Post
      Hello Bryan,
      You have to Add an additional bar series to refer to the ask bar series.

      Please use the below overload to Add an additional bas array and please make sure to assign the MarketDataType as Ask.




      http://www.ninjatrader.com/support/h...nstruments.htm
      Ah, ok I have added Bar series before, so I know how, thanks! Tell me then, for futures instruments (and all others), is the main bar series on every chart always the Bid price then? It doesn't matter on futures because bid/ask is so close and there are commissions, but it does matter on Forex.

      Thanks!
      cassb
      NinjaTrader Ecosystem Vendor - Logical Forex

      Comment


        #4
        Hello Bryan,
        Only forex references the bid price as the last traded price. For futures/stocks the last traded price is a separate bar series.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Joydeep View Post
          Hello Bryan,
          Only forex references the bid price as the last traded price. For futures/stocks the last traded price is a separate bar series.
          Oh, OK got it. So I only need this secondary data series for InstrumentType = Currency. Now one more thing... when adding the new dataseries in the Initialize tag, I am trying to add one using the same instrument as the primary series. But for currencies, when I use Instrument.MasterInstrument.Name.ToString(), it returns "EURUSD" which is an invalid instrument name. The name should be "$EURUSD". Is there a different method to get the proper instrument name?

          Thanks!
          cassb
          NinjaTrader Ecosystem Vendor - Logical Forex

          Comment


            #6
            Hello Bryan,
            If you use the below code then can you get the proper name

            Code:
            Instrument.FullName
            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Hi Joydeep. Can you help me explain something? I am adding the second Bars series to my indicator using the Add() method you recommend. However, the indicator script never run the OnBarUpdate() code for BarsInProgress = 1. Why not? I have attached an example indicator that shows the issue. Put this indicator on a chart with a currency instrument -- I used $EURUSD. And here is the output I get with it:

              0: BarsInProgress = 0
              Highs[0][0] = 1.23485, Highs[1][0] = 0
              1: BarsInProgress = 0
              Highs[0][0] = 1.23392, Highs[1][0] = 0
              2: BarsInProgress = 0
              Highs[0][0] = 1.23392, Highs[1][0] = 0
              3: BarsInProgress = 0
              Highs[0][0] = 1.23387, Highs[1][0] = 0
              4: BarsInProgress = 0
              Highs[0][0] = 1.23381, Highs[1][0] = 0
              5: BarsInProgress = 0
              Highs[0][0] = 1.23374, Highs[1][0] = 0
              6: BarsInProgress = 0
              Highs[0][0] = 1.2338, Highs[1][0] = 0
              7: BarsInProgress = 0
              Highs[0][0] = 1.23386, Highs[1][0] = 0
              8: BarsInProgress = 0
              Highs[0][0] = 1.2337, Highs[1][0] = 0
              9: BarsInProgress = 0
              Highs[0][0] = 1.23392, Highs[1][0] = 0
              10: BarsInProgress = 0
              Highs[0][0] = 1.23394, Highs[1][0] = 0
              It never sets BarsInProgress = 1, and therefore the Highs[1][0] value is always 0. I assume it should have actual values in it from the bars in that data series.

              Thanks!
              cassb
              NinjaTrader Ecosystem Vendor - Logical Forex

              Comment


                #8
                Hello Bryan,
                To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

                Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

                I look forward to assisting you further.

                *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Yes, I am sorry -- I forgot to attach the indicator last night.

                  I attached it to this post... let me know what you think.

                  Thanks!
                  Attached Files
                  cassb
                  NinjaTrader Ecosystem Vendor - Logical Forex

                  Comment


                    #10
                    Hello Bryan,
                    Thanks for the code.

                    To assist you further may I know
                    • Who your connectivity provider is?
                    • On what chart (timeframe) you are putting the indicator on?


                    I look forward to assisting you further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Joydeep View Post
                      Hello Bryan,
                      Thanks for the code.

                      To assist you further may I know
                      • Who your connectivity provider is?
                      • On what chart (timeframe) you are putting the indicator on?


                      I look forward to assisting you further.
                      I am using the FXCM connection. This is on a $GBPUSD 5 min. bar chart.
                      cassb
                      NinjaTrader Ecosystem Vendor - Logical Forex

                      Comment


                        #12
                        Hello Bryan,
                        Thanks for the information.

                        I am able to get the data using FXCM.

                        Please make sure you have enough bars before you request the quotes

                        Code:
                        if (CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
                        Print(CurrentBar + ": BarsInProgress = " + BarsInProgress);
                        Print("Highs[0][0] = " + Highs[0][0] + ", Highs[1][0] = " + Highs[1][0]);


                        1773: BarsInProgress = 0
                        Highs[0][0] = 1.6237, Highs[1][0] = 1.6239
                        1773: BarsInProgress = 0
                        Highs[0][0] = 1.6237, Highs[1][0] = 1.6239
                        1593: BarsInProgress = 1
                        Highs[0][0] = 1.6237, Highs[1][0] = 1.6239
                        1773: BarsInProgress = 0
                        Highs[0][0] = 1.6237, Highs[1][0] = 1.6239

                        Please let me know if I can assist you any further.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #13
                          OK thanks. There must be a bug in the NT core code then, because last night, you can see that BarsInProgress was never set to 1. However, today that data series is working fine.

                          For some reason last night, the second data series never activated... I have had trouble with this beta FXCM connection for the past few weeks. It probably has something to do with that connection. You might want to investigate the FXCM connection code?
                          cassb
                          NinjaTrader Ecosystem Vendor - Logical Forex

                          Comment


                            #14
                            Hello Bryan,
                            Thanks for your note.

                            Glad to know you are getting the correct prints.

                            Everything is working fine at my end. If you can replicate the scenario then please let us a step by step reproducible scenario and we will be happy to further investigate it.
                            JoydeepNinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Joydeep View Post
                              Hello Bryan,
                              Thanks for your note.

                              Glad to know you are getting the correct prints.

                              Everything is working fine at my end. If you can replicate the scenario then please let us a step by step reproducible scenario and we will be happy to further investigate it.
                              Sorry, but I think you'll have to go back in time to do that. That is frustrating, because it clearly did not work the same last night as the same code is working this morning. I don't know what to tell you other than I don't think anything is different on my end except for the time of day.
                              cassb
                              NinjaTrader Ecosystem Vendor - Logical Forex

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Jonker, Today, 01:19 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post Jonker
                              by Jonker
                               
                              Started by futtrader, Today, 01:16 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post futtrader  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              14 responses
                              1,791 views
                              0 likes
                              Last Post aligator  
                              Started by Jimmyk, 01-26-2018, 05:19 AM
                              6 responses
                              839 views
                              0 likes
                              Last Post emuns
                              by emuns
                               
                              Started by jxs_xrj, 01-12-2020, 09:49 AM
                              6 responses
                              3,294 views
                              1 like
                              Last Post jgualdronc  
                              Working...
                              X