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 alifarahani, Today, 09:40 AM
    6 responses
    36 views
    0 likes
    Last Post alifarahani  
    Started by Waxavi, Today, 02:10 AM
    1 response
    17 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by Kaledus, Today, 01:29 PM
    5 responses
    14 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Waxavi, Today, 02:00 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by gentlebenthebear, Today, 01:30 AM
    3 responses
    17 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X