NexusFi: Find Your Edge


Home Menu

 





Time of day?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one patbateman with 9 posts (1 thanks)
    2. looks_two Fat Tails with 5 posts (3 thanks)
    3. looks_3 monpere with 3 posts (5 thanks)
    4. looks_4 NinjaTrader with 2 posts (0 thanks)
      Best Posters
    1. looks_one monpere with 1.7 thanks per post
    2. looks_two NJAMC with 1.5 thanks per post
    3. looks_3 Fat Tails with 0.6 thanks per post
    4. looks_4 patbateman with 0.1 thanks per post
    1. trending_up 7,948 views
    2. thumb_up 12 thanks given
    3. group 4 followers
    1. forum 20 posts
    2. attach_file 2 attachments




 
Search this Thread

Time of day?

  #11 (permalink)
 
patbateman's Avatar
 patbateman 
NY, NY
 
Experience: None
Platform: T4, NinjaTrader
Trading: All!
Posts: 235 since Mar 2012
Thanks Given: 113
Thanks Received: 200


NinjaTrader View Post
As it currently stands, it seems that bug is not in NinjaTrader but in your code.

Your thread here - Time of day? - [AUTOLINK]NinjaTrader[/AUTOLINK] Support Forum

No it wasn't... that error was in a sample code, and I mentinoed the fix in the post before.

I was going to make another post on your forum (NT support), but I gave up. However here is what I found, and I think it strongly supports a bug in NT:
  • Using the format if (time xxx) { if (strategy / time) { order } } is the only way it will function
  • It will correctly execute the time on some contracts, and not others. Why is this? Bug in the ninjascript?
  • On the contracts where the time clause does not function, it only ignores the <= timeofday clause. In other words, it starts trades at the beginning of the time period, and goes to the close - not the end of the time period.



"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Build trailing stop for micro index(s)
Psychology and Money Management
Deepmoney LLM
Elite Quantitative GenAI/LLM
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
23 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #12 (permalink)
 
NinjaTrader's Avatar
 NinjaTrader  NinjaTrader is an official Site Sponsor
Site Sponsor

Web: NinjaTrader
AMA: Ask Me Anything
Webinars: NinjaTrader Webinars
Elite offer: Click here
 
Posts: 1,713 since May 2010
Thanks Given: 203
Thanks Received: 2,686


patbateman View Post
No it wasn't... that error was in a sample code, and I mentinoed the fix in the post before.

I was going to make another post on your forum (NT support), but I gave up. However here is what I found, and I think it strongly supports a bug in NT:
  • Using the format if (time xxx) { if (strategy / time) { order } } is the only way it will function
  • It will correctly execute the time on some contracts, and not others. Why is this? Bug in the ninjascript?
  • On the contracts where the time clause does not function, it only ignores the <= timeofday clause. In other words, it starts trades at the beginning of the time period, and goes to the close - not the end of the time period.


I see, thanks for clarifying. I have since re-read the thread. Two issues I see here. One is your comments on how to evaluate time which is independent from the second issue about orders submitting on some contracts and not on others.

- Time evaluation is simple to isolate, take the order submission out of the "If time condition" and place Print() statements. If you get print statements on bars that you should not be included in the time condition then there must be something wrong with the time condition. We have run tests here on our ToTime() and Time[] (which returns a .NET DateTime structure (not our code) and it works as expected.

Once the time conditions are created and working as expected (without any order submission code) then you can add back in order submission methods. If this is now not working as expected, then likely it has something to do with your strategy order handling settings? That is the first place I would like and I would also enable TraceOrders = true since this will print out any reason why an order submission method is ignored to the NinjaScript Output window.

Follow me on Twitter Reply With Quote
  #13 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



patbateman View Post
No it wasn't... that error was in a sample code, and I mentinoed the fix in the post before.

I was going to make another post on your forum (NT support), but I gave up. However here is what I found, and I think it strongly supports a bug in NT:
  • Using the format if (time xxx) { if (strategy / time) { order } } is the only way it will function
  • It will correctly execute the time on some contracts, and not others. Why is this? Bug in the ninjascript?
  • On the contracts where the time clause does not function, it only ignores the <= timeofday clause. In other words, it starts trades at the beginning of the time period, and goes to the close - not the end of the time period.

@patbateman:

You have written a dirty piece of code with a few bugs and you are complaining about NinjaTrader by making a lot of noise. Did you realize that ?

Actually all those commands are not NinjaScript, but C#, and it would be enough to have a look at the MSDN Library, where these commands are explained. See below

MSDN Library

NinjaTrader may have a few little bugs (all software packages that I know have them), but they are more subtle and will not affect any simple strategies.

Reply With Quote
Thanked by:
  #14 (permalink)
 
patbateman's Avatar
 patbateman 
NY, NY
 
Experience: None
Platform: T4, NinjaTrader
Trading: All!
Posts: 235 since Mar 2012
Thanks Given: 113
Thanks Received: 200


Fat Tails View Post
@patbateman:

You have written a dirty piece of code with a few bugs and you are complaining about NinjaTrader by making a lot of noise. Did you realize that ?

Actually all those commands are not NinjaScript, but C#, and it would be enough to have a look at the MSDN Library, where these commands are explained. See below

MSDN Library

NinjaTrader may have a few little bugs (all software packages that I know have them), but they are more subtle and will not affect any simple strategies.

I've been a supporter of Ninjatrader, and have persuaded friends to go with it over other retail platforms... there is a bug in this however. Let me know which code is dirty - unless if you're referring to the cursory example I put in the bullet list, I obviously did not write the whole thing for the sake of time and continuity. I hope it's also obvious to you what my point is (wrapping the ToTime in one if statement versus individual if statements).

I think it's generally well accepted around the board that NT has many bugs, most of them little (such as this apparent one... see my bullet list before attacking me on this) but some of them quite large. I often get the impression that working for NT is stressful, with poor team development and a management that brings the hammer down on them when things don't go their way. A few posts around here have mentioned the performance of strategy development in NT versus how many developers work there. Just my opinion, though.

I still think it's the best retail platform out there for retailers, especially considering the limitations with Easy-Language, and oft-cited poor performance with IB and some other products out there. I'm really looking forward to NT8 - even though they don't have the slightest idea of when it will be ready, and even though it probably won't be around until next year, even if they are planning on it sooner. Software is tough - if Apple has problems with Final Cut and can't get Lion out without big stress on employees (friends)...

"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote
Thanked by:
  #15 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


patbateman View Post
I've been a supporter of Ninjatrader, and have persuaded friends to go with it over other retail platforms... there is a bug in this however. Let me know which code is dirty - unless if you're referring to the cursory example I put in the bullet list, I obviously did not write the whole thing for the sake of time and continuity. I hope it's also obvious to you what my point is (wrapping the ToTime in one if statement versus individual if statements).

@ patbateman: If a strategy does not work, best you export it and attach it here, then it is more easy to see, where the problem lies. This is what you have published on the NinjaTrader forum:

 
Code
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");
 }
Just a few comments. Line 1 is already false, as this would normally trigger a long entry with each single bar, if one moving average is above the other, the correct code for a cross entry would be

 
Code
if (SMA(14)[0] > EMA(14)[0] && SMA(14)[1] <= EMA(14)[1]
You were just luckky that NinjaTrader did only take one entry per direction. Maybe you specified this somewhere in the Intialize section, which you did not post. Anyhow the code is not correct.

There is a bug in line 3, as you used ">=" instead of "<="

Line 7 is false in the same way as is line 1.

The whole logic used is false. If you enter a position, if there is a long cross during the specified time interval, and you exit a position for a short cross in that same time interval, then you will end up with a long position, if the last cross was a long cross, and that long position will be held until the close - unless you have disabled ExitOnClose, in that case the position will be held until the next working day.

Two logical errors and a bug, that strategy for sure cannot work correctly.

Reply With Quote
Thanked by:
  #16 (permalink)
 
patbateman's Avatar
 patbateman 
NY, NY
 
Experience: None
Platform: T4, NinjaTrader
Trading: All!
Posts: 235 since Mar 2012
Thanks Given: 113
Thanks Received: 200


Fat Tails View Post
@ patbateman: If a strategy does not work, best you export it and attach it here, then it is more easy to see, where the problem lies. This is what you have published on the NinjaTrader forum:

 
Code
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");
 }
Just a few comments. Line 1 is already false, as this would normally trigger a long entry with each single bar, if one moving average is above the other, the correct code for a cross entry would be

 
Code
if (SMA(14)[0] > EMA(14)[0] && SMA(14)[1] <= EMA(14)[1]
You were just luckky that NinjaTrader did only take one entry per direction. Maybe you specified this somewhere in the Intialize section, which you did not post. Anyhow the code is not correct.

There is a bug in line 3, as you used ">=" instead of "<="

Line 7 is false in the same way as is line 1.

The whole logic used is false. If you enter a position, if there is a long cross during the specified time interval, and you exit a position for a short cross in that same time interval, then you will end up with a long position, if the last cross was a long cross, and that long position will be held until the close - unless you have disabled ExitOnClose, in that case the position will be held until the next working day.

Two logical errors and a bug, that strategy for sure cannot work correctly.

I had picked up on that error (this code is sample code I wrote for NT btw) two days ago here - NinjaTrader Support Forum - View Single Post - Time of day?

I also posted two other strategies (one here) that are uploaded and do not work in NT. No bugs in them!

You probably missed my post which is fine, so now you know. The reality however is the bug is prevalent and I'm still working on trying to possibly rid it myself. I will reset the instruments, then reinstall today to see what happens. My bullet list above outlines exactly what happens.

Btw, you don't have to, but since you're going over my code, make your own sample strategy to see how NT functions to this (if you have not already).

"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote
  #17 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


patbateman View Post
I also posted two other strategies (one here) that are uploaded and do not work in NT. No bugs in them!


The strategy which I found under the link, also has a few bugs. Your code:

 
Code
/// <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");
            }
        }


(1) If you enter a long position via EnterLong(), NinjaTrader will close out short positions.

So you do not need and should not use ExitShort(). This may result in an overfill. Just scrap the ExitLong() and ExitShort() commands.


(2) In one line you used 12,000 instead of 120,000 for the time filter.

Reply With Quote
  #18 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371


patbateman View Post
I had picked up on that error (this code is sample code I wrote for NT btw) two days ago here - NinjaTrader Support Forum - View Single Post - Time of day?

I also posted two other strategies (one here) that are uploaded and do not work in NT. No bugs in them!

You probably missed my post which is fine, so now you know. The reality however is the bug is prevalent and I'm still working on trying to possibly rid it myself. I will reset the instruments, then reinstall today to see what happens. My bullet list above outlines exactly what happens.

Btw, you don't have to, but since you're going over my code, make your own sample strategy to see how NT functions to this (if you have not already).

Here's an example

namespace NinjaTrader.Strategy
{
public class a0test : Strategy
{
#region Variables
#endregion

protected override void Initialize() {
CalculateOnBarClose = true;
}

protected override void OnBarUpdate() {
//### Only trade between 8am and 12noon
if (ToTime(Time[0]) >= 080000 && ToTime(Time[0]) < 120000) {

DrawText("Hour"+CurrentBar, Time[0].Hour+"", 0, High[0]+(20*TickSize), Color.Blue);
//###
//### Put your order execution code below
//###
}
}

#region Properties
#endregion
}
}


Reply With Quote
Thanked by:
  #19 (permalink)
 
patbateman's Avatar
 patbateman 
NY, NY
 
Experience: None
Platform: T4, NinjaTrader
Trading: All!
Posts: 235 since Mar 2012
Thanks Given: 113
Thanks Received: 200


monpere View Post
Here's an example

namespace NinjaTrader.Strategy
{
public class a0test : Strategy
{
#region Variables
#endregion

protected override void Initialize() {
CalculateOnBarClose = true;
}

protected override void OnBarUpdate() {
//### Only trade between 8am and 12noon
if (ToTime(Time[0]) >= 080000 && ToTime(Time[0]) < 120000) {

DrawText("Hour"+CurrentBar, Time[0].Hour+"", 0, High[0]+(20*TickSize), Color.Blue);
//###
//### Put your order execution code below
//###
}
}

#region Properties
#endregion
}
}


I'll try that right now, thanks allot for sharing -

are the print statements required? I have not been using them, but maybe it's required and that's what I've been missing all along...

"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote
  #20 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


Print statements are not required.

Print statements can be used for debugging.

If you want to know, which value a specific variable took, while the indicator was running, you can print those values to the NinjaTrader output window.

Just open that window and watch how the values are being printed.

Reply With Quote




Last Updated on April 21, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts