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

historical bid ask data

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

    historical bid ask data

    I created an indicator that requires bid ask data. How do I ask it when loading up a chart? It works live but not on initial loading

    #2
    Hello ballboy11,

    Thank you for your post.

    Is this indicator using GetCurrentBid() and/or GetCurrentAsk()? It would be expected for these to only function on real time data. For the indicator to function on historical data, Tick Replay would need to be used:



    Here's the example of how to access historical bid/ask prices using Tick Replay from the above link:

    Code:
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {
      // TickReplay events only occur on the "Last" market data type
      if (marketDataUpdate.MarketDataType == MarketDataType.Last)
      {
        if (marketDataUpdate.Price >= marketDataUpdate.Ask)
        {
            Print(marketDataUpdate.Volume + " contracts traded at asking price " + marketDataUpdate.Ask);
        }
    
        else if (marketDataUpdate.Price <= marketDataUpdate.Bid)
        {
            Print(marketDataUpdate.Volume + " Contracts Traded at bidding price " + marketDataUpdate.Bid);
        }
      }
    }
    Basically you'd want to separate your logic out so that on real time, it uses GetCurrentBid and GetCurrentAsk but on Historical data it uses the above approach. Tick replay would need to be turned on on the chart the indicator is applied to for the historical portion to function.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Kate if you want to take the above script, which i have try without success and calculate the spread where would i place the following into that script

      Spread[0] = (marketDataUpdate.Ask - marketDataUpdate.Bid);

      or do i not actually need all of that script, thanks

      Comment


        #4
        Hello DTSSTS,

        Thank you for your reply.

        You'd want to assign a non- Series<T> double variable the spread you calculate in OnMarketData. You can then use that variable in OnBarUpdate to assign the value to your Series<T> variable.

        I've attached a simple example script that shows how you could accomplish this. It requires Tick Replay to be turned on for it to function correctly.

        Please let us know if we may be of further assistance to you.
        Attached Files
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thanks much

          Comment


            #6
            Tick replay is resource intensive, and I could not be sure clients would enable as well so best not to use anything like that in strategies, Thanks for help.

            Comment


              #7
              Kate with you help I have an indicator that plots oneachtick the spread. If the chart remains open the plot continues through out the session. Of course if instruments are changed on the chart the plot starts with zero historical and creates a new plot for the new instrument. Point is the chart instrument has to remain live for the indicator to show any history

              Question is. If I create a condition in my Strategy using the indicator, (understand will not work on backtesting) After applying strategy to a chart the Spread Tracker would of course work same as it does as an indicator on a chart.

              IF I PLACE MY STRATEGY ON A INSTRUMENT LIST IN THE CONTROL CENTER (no charts) WILL THAT STILL TRACK THE SPREAD for all instruments the strategy is applied to

              Thanks, Hap

              Comment


                #8
                Hello DTSSTS,

                Thank you for your reply.

                If the strategy calls the spread indicator, yes, that would still calculate when the strategy is applied to the Strategies tab in the Control Center.

                Please let us know if we may be of further assistance to you.
                Kate W.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by frslvr, 04-11-2024, 07:26 AM
                9 responses
                123 views
                1 like
                Last Post caryc123  
                Started by rocketman7, Today, 09:41 AM
                4 responses
                16 views
                0 likes
                Last Post rocketman7  
                Started by selu72, Today, 02:01 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by WHICKED, Today, 02:02 PM
                2 responses
                18 views
                0 likes
                Last Post WHICKED
                by WHICKED
                 
                Started by f.saeidi, Today, 12:14 PM
                8 responses
                21 views
                0 likes
                Last Post f.saeidi  
                Working...
                X