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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    571 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    330 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    549 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    549 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X