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

GetCurrentBid, GetCurrentAsk

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

    GetCurrentBid, GetCurrentAsk

    Hello,

    The documentation says: "When accessed during a historical backtest, the close price of the evaluated bar is substituted"

    1) can you clarify....is this only for Back Testing, or is this also the case when the indicator is processing Historical (i.e. not Real Time) data as a chart is being loaded?

    2) Is there any other way, say by a direct data reference, to get the current Bid / Ask without calling a Method ()?

    3) What is the overhead of using these methods if CalculateOnBarClose = false; (i.e. for each tick in OnBarUpdate?)

    Thanks

    #2
    Hello llanqui,

    All historical processing is called a backtest so that would be in any historical mode.

    To access ask/bid data historically you can add secondary ask/bid series as long as your data provider offers historical ask/bid data for the bar type you are using. https://ninjatrader.com/support/help...ghtsub=adddata

    There would not be any additional overhead using the Get methods, they return either a value from the close series or the ask/bid price in realtime.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Unfortunately, it seems, I could be wrong (I hope), that to add a new series for Bid or Ask I have to hard code the instrument name in the ninjascript. both for NT7 and NT8.

      since I trade multiple instruments then I have to have a different indicator for each instrument

      Is that so?

      here is the proto ninjascript

      AddDataSeries(string instrumentName, BarsPeriodType periodType, int period, MarketDataType marketDataType)

      I was told in another question that the InstrumentName needs to be hardcoded and cannot be a variable.....


      So... ????

      Is there a way to do what I need, it can be in NT8...

      if not then...

      Can you please ask the development team to consider this...for NT8

      AddDataSeries(BarsPeriodType periodType, int period, MarketDataType marketDataType)

      and take the Instrument Name from the primary series?


      Comment?

      Comment


        #4
        Hello llanqui,

        If you are manually coding the script you can use null as the instrument which results in the primary instrument being used:

        AddDataSeries(null, Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Ask);
        ​​​​​​​
        JesseNinjaTrader Customer Service

        Comment


          #5
          Wonderful!!

          Would that work also in NT7?

          Comment


            #6
            Hello llanqui,

            No that would be for NT8, in NT7 you would need to manually code the instrument names.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Ok, thanks...another reason to port all the code to NT8....wish I could clone myself....one clone Trader, another clone Software Engineer

              Comment


                #8
                A little more digging...

                in the documentation for
                Navigation: NinjaScript > Educational Resources >

                Developing for Tick Replay

                it says.... "GetCurrentAsk() and GetCurrentBid(), which are methods designed to function on real-time data only​"

                Ok, so I can't use these OnBarUpdate methods to get the Ask and Bid for historical data...


                so, how can I get Bid/Ask at the lowest level for historical data when a chart is loading live market data? (i.e. not replay)

                the same as OnMarketData for live data?

                Comment


                  #9
                  and this seems to be conflicting information

                  Help Page: Using Historical Bid/Ask Series

                  •The historical bid/ask series holds all bid/ask events sent out by the exchange. This would not be equivalent to the bid/ask at a specific time a trade went off.

                  •When processing your NinjaScript, the historical bid/ask series would have the historical portion triggered in the OnBarUpdate() method only. OnMarketData() method events for the historical bid/ask series would only be triggered in real-time.

                  Comment


                    #10
                    Hello llanqui,

                    In NT7 that is the Add method, you can add secondary series of ask/bid data to be used historically.
                    https://ninjatrader.com/support/help...ghlightsub=add

                    You can then use either the secondary series OnBarUpdate events or the OnMarketData events to get prices in realtime.

                    Here is the NT8 equivalent as well. https://ninjatrader.com/support/help...ghtsub=adddata
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      I'll use NT8 then because I can set the second data series to Null

                      I can already get the Real Time data for all three Last/Bid/Ask in OnMarketData without adding a second or third series...

                      but hat I need is the Historical Bid/Ask


                      to clarify....in NT8 I can get the Historical Bid/Ask as well as the Historical Last Price / VOLUME in OnMarketData if I add the series?


                      (using the appropriate series...)

                      Comment


                        #12
                        Hello llanqui,

                        To get historical ask/bid data you need to add secondary ask/bid series. OnMarketData can be used with tick replay for historical bars but that is not all of the ask/bid data, that's the ask/bid at the time of the last event. You can get historical ask/bid/last by just using historical data and OnBarUpdate. For realtime you can use OnMarketData to receive all of the ask/bid events as well.



                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Ok, then is this the case?

                          In order to get both historical and real time Bid/Ask I need to have three data series Last, Bid, Ask

                          then OnMarketData is used for Real Time

                          and

                          OnBarUpdate (with the series specified) can give me Historical Last, Bid, Ask?

                          Comment


                            #14
                            Hello llanqui,

                            Yes if you wanted historical data you need to use OnBarUpdate and then any series you wanted historical data for such as last/ask/bid. OnMarketData is not required for realtime you can also use the series you added for realtime prices. You can alternatively use OnmarketData if you don't need historical data and just wanted the live ask/bid data.

                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Ok, can you tell me if this for NT7 will give me Historical TICK LEVEL Bid Ask prices?

                              Do I use Close[] or GetCurrentBid/Ask?

                              ================================================== ================================================== ============

                              region Initialize
                              protected override void Initialize()
                              {
                              CalculateOnBarClose = false; // on bar update needs to process each tick

                              // [0] series is LAST
                              // add BID and ASK series
                              Add("ES 12-22", PeriodType.Minute, 10, MarketDataType.Bid); // [1]
                              Add("ES 12-22", PeriodType.Minute, 10, MarketDataType.Ask); // [2]
                              }
                              #endregion​



                              region OnBarUpdate
                              protected override void OnBarUpdate()
                              {
                              if (Historical)
                              {

                              // BID
                              if (BarsInProgress == 1)
                              {
                              // lastBidPrice = GetCurrentBid[1];
                              lastBidPrice = Close[1];
                              return;
                              }

                              // ASK
                              if (BarsInProgress == 2)
                              {
                              // lastAskPrice = GetCurrentAsk[2];
                              lastAskPrice = Close[2];
                              return;
                              }
                              }​



                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NRITV, Today, 01:15 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post NRITV
                              by NRITV
                               
                              Started by frankthearm, Today, 09:08 AM
                              7 responses
                              31 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by maybeimnotrader, Yesterday, 05:46 PM
                              5 responses
                              26 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by quantismo, Yesterday, 05:13 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post quantismo  
                              Started by adeelshahzad, Today, 03:54 AM
                              5 responses
                              33 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X