Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData not called

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

    OnMarketData not called

    Hello,

    I'm using the latest beta of NT7 with a ZenFire connection.
    I'm trying to build a strategy working with market data, but I can't seem to have NinjaTrader calling my method.

    Could you please tell me what's wrong with this code?

    Please mind that I'm loading this with CalculateOnBarClose set to false and everything else to the default settings.
    My computer is running Windows 7 x64 SP1 and I'm running the 32bit version of NT7.

    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    using System.IO;
    #endregion
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// 
        /// </summary>
        [Description("")]
        public class ProblemExample : Strategy
        {
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose = false;
    			try
    			{
    				Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
    				Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
    				Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
    			}
    			catch(Exception e)
    			{
    				Print(e.Message);
    			}
    			Print("Initialization finished");
            }
    		
    		
    		protected override void OnMarketData(MarketDataEventArgs e)
    		{
    			Print("SUCCESS!");
    		}
    		
    		protected override void OnBarUpdate()
    		{
    		}
        }
    }

    #2
    Welcome to our forums - are you testing on realtime / market replay data or in backtesting with this snippet? OnMarketData() would not work in backtesting unfortunately.

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Welcome to our forums - are you testing on realtime / market replay data or in backtesting with this snippet? OnMarketData() would not work in backtesting unfortunately.
      Thanks for the quick reply!
      I'm testing on a real-time ZenFire feed. I was aware of the limitations of backtesting so I had a demo account at my brokerage firm set up for my testing purposes. Although the strategy will only be paper trading, for now, the feed is live.

      Comment


        #4
        Thanks for the reply - can you try just on one stream first so commenting out the Add() series? Would you see any log tab errors as you apply your script?

        Please also ensure you receive Level 1 data for the instrument in question, quickest check would be directly for the needed expiry in the Control Center while being connected live.

        Thanks,

        Comment


          #5
          Thanks, I've solved the issue which was simply that I didn't know that I had to remove and readd a strategy after recompilation to make use of the freshly compiled code.

          Now I'm stuck with another problem, though: tape data seems to be lacking the millisecond value.
          Is this by design?
          Does this depend on ZenFire? (would, for instance, IQFeed be any different?)

          Comment


            #6
            Correct, you would need to use a fresh instance then after code changes - unfortunately the granularity will be down to a second, sub-second access is on our list for future consideration.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            105 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            53 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            35 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            38 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            74 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X