Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problems with Strategy Analyzer

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

    Problems with Strategy Analyzer

    So far, I have been unable to get any useful data from the Strategy Analyzer Back test and Optimizer. The main problem as far as I can tell is that Indicator data is ignored until the "session begins time". The problem is that any time Ninjatrader is connected to a data feed, it immediately grabs trade data going back several days and uses it to create chart information. When trading with a strategy that relies on an average (SMA/ EMA), the strategy analyzer pretends no data exists between the close the previous day and the opening of the current day. (This can be seen by viewing the chart after running a Backtest or Optimizer).

    I think what could solve this is to have a checkbox when running the Backtest or Optimizer, is to include all data so when the open starts (normally 9:30am), the indicators are already running (as occurs during live or replay trading).

    It would also be beneficial if an "ATM Strategy" could be applied (one created in SuperDOME). The ATM strategy could exit a trade before the strategy reverses. I tried creating exit strategies in the strategy wizard, but had no success with that.

    #2
    dsherman, a solution to the first problem you outlined would be to use a 24 hour session and then use a time filter to limit trading.

    With regards to your second question, applying an ATM Strategy, there already is a strategy demonstrating this very concept that comes with NinjaTrader. It is called 'SampleAtmStrategy'.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thank you. I see that. I guess it is the "Strategy Wizard" that is the problem here. The Wizard would be useful if the ATM strategy could be added and the "Session Time" was changed to "Trade time".

      Is there a use for the "Session time" as currently implemented? As implemented, the "Session time" starts the minimum bar count and trade data, something that I have a hard time visualizing actually happens in real trading.

      Comment


        #4
        Originally posted by dsherman View Post
        Thank you. I see that. I guess it is the "Strategy Wizard" that is the problem here. The Wizard would be useful if the ATM strategy could be added and the "Session Time" was changed to "Trade time".

        Is there a use for the "Session time" as currently implemented? As implemented, the "Session time" starts the minimum bar count and trade data, something that I have a hard time visualizing actually happens in real trading.
        I'm not exactly sure what you're trying to do, but it sure is possible to limit trading time in the Strategy Wizard. If that is what you're trying to accomplish, I've attached a picture that shows how to set the conditions to between 9:45AM and 12:00PM.

        The strategy wizard doesn't allow for integration of ATM concepts into your strategies.

        If you'd like a professional solution for your coding needs, you can always contact one of our 3rd party consultants.
        Attached Files
        AustinNinjaTrader Customer Service

        Comment


          #5
          Thank you. I will give that a try.

          Comment


            #6
            I added the code to a sample strategy from your site (crossover strategy)
            When I run a back test, it still enters trades outside the time window

            Here is the 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;
            #endregion

            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Strategy
            {
            /// <summary>
            /// March 2009 Traders' Tips for S&C
            /// </summary>
            [Description("March 2009 Traders' Tips for S&C")]
            public class MACDCrossOver : Strategy
            {
            #region Variables
            // Wizard generated variables
            private int fast = 12; // Default setting for Fast
            private int slow = 26; // Default setting for Slow
            private int smooth = 9; // Default setting for Smooth
            private int mAPeriod = 9; // Default setting for MAPeriod
            // User defined variables (add any user defined variables below)
            #endregion

            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
            Add(MACD(Fast, Slow, Smooth));

            CalculateOnBarClose = true;
            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            // Condition set 1
            if (ToTime(Time[0]) >= ToTime(9, 30, 0)
            && ToTime(Time[0]) < ToTime(15, 50, 0)
            && (CrossAbove(EMA(MACD(Fast, Slow, Smooth).Avg, MAPeriod), MACD(Fast, Slow, Smooth).Avg, 1)
            ))
            {
            EnterLong(DefaultQuantity, "");
            }

            // Condition set 2
            if (ToTime(Time[0]) >= ToTime(9, 30, 0)
            && ToTime(Time[0]) < ToTime(15, 50, 0)
            && (CrossAbove(MACD(Fast, Slow, Smooth).Avg, EMA(MACD(Fast, Slow, Smooth).Avg, MAPeriod), 1)))
            {
            EnterShort(DefaultQuantity, "");
            }
            }

            #region Properties
            [Description("MACD's Fast parameter")]
            [Category("Parameters")]
            public int Fast
            {
            get { return fast; }
            set { fast = Math.Max(1, value); }
            }

            [Description("MACD's Slow parameter")]
            [Category("Parameters")]
            public int Slow
            {
            get { return slow; }
            set { slow = Math.Max(1, value); }
            }

            [Description("MACD's Smooth parameter")]
            [Category("Parameters")]
            public int Smooth
            {
            get { return smooth; }
            set { smooth = Math.Max(1, value); }
            }

            [Description("Numbers of bars used for MA calculations")]
            [Category("Parameters")]
            public int MAPeriod
            {
            get { return mAPeriod; }
            set { mAPeriod = Math.Max(1, value); }
            }
            #endregion
            }
            }

            Comment


              #7
              dsherman, I downloaded and ran the code and everything appears to be fine on my end. It doesn't enter any trades before 9:30 and it doesn't exit or open any trades after 15:50. The way the strategy is currently programmed, no action is taken after the time filter has passed (including exiting any open trades).

              Can you post a screenshot or something showing how it doesn't work?
              AustinNinjaTrader Customer Service

              Comment


                #8
                This is what it looks like on my end. I just tried again after shutting down the program and restarting it.
                Attached Files

                Comment


                  #9
                  dsherman, a coworker and I will take a look at this and get back to you as soon as we can.
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks again.

                    What I am seeing specifically is that the strategy runs correctly when in live or replay mode. Even without the logic to restrict the trade times we manually entered, the strategy correctly uses the "session time" setting to limit when the trades are executed. It also calculates the indicators correctly.

                    It is in Strategy Analyzer when running Backtest and Optimizer that it runs incorrectly. It is in reverse. It trades 24/7 but limits the indicators to the "session time".

                    One more thing that the Strategy Analyzer does wrong is that it does not close the position as defined "Exit at close"=true. This works in Live mode, but not in "Market replay" nor Strategy Analyzer (both Backtest and Optimizer).
                    Last edited by dsherman; 07-15-2009, 05:04 AM.

                    Comment


                      #11
                      dsherman, with which session times are you running this modified strategy then in the Strategy Analyzer? Do you see the same ExitOnClose behavior with the default 'SampleMACrossOver' strategy?
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Bertrand,

                        The exit on close works correctly when running the Strategy Analyzer and Optimizer. It does not work on Market Replay.

                        The main problem persists though. I am unable to get close to any similarity between running a backtest and running live or Market replay.
                        It is a simple test to do, and as far as I can tell has nothing to do with the difference of tick data vs bar close data. The strategy is set to calculate on bar close.
                        Take a look at the attached graph. When running Strategy Analyzer, it counts the minimum number of bars from the session start time before the indicator is graphing and trading begins. When running live, or in Replay mode, Ninja Trader utilizes bar information going back before the session start time so the first trade can execute as soon as the session time begins.
                        Attached Files

                        Comment


                          #13
                          This is expected, please do not enter session times when doing the backtest, your time filters in the strategy itself would limit trading to your times then. This way the strategy has all the historical (presession, overnight) data available for the day to work from your session begin time as you would expect.
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            1. Why would the strategy settings behave one way in backtest and a different way in Replay/Live. In live/replay the session time settings behave as expected. In Strategy Analyzer they do not.

                            2. I tried adding the time restricting logic directly in the strategy and the backtest/optimizer still ignores the time restrictions. (See msg 6 and 8 in this thread).

                            Comment


                              #15
                              dsherman, the charts would use per default a 24 hr session so this would explain the differences you noticed, I checked with Austin and he tested the strategy you posted without issues on the default charts. If you now made further changes to the code, it would be best if you could post it here so we're talking about the same source. Thanks!
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              150 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post tkaboris  
                              Working...
                              X