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

MarketDataEventArgs Price vs Bid vs Ask

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

    MarketDataEventArgs Price vs Bid vs Ask

    Hi there,

    I'm trying to get my head around MarketData updates. In particular I'm trying to use the data to work out the correct spread.



    The docs at the above link indicate that when x.MarketDataType is (Ask | Bid | Last) that x.Price represents that particular price. However on the MarketDataEventArgs object the x.Ask and x.Bid properties often do not always equate to x.Price.

    I wrote the attached indicator to print out MarketData updates where x.MarketData type is (Ask | Bid) and where x.Price does not equal the relevant x.Ask x.Bid property.

    I've also printed out the value of GetCurrentBid() and GetCurrentAsk().

    The output of this indicator shows that there are many market updates where x.Price is not equal to the corresponding x.Ask/x.Bid property in the EventArgs. Furthermore there are some updates where GetCurrentBid/GetCurrentAsk also does not equal the expected value from x.Price.

    I've attached an output from my indicator with highlighting.

    The reason I've undertook this analysis is because on certain CFD instruments with Forex.com such as Index CFDs (SP500/UK100) Forex.com provide guaranteed fixed spreads - their own platform shows the spread fixed as expected. If I use GetCurrentAsk() - GetCurrentBid() in an indicator, it always gives me the correct spread; and on these CFD instruments its always fixed, as expected. However using MarketDataEvents I cannot establish the correct way to calculate the spread, my calculated spread jumps around all over the place, I've tried various ways to calculate this, but I can't get the correct fixed spread.

    I've done my analysis on Crude oil futures to ensure this isn't something peculiar to Forex.com / CFDs.

    I'd be very grateful if someone could help me to understand how to interpret these market data updates in order to obtain the correct values for bid and ask to calculate the spread.

    Thanks,

    Kevin.





    Click image for larger version

Name:	image_2022-01-24_161600.png
Views:	232
Size:	154.8 KB
ID:	1186832






    #2
    Hello kevinenergy,

    Thank you for your post.

    GetCurrentAsk() and GetCurrentBid() can peek ahead to whatever the last updated price was for the instrument. Due to the multi-threaded nature of NinjaTrader 8 there is the possibility for the GetCurrentAsk() or GetCurrentBid() to see ahead of the instrument thread that updates MarketDataType events such as MarketDataType.Ask.

    marketDataUpdate.Price would be the current bid/ask/last price within OnMarketData. (e.MarketDataType == MarketDataType.Ask) and (e.MarketDataType == MarketDataType.Bid) are updates to resting limit orders in the level 1 book.

    GetCurrentAsk() and GetCurrentBid() are intended to be used in OnBarUpdate() to pull a snapshot of the data at that time from the core process.

    OnMarketData() is the raw Level 1 event. Do not use GetCurrentAsk() or GetCurrentBid() within OnMarketData().

    If you need the snapshot of the current bid or ask use GetCurrentBid() or GetCurrentAsk() inside of OnBarUpdate().

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

    Comment


      #3
      HI Kate, thanks for the response. I'm actually trying to do this from the MarketData class in an Addon:


      It was just easier to use the OnMarketData event in an Indicator to provide an example.

      Unfortunately, because I'm using an Addon I don't actually have access to GetCurrentAsk or GetCurrentBid, just the MarketDataEventArgs from the MarketData class.

      I did notice that GetCurrentBid and GetCurrentAsk always give me the correct values and give me the right spread, but I just can't work out how to get the same result from the MarketDataEvent.

      Comment


        #4
        Hello kevinenergy,

        Thank you for your post.

        This post from the forum goes into some options you can try:
        I'm unable to resolve a compilation error on the SubmitBuyLimitOrderWithAtmAddonNoTabsExample Addon and as follows; Order buyLimitOrder = accountSelector.SelectedAccount.CreateOrder(atmStrategySelector.Instrument, OrderAction.Buy, OrderType.Limit, TimeInForce.Gtc, 3, <GetCurrentAsk>, 0, string.Empty, "Entry",


        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 bmartz, 03-12-2024, 06:12 AM
        4 responses
        31 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by Aviram Y, Today, 05:29 AM
        4 responses
        12 views
        0 likes
        Last Post Aviram Y  
        Started by algospoke, 04-17-2024, 06:40 PM
        3 responses
        28 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X