Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Newbie

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

    Newbie

    Total newbie here. Trying out Ninja trader and so far like the possibilities. Two questions: 1) How do I add indexes and backtest (not the securities comprising the index)? For example, the EAFE, S&P 500, etc.

    Also, I'm trying to set up a basic long only 200 day moving average crossover system using Yahoo data as a test. The Sample systems all seem to run fine. What is wrong with my system below (told you I was a newbie):

    // 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 MA200 : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int mAPeriod = 200; // 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()
    {
    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Close[0] >= MAPeriod)
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (Close[0] < MAPeriod)
    {
    ExitLong("", "");
    }
    }

    #region Properties
    [Description("the moving average period")]
    [Category("Parameters")]
    public int MAPeriod
    {
    get { return mAPeriod; }
    set { mAPeriod = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #region Wizard settings, neither change nor remove

    #2
    Welcome to the forums! Your entry condition can never become true, please try something like -

    Code:
    if (Close[0] >= EMA(Close, MAPeriod)[0])
    {
    EnterLong(DefaultQuantity, "");
    }
    Same would apply to your exit....
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks

      Thanks, I'll try that. I used the new strategy wizard and that's what was produced. Any idea what I did wrong in the wizard?

      Also, where can I find instructions on how to backtest on individual securities or indexes that are not already listed in the dow 30, naz 100, or s&p 500? Specifically, I want to backtest a strategy on S&P 500 Index and SPY - how do I add them?

      Comment


        #4
        The wizard is just a powerful tool for non programmers, it does not guarantee the conditions entered produce valid trades, so you would need to check it's output and the results you get.

        Unfortunately you can't backtest on an index, but you can add the SPY's and try your strategy on those then - http://www.ninjatrader-support.com/H...eDatabase.html
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Still no data

          I still get no data - here's what it looks like, just trying to backtest the 200 SMA to start:

          // 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 MA200 : Strategy
          {
          #region Variables
          // Wizard generated variables
          private int mAPeriod = 200; // 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()
          {
          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Condition set 1
          if (Close[0] >= SMA(Close, MAPeriod)[0])
          {
          EnterLong(DefaultQuantity, "");
          }

          // Condition set 2
          if (Close[0] < SMA(Close, MAPeriod)[0])
          {
          ExitLong("", "");
          }
          }

          #region Properties
          [Description("the moving average period")]
          [Category("Parameters")]
          public int MAPeriod
          {
          get { return mAPeriod; }
          set { mAPeriod = Math.Max(1, value); }
          }
          #endregion
          }
          }

          Comment


            #6
            Suggest you first try opening a chart while connected to your data provider. You will not be able to backtest until you have data.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CortexZenUSA, Today, 12:53 AM
            0 responses
            2 views
            0 likes
            Last Post CortexZenUSA  
            Started by CortexZenUSA, Today, 12:46 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Started by usazencortex, Today, 12:43 AM
            0 responses
            5 views
            0 likes
            Last Post usazencortex  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            168 responses
            2,266 views
            0 likes
            Last Post sidlercom80  
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            13 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X