Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData() not working

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

    OnMarketData() not working

    I've inserted the the OnMarketData() example given in the help file into an otherwise blank strategy.

    It is not being called on either live or Sim101 accounts.

    What am I missing?

    #2
    It does work on a live feed. It will not be called on historical data such as a backtest in the Strategy Analyzer.

    The following code inserted into a strategy will output data to the Output window.

    Code:
    [FONT=Courier New][COLOR=#0000ff]protected override[/COLOR] [COLOR=#0000ff]void[/COLOR] OnMarketData(MarketDataEventArgs e)[/FONT] 
    [FONT=Courier New]{[/FONT] 
    [FONT=Courier New]    [COLOR=#008000]// Print some data to the Output window[/COLOR][/FONT] 
    [FONT=Courier New]    [COLOR=#0000ff]if[/COLOR] (e.MarketDataType == MarketDataType.Last)[/FONT] 
    [FONT=Courier New]        Print("Last = " + e.Price + " " + e.Volume);[/FONT] 
    [FONT=Courier New]    [COLOR=#0000ff]else if[/COLOR] (e.MarketDataType == MarketDataType.Ask)[/FONT] 
    [FONT=Courier New]        Print("Ask = " + e.Price + " " + e.Volume);[/FONT] 
    [FONT=Courier New]    [COLOR=#0000ff]else if[/COLOR] (e.MarketDataType == MarketDataType.Bid)[/FONT] 
    [FONT=Courier New]        Print("Bid = " + e.Price + " " + e.Volume);[/FONT] 
    [FONT=Courier New]}[/FONT]
    [FONT=Courier New][/FONT]
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      It will not be called on historical data such as a backtest in the Strategy Analyzer.
      I'm sure you've already given this some thought, but I'd sure like to see a way that the OnMarketData could be simulated from the Strategy Analyzer, for backtesting and optimization.

      Otherwise one has to spend money to test live. (Ouch.)

      Or will this work with the Market Replay connections?

      Comment


        #4
        It will work with Market Replay and also the Simulated Data Feed.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Not sure what changed, but it is working now

          Thanks Ray.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          656 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          371 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          579 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X