Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Use of OnMarketData (MarketDataEventArgs e) in a custom strategy

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

    Use of OnMarketData (MarketDataEventArgs e) in a custom strategy

    Hi Ninja experts, I need help with two short questions about OnMarketData()

    # 1: I need to access the price (or the close price) of each tick in the OnMarketData() event. I want to confirm whether these two codes generate the same price data or not:
    protected override void OnMarketData (MarketDataEventArgs e)
    {
    if (e. MarketDataType == MarketDataType.Last)
    Print ("Last = " + e. Price);
    }

    protected override void OnBarUpdate () // It is a 1-Tick data series
    {
    Print ("Last = " + Close[0]);
    }

    # 2: Is it technically correct and supported to access PriceSeries<double> (Close, High, Low, Open) and the BarsInProgress values in the OnMarketData ()? If yes, do we have any example code?

    Many thanks for your support

    #2
    Hello Mubeen Haider,

    If you are using a 1 tick series for the strategy then the Close[0] would represent each tick as OnBarUpdate is called for each tick.

    You can use regular NinjaScript properties inside OnMarketData, you can use the BarsInProgress or the Instrument to determine which series is calling OnMarketData.

    You can find this note about using multi timeframes or instruments with OnMarketData in the OnMarketData help guide page:

    4.With multi-time frame and instrument strategies, a subscription will be created on all bars series added in your indicator or strategy strategy (even if the instrument is the same). The market data subscription behavior occurs both in real-time and during TickReplay historical

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    84 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    143 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    83 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    256 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    334 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X