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

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 ursavent, Today, 12:54 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by cre8able, Today, 01:01 PM
    0 responses
    4 views
    0 likes
    Last Post cre8able  
    Started by manitshah915, Today, 12:59 PM
    0 responses
    3 views
    0 likes
    Last Post manitshah915  
    Started by Mizzouman1, Today, 07:35 AM
    3 responses
    17 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by RubenCazorla, Today, 09:07 AM
    2 responses
    13 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X