Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData and GetCurrentBid()

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

    OnMarketData and GetCurrentBid()

    I have a strategy that has CalculateOnBarClose set to true. However, I need to do a few checks on every bid or ask change. So, I'm using OnMarketData to look for those changes.

    If I check to see if there has been an update by using OnMarketData, will GetCurrentBid() be updated to the latest bid? Or would I need to update my own bid price? Something like:

    Code:
    if (e.MarketDataType == MarketDataType.Bid)
                    bid = e.Price;
    Basically, I'm not clear on whether GetCurrentBid/Ask is updated on each incoming data, or if it takes place on each bar (if using CalculateOnBarClose true).

    Thanks
    Last edited by lookOutBelow; 08-14-2015, 12:07 PM.

    #2
    Hello lookOutBelow,

    Thank you for your inquiry.

    A great way to test out if the values of both e.Price in OnMarketData() and GetCurrentBid() are similar is to print both the values of GetCurrentBid() and e.Price. Here's an example:
    Code:
    protected override void OnBarUpdate()
    {
         Print("OnBarUpdate: " + GetCurrentBid());
    }
    
    protected override void OnMarketData(MarketDataEventArgs e)
    {
         if (e.MarketDataType = MarketDataType.Bid)
              Print("OnMarketData: " + e.Price);
    }
    As long as CalculateOnBarClose is set to false, you will see that both values are the same. Please note that when GetCurrentBid() is ran on a historical bar, the close price of the evaluated bar will be substituted: http://ninjatrader.com/support/helpG...currentbid.htm

    Therefore, either using the value that is returned by the GetCurrentBid() method call or the value in OnMarketData() are both valid as long as CalculateOnBarClose is false.

    OnMarketData() will still be called on every change of level one market data and is not affected by CalculateOnBarClose being true or false. If you would like to get up-to-date data with CalculateOnBarClose being true, obtaining the value from OnMarketData() would be the choice.

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    152 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    87 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    131 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    127 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    106 views
    0 likes
    Last Post CarlTrading  
    Working...
    X