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

Putting an Indicator inside a Strategy

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

    Putting an Indicator inside a Strategy

    Hello.

    I have an indicator that uses "Protected override void OnMarketData(MarketDataEventArgs e)" to gather realtime tick volume. This information is later used to build a trend indicator. This indicator can not be used in Market Replay, because it doesn't work with historical data, since NT 7 doesn't collect that data.

    I want to put this code inside of an existing strategy I have, so that the trend indicators will generate automated signals.

    Question. Do you see any reason why that won't work? Can I put OnMarketData inside of a strategy? Are there any NT indicator reserved words that can't exist inside of a strategy?

    #2
    Hello rcsingleton, and thank you for your question.

    Methods such as OnBarUpdate() and OnMarketData() are methods of the base Indicator and Strategy class, and are available in both. To demonstrate the difference, I have provided a small code sample, which does compile. If you attempted to run this, you would only see output from the Strategy, and not from the Indicator.

    Code:
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Enter the description of your strategy here
        /// </summary>
        [Description("Enter the description of your strategy here")]
        public class Example1470821 : Strategy
        {
            #region Variables
            // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
            private MySMA sma;
            #endregion
            
            private class MySMA : SMA
            {
                protected override void OnBarUpdate()
                {
                    Print("OnBarUpdate called from indicator");
                }
                protected override void OnMarketData(MarketDataEventArgs e)
                {
                    Print("OnMarketData called from indicator");
                }
            }
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                sma = new MySMA();
                sma.CalculateOnBarClose = false;
                CalculateOnBarClose = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                Print("OnBarUpdate called from Strategy");
            }
            
            protected override void OnMarketData(MarketDataEventArgs e)
            {
                Print("OnMarketData called from Strategy");
            }
    
            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = Math.Max(1, value); }
            }
            #endregion
        }
    }
    All the event handling methods, such as OnBarUpdate, present in Indicators, are present in Strategies as well.

    By the way, an indicator or strategy with OnMarketData() should work in Market Replay. It is not historical data. I am including a link to the Help Guide sections for Market Replay and Historical Data for more information.



    http://ninjatrader.com/support/helpGuides/nt7/historical_data.htm"
    Jessica P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by PhillT, Today, 02:16 PM
    2 responses
    3 views
    0 likes
    Last Post PhillT
    by PhillT
     
    Started by Kaledus, Today, 01:29 PM
    3 responses
    9 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by frankthearm, Yesterday, 09:08 AM
    14 responses
    47 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by gentlebenthebear, Today, 01:30 AM
    2 responses
    14 views
    0 likes
    Last Post gentlebenthebear  
    Started by PaulMohn, Today, 12:36 PM
    2 responses
    17 views
    0 likes
    Last Post PaulMohn  
    Working...
    X