Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Platform Technical Support

Platform Technical Support General platform technical support for NinjaTrader 7.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 04-19-2012, 01:23 PM   #1
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default Time[0] does NOT work

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 at 02:58 PM.
gg007 is offline  
Reply With Quote
Old 04-19-2012, 02:09 PM   #2
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default

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 Images
File Type: jpg gaps.jpg (318.6 KB, 11 views)
gg007 is offline  
Reply With Quote
Old 04-19-2012, 02:10 PM   #3
NinjaTrader_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 436 times in 429 posts
Default

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:
http://www.ninjatrader.com/support/f...ead.php?t=3226

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:
http://www.gaplessindicators.com/Home.aspx
NinjaTrader_RyanM1 is offline  
Reply With Quote
Old 04-19-2012, 02:18 PM   #4
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default

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
gg007 is offline  
Reply With Quote
Old 04-19-2012, 02:25 PM   #5
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default

edit... a little tweaking got it to work.
gg007 is offline  
Reply With Quote
Old 04-19-2012, 02:27 PM   #6
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default

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.
gg007 is offline  
Reply With Quote
Old 04-19-2012, 02:44 PM   #7
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default

So is this feature disfunctional or something? Should I move on?
gg007 is offline  
Reply With Quote
Old 04-19-2012, 03:21 PM   #8
NinjaTrader_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 436 times in 429 posts
Default

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.
NinjaTrader_RyanM1 is offline  
Reply With Quote
Old 04-19-2012, 03:30 PM   #9
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default

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 Images
File Type: jpg Project1.jpg (500.0 KB, 8 views)
gg007 is offline  
Reply With Quote
Old 04-19-2012, 03:36 PM   #10
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default

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 Images
File Type: jpg Project2.jpg (575.9 KB, 3 views)
Attached Files
File Type: cs Test14.cs (1.7 KB, 3 views)
gg007 is offline  
Reply With Quote
Old 04-19-2012, 03:40 PM   #11
NinjaTrader_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 436 times in 429 posts
Default

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:
http://www.ninjatrader.com/support/f...ead.php?t=3418

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.
NinjaTrader_RyanM1 is offline  
Reply With Quote
The following user says thank you to NinjaTrader_RyanM1 for this post:
Old 04-19-2012, 03:58 PM   #12
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default

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 Images
File Type: jpg Project3.jpg (636.3 KB, 5 views)
gg007 is offline  
Reply With Quote
Old 04-19-2012, 04:10 PM   #13
NinjaTrader_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 436 times in 429 posts
Default

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:
http://www.ninjatrader.com/partners#...pt-Consultants
NinjaTrader_RyanM1 is offline  
Reply With Quote
Old 04-19-2012, 04:33 PM   #14
gg007
Junior Member
 
Join Date: Apr 2012
Posts: 14
Thanks: 1
Thanked 0 times in 0 posts
Default

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 Images
File Type: jpg Project3.jpg (636.3 KB, 7 views)
Last edited by gg007; 04-19-2012 at 04:36 PM.
gg007 is offline  
Reply With Quote
Old 04-19-2012, 04:48 PM   #15
NinjaTrader_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 436 times in 429 posts
Default

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 at 05:08 PM.
NinjaTrader_RyanM1 is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Time of Day johnlucas General Development 20 03-08-2012 09:31 AM
Time of day TroyEarth Platform Technical Support 2 01-03-2012 04:48 AM
Day and Time 30percent General Development 5 12-21-2011 08:40 AM
Time of day ckait Platform Technical Support 3 09-07-2011 06:44 AM
resetting flag at end of day or a certain time of day sauer11155 Strategy Development 5 09-23-2008 08:30 AM


All times are GMT -6. The time now is 09:34 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.