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

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
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,606 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    8 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    4 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    13 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X