Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time of day?

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

    Time of day?

    I noticed that when you apply a template (i.e. excluding certain times of days; CME US Index RTH, etc.) to a chart or strategy, the gap wrecks allot of indicators (example attached).

    Is it possible to enter directly into a strategy's code what time of day it should execute, so the default 24/7 template may be used to avoid gaps indicators?

    I added

    && ToTime(Time[0]) >= ToTime(8, 0, 0)
    && ToTime(Time[0]) <= ToTime(12, 0, 0)

    But it doesn't work...


    Thanks for your continued awesome support
    Last edited by gg007; 04-19-2012, 02:58 PM.

    #2
    Here is a screen shot that shows indicators gapping because of the template...

    how can I enter what time of day the program should trade in the ninjascript?

    Thanks a ton for your great support
    Attached Files

    Comment


      #3
      Hi gg007,

      Yes, you can integrate a time filter in your strategy, and it will look much like you have posted there. A complete strategy with a time filter is available here in this sample:


      With the time filter you posted, you should expect it to check that bar time stamps fall in range 8:00 AM to 12:00 PM. Are you seeing something different than this?

      I'd also like to add that one of our partners provides a custom solution that helps work around price differences at session breaks. You can find their site here:
      Gapless Indicators self-adjust in real-time to any opening gap, repainting-free. No additional market data downloads, setups, or configurations required. Simply start using gapless ones instead of the classic ones and enjoy the benefits. Gapless Indicators can also be used in automated strategies, as well as in backtesting, optimization, and walk-forward. List includes EMA, SMA, HMA, WMA, Stochastics, MACD, RSI, CCI, ADX, ATR, Bands, ParabolicSAR, Support Resistance, Linear Regression
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        No it does not work.

        I tried the code I originally posted, and I also tried to do the sample code of ToTime(Time[0]) >= 80000. I and selecting 'use instrument settings' as the template, and also tried 24/7. I'm also working with volume bars. Guess it doesn't work

        Comment


          #5
          edit... a little tweaking got it to work.

          Comment


            #6
            Unfortunately none of it is working. I thought it was my fault because I didn't enter the time on the exit orders, however I have

            && ToTime(Time[0]) > 80000
            && ToTime(Time[0]) < 12000

            On all conditions, yet it still enters trades outside the time period.

            Comment


              #7
              So is this feature disfunctional or something? Should I move on?

              Comment


                #8
                It works here. We've had the same sample for years and thousands of users have downloaded and used it. One thing to keep in mind is that in a historical (backtest) setting, conditions are evaluated on any given bar, and then orders are submitted to the next bar after the condition evaluates true.

                Let's figure out what's different about your expectations or your usage.

                Please share the whole code snippet or file you're using and we can take a quick look. Include as well a screenshot showing execution times if you can. If you're viewing a performance report, this would be shown on the executions tab.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  I

                  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>
                      /// -- C 4/12
                      /// </summary>
                      [Description("-- C 4/12")]
                      public class Strat : Strategy
                      {
                          #region Variables
                          // Wizard generated variables
                          private int n = 14; // Default setting for N
                          private double ph = 0; // Default setting for Ph
                          private int q = 1; // Default setting for Q
                          // 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()
                          {
                              if (JMA(N, Ph)[0] > JMA2(N, Ph)[1]
                  				&& ToTime(Time[0]) > 80000
                  				&& ToTime(Time[0]) < 12000)
                              {
                                  EnterLong(Q, "Buy");
                              }
                  
                              if (JMA(N, Ph)[0] < JMA2(N, Ph)[1]
                  				&& ToTime(Time[0]) > 80000
                  				&& ToTime(Time[0]) < 120000)
                              {
                                  EnterShort(Q, "Short");
                              }
                  		 	if (JMA(N, Ph)[0] > JMA2(N, Ph)[1]
                  				&& ToTime(Time[0]) > 80000
                  				&& ToTime(Time[0]) < 120000)
                              {
                                  ExitShort("Cover", "Short");
                              }
                  
                              if (JMA(N, Ph)[0] < JMA2(N, Ph)[1]
                  				&& ToTime(Time[0]) > 80000
                  				&& ToTime(Time[0]) < 120000)
                              {
                                  ExitLong("Sell", "Short");
                              }
                          }
                  
                          #region Properties
                          [Description("")]
                          [GridCategory("Parameters")]
                          public int N
                          {
                              get { return n; }
                              set { n = Math.Max(1, value); }
                          }
                  
                          [Description("")]
                          [GridCategory("Parameters")]
                          public double Ph
                          {
                              get { return ph; }
                              set { ph = Math.Max(-100, value); }
                          }
                  
                          [Description("")]
                          [GridCategory("Parameters")]
                          public int Q
                          {
                              get { return q; }
                              set { q = Math.Max(1, value); }
                          }
                          #endregion
                      }
                  }
                  Attached Files

                  Comment


                    #10
                    Here is another example of the time funcitons not working, this time with the NT wizard suggested code.

                    Does this not work, or am I doing something wrong? If it doesn't work (like the ask prices) then I'll just move on and try to work around it...

                    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>
                        /// Test
                        /// </summary>
                        [Description("Test")]
                        public class Test14 : Strategy
                        {
                            #region Variables
                            // Wizard generated variables
                            // 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 (SMA(14)[0] > EMA(14)[0]
                                    && ToTime(Time[0]) >= ToTime(17, 33, 19)
                    				&& ToTime(Time[0]) >= ToTime(18, 33, 19))
                                {
                    				EnterLong(1, "Buy test14");
                                }
                    			if (SMA(14)[0] < EMA(14)[0]
                                    && ToTime(Time[0]) >= ToTime(17, 33, 19)
                    				&& ToTime(Time[0]) <= ToTime(18, 33, 19))
                                {
                    				ExitLong("Sell test14", "Buy test14");
                                }
                            }
                    
                            #region Properties
                            #endregion
                        }
                    }
                    Attached Files

                    Comment


                      #11
                      The periods tab breaks down trades based on the time the bar end To verify that this is working, please check execution tab and look at the times. Also keep in mind that orders are submitted to the next bar after the condition.

                      It also helps to print all values used in your condition, so you can verify everything is what you expect them to be. Please see here for help using print statements and TraceOrders output to debug your NinjaScript code:


                      If you're still not able to follow what the strategy should be doing, start simplifying by removing or commenting out code blocks -- work with say only 1 entry and 1 exit. Get your strategy in a state where you understand everything it's doing before adding additional complexity.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        I really appreciate the help.

                        Lets be clear - I posted two strategies which are very simple. They are just moving average crosses. Around 20 lines of code, or 130 lines for the whole thing. Did you take a look at them?

                        Ninjatrader is not functioning. This is another apparent bug that simply doesn't work (unless you can point me to something that will get it working besides reviewing my strategy).

                        Execute on the next bar? These aren't multi hour long bars... orders are all over the place, both in the periods section and execution section (btw, screenshot attached of the execution tab, as you requested).

                        If you're not familiar with the time series, no biggie, although maybe someone else around does. Any thoughts? Should I move on?
                        Attached Files

                        Comment


                          #13
                          We're willing to help point you in the right direction to track things down on your own, but unfortunately cannot offer complete debugging. It's for sure a simple strategy that could use additional simplification if you're not following its behavior in its current state.

                          We're also more than willing to investigate a potential bug report, but there's nothing shown here yet that indicates a bug. The code should do what it's designed to do and you're working in an area that's been established and stable for some time and for many users.

                          If you haven't yet Printed the values used in your conditions, there's not yet anything for us to really follow up on. Check the actual values and you should find that code behavior is consistent with them. If they're not, please share with us the steps needed to see this, along with a simplified version of the strategy.

                          If you are looking for professional help developing and debugging your strategy, please consider hiring a NinjaScript consultant for this:
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            No, Ninjatrader has bugs, and is placing orders outside of the specified times.

                            You say you won't debug strategies, although that wasn't what I was asking... I can't simplify the 10 lines of example code I wrote anymore; if you looked at it you would know that. The code is so simple, I can say it in one breath:

                            if (SMA(14)[0] > EMA(14)[0]
                            && ToTime(Time[0]) >= ToTime(17, 33, 19)
                            && ToTime(Time[0]) >= ToTime(18, 33, 19))
                            {
                            EnterLong(1, "Buy test14");
                            }
                            if (SMA(14)[0] < EMA(14)[0]
                            && ToTime(Time[0]) >= ToTime(17, 33, 19)
                            && ToTime(Time[0]) <= ToTime(18, 33, 19))
                            {
                            ExitLong("Sell test14", "Buy test14");
                            }


                            I gave two screenshots and two example codes that it does not work. I suggest you try to replicate it with the code I provided, then try your own strategies, before blaming me and the two simple examples I provided- Unless Ninjatrader has never had a disastrous bug before and you believe it's absolutely impossible for there to be something wrong with NT source code, especially at $180/mo.

                            I was wondering if I should move on and not worry about the NT bug, or if I was not following the correct instructions. It seems very clear that NT is bugged in this respect. Maybe no one has rose the issue because no one uses an obscure feature like time. All I really asked was to move on or be corrected with what I was doing wrong.
                            Attached Files
                            Last edited by gg007; 04-19-2012, 04:36 PM.

                            Comment


                              #15
                              Thanks for the test setup and screenshots. Are you using the latest release 7.0.1000.9?

                              Do you intend for this?
                              && ToTime(Time[0]) >= ToTime(17, 33, 19)
                              && ToTime(Time[0]) >= ToTime(18, 33, 19))

                              As it's written you're not checking for a range but any time stamp after 17:33:00 will meet the condition. I changed this condition to make a range and everything is working as expected here. No executions outside the times in the condition. Are you compiling your code changes by Right Clicking > Compile? And then running a new report after any changes?

                              Any insight gained when printing the value used in your conditions? Check Tools > Output Window and please let us know if you ever see a time stamp that doesn't meet the preceding conditions:

                              Code:
                              if (SMA(14)[0] > EMA(14)[0]
                              && ToTime(Time[0]) >= ToTime(17, 33, 19)
                              && ToTime(Time[0]) <= ToTime(18, 33, 19)) //edited your version.
                              {
                              EnterLong(1, "Buy test14");
                              Print("Buy: " + ToTime(Time[0]));
                              }
                              if (SMA(14)[0] < EMA(14)[0]
                              && ToTime(Time[0]) >= ToTime(17, 33, 19)
                              && ToTime(Time[0]) <= ToTime(18, 33, 19))
                              {
                              ExitLong("Sell test14", "Buy test14");
                              Print("Sell: " + ToTime(Time[0]));
                              }
                              Last edited by NinjaTrader_RyanM1; 04-19-2012, 05:08 PM.
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Lumbeezl, 01-11-2022, 06:50 PM
                              31 responses
                              817 views
                              1 like
                              Last Post NinjaTrader_Adrian  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              5 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by swestendorf, Today, 11:14 AM
                              2 responses
                              6 views
                              0 likes
                              Last Post NinjaTrader_Kimberly  
                              Started by Mupulen, Today, 11:26 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post Mupulen
                              by Mupulen
                               
                              Started by Sparkyboy, Today, 10:57 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X