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