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 GussJ, 03-04-2020, 03:11 PM
    11 responses
    3,229 views
    0 likes
    Last Post xiinteractive  
    Started by andrewtrades, Today, 04:57 PM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    7 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    441 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    12 views
    0 likes
    Last Post FAQtrader  
    Working...
    X