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

Strategy Wizard Questions

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

    Strategy Wizard Questions

    I am new to Ninja Trader, but I am getting better with the Strategy Wizard. However, I have two related questions that I cannot find the answers to. Thanks in advance for your help.

    1. How do I set up a 200 day simple moving average for use with minute bars? If I put in 200 as the period and then backtest using minute bars, it will calculate the SMA for 200 minuate and not 200 days, correct? The answer cannot be to use 78,000 as the period (6.5 hours per day x 60 minutes per hour x 200 days). There has to be a way to calculate a MA (and other indicators) based on daily data when using minute bar, right?

    2. This is a related question, but how do I compare the close from two days ago to the close yesterday when I am backtesting using minute bars?

    Thanks again.

    #2
    Legal Eagles,

    Thank you for your post.

    1) You would need to add a second data series using the Daily interval and set the moving average to calculate from that data series. Unfortunately, you cannot add a second data series through the Strategy Wizard and will need to work from inside the code.

    Please see our Help Guide on working with Multiple Time Frames:



    2) You could do this rather easily by adding a Daily interval and referencing the Closes[2] and Closes[1].

    If you wanted to reference from the minute bars, you'd need to specify the close of the bar at the time end of each session. This would be possible via the Wizard, but it would be much easier to manage through adding a Daily interval and would accomplish both of your functions in your inquiry.
    MatthewNinjaTrader Product Management

    Comment


      #3
      I gave it a try (my first attempt working outside the Wizard). Can you take a look at let me know where I went wrong.

      In this case, I was looking to enter a long position at 3:58 pm if:
      The ask price is greater than the 10, 50 and 200 day SMAs;
      The ask price is greater than the prior day high;
      The ask price is greater than than the current day's open;
      The current day's open was greater than the prior day's close; and
      The close yesterday was greater than the close two days ago.

      I would then exist the long position at 9:02 am the next day.

      I will copy the code into the next reply. I used the wizard and then unlocked the code and tried to add the second daily interval data series.

      Comment


        #4
        Code, Part 1

        #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>
        /// Enter the description of your strategy here
        ///</summary>
        [Description("Enter the description of your strategy here")]
        publicclass Editor1 : Strategy
        {

        Comment


          #5
          Code Part 2
          ///<summary>
          /// Enter the description of your strategy here
          ///</summary>
          [Description("Enter the description of your strategy here")]
          publicclass Editor1 : Strategy
          {
          #region Variables
          // Wizard generated variables
          privatedouble stop = 0.005; // Default setting for Stop
          privatedouble profit = 0.005; // Default setting for Profit
          privateint mA1 = 200; // Default setting for MA1
          privateint mA2 = 50; // Default setting for MA2
          privateint mA3 = 10; // Default setting for MA3
          privateint dC1 = 20; // Default setting for DC1
          privateint dC2 = 55; // Default setting for DC2

          Comment


            #6
            Code Part 3
            // 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>
            protectedoverridevoid Initialize()
            {
            CalculateOnBarClose =
            true;
            }
            ///<summary>
            /// Called on each bar update event (incoming tick)
            ///</summary>
            protectedoverridevoid Initialize ()
            {
            Add (PeriodType.Day,
            1);
            }
            protectedoverridevoid OnBarUpdate()
            {

            Comment


              #7
              Code Part 4

              // Condition set 1
              if (GetCurrentAsk() > SMA(MA1)[1]
              && GetCurrentAsk() > SMA(MA2)[
              1]
              && GetCurrentAsk() > SMA(MA3)[
              1]
              && GetCurrentAsk() > PriorDayOHLC().PriorHigh[
              0]
              && GetCurrentAsk() > CurrentDayOHL().CurrentOpen[
              0]
              && CurrentDayOHL().CurrentOpen[
              0] > PriorDayOHLC().PriorClose[0]
              && PriorDayOHLC().PriorClose[
              1] > PriorDayOHLC(1).PriorClose[1]
              && ToTime(Time[
              0]) == ToTime(15, 58, 0))
              {
              EnterLong(DefaultQuantity,
              "");
              }
              // Condition set 2
              if (ToTime(Time[0]) == ToTime(9, 32, 0))
              {
              ExitLong(
              "", "");
              }
              }

              Comment


                #8
                Let me know if you need the region properties code section. The code below is in reverse order. Is there a way to copy all of the code into one reply? Thanks for being patient with a newbie.

                Comment


                  #9
                  Congratulations on taking your first steps outside of the wizard! You're on your way to taken full advantage of NinjaScript automated strategies. You're on the right track here, just a few minor corrections:


                  In post #6 you have two instances of the Initialize() method. Please removed one of these instances and include the Add() method in the same section as the CalulateOnBarClose property.

                  Code:
                  protectedoverridevoid Initialize()
                  {
                  CalculateOnBarClose = true;
                  Add(PeriodType.Day, 1);
                  }
                  I also corrected a typo where there was a space between the Add and the opening parenthesis (

                  For the moving averages, you will need to specify these to use your Daily data series as the input series. You can specify this by adding BarsArray[1], where this will be the data series you added in the Initialize () method.

                  Then instead of PriorDayOHLC, Current Day, etc, you can just reference the daily bar itself using Closes[1][1], where the first index value [1] is the added data series (daily) and the second [1] one bar ago

                  Code:
                      if (GetCurrentAsk() > SMA(BarsArray[1], MA1)[1]
                              && GetCurrentAsk() > SMA(BarsArray[1], MA2)[1]
                              && GetCurrentAsk() > SMA(BarsArray[1], MA3)[1]
                              && GetCurrentAsk() > Highs[1][1]
                              && GetCurrentAsk() > Opens[1][0]
                              && Opens[1][0] > Closes[1][1]
                              && ToTime(Time[0]) == ToTime(15, 58, 0))
                              {
                              EnterLong(DefaultQuantity, "");
                              }
                  Please let me know if you have additional questions.
                  MatthewNinjaTrader Product Management

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by AttiM, 02-14-2024, 05:20 PM
                  11 responses
                  184 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by fernandobr, Today, 09:11 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by timmbbo, Today, 08:59 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by KennyK, 05-29-2017, 02:02 AM
                  2 responses
                  1,281 views
                  0 likes
                  Last Post marcus2300  
                  Started by itrader46, Today, 09:04 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Working...
                  X