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 CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    376 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    243 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    208 views
    1 like
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    294 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    255 views
    0 likes
    Last Post CarlTrading  
    Working...
    X