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 8,066 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?

  #1 (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

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?

"A Jedi's strength flows from the force."
-Yoda
Attached Thumbnails
Click image for larger version

Name:	gaps.jpg
Views:	132
Size:	318.6 KB
ID:	70572  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #2 (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

Update... I added

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

But it doesn't work...

"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote
  #3 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,395



patbateman View Post
Update... I added

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

But it doesn't work...

I think Time[0] yield something like a string. I think 8AM is 80000, so something like this may work (or get you close):

&& Time[0] >= 80000 && Time[0] <= 120000

I don't think they need to be strings but something along this line will work. I have it in a few indicators and will look when I get home if you still need it.

Try this if the above doesn't work:
&& Time[0] >= "080000" && Time[0] <= "120000"

Be sure to add the leading 0 on the single digit times.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (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 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?

Yes, it is possible. My strategies only trade during specific times of the day. For example, if you have a breakout strategy you may not want to trade the false breakouts in the early afternoon.

Best you define some TimeSpan variables for the start and end times during which you want to enter positions. Then serialize these variables to make them accessible. Code a flag to check whether your current bar is within one of those time intervals. If this is the case allow for order execution.

Reply With Quote
Thanked by:
  #5 (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
Yes, it is possible. My strategies only trade during specific times of the day. For example, if you have a breakout strategy you may not want to trade the false breakouts in the early afternoon.

Best you define some TimeSpan variables for the start and end times during which you want to enter positions. Then serialize these variables to make them accessible. Code a flag to check whether your current bar is within one of those time intervals. If this is the case allow for order execution.

I updated it to
 
Code
&& ToTime(Time[0]) > 02000
				&& ToTime(Time[0]) < 08000
yet still does not work... the session template works, but not the time code. Session template doesn't work for me because of price gaps leading indicators to give bad readings.

I made a thread on the NT board, and only had snide responses from the rep (Ryan). I wrote an example program that was an EMA/SMA cross, and he told me to go back and make it simpler. Obviously not even looking at what I wrote for him. Crap bugs in software are fine if you can work around them and make it better for everyone, but not idiot programmers who are as efficient as a steam engine with holes telling me yet again to look at myself so their managers won't bring the hammer down on them.

Oh well... thanks for the response ft and nj

"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote
  #6 (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

edit... regarding your suggestion, are you saying

if (ToTime xxxxxx )
{
if (strategy) { lxxx ong xxx }
}

"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote
  #7 (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

Also one quick update... to be clear, I'm trying to get the strategy to execute only during certain times of days. Maybe this function isn't what this is for...

"A Jedi's strength flows from the force."
-Yoda
Started this thread Reply With Quote
  #8 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,395


patbateman View Post
Also one quick update... to be clear, I'm trying to get the strategy to execute only during certain times of days. Maybe this function isn't what this is for...


I did implement it a little complex and not sure how this will work in the wizard, but you might be able to round off to the Hour or something to make it simpler
m_Time=Time[0].Hour.ToString("D2")+Time[0].Minute.ToString("D2")+Time[0].Second.ToString("D2");
m_InTimeWindow=Filter_TimeWindow(m_Time,m_TimeStart1,m_TimeEnd1);

Here is the function Filter_TimeWindow():

 
Code
#region Filter_TimeWindow        
        // --------------------------------------------------
        //   Filter_TimeWindow(string m_Time,string m_StartWindow,string m_StopWindow)
        //    
        //        m_Time:         Time to test against window, 24H format HHMMSS
        //        m_StartWindow:     Start of window, 24H format HHMMSS
        //        m_StopWindow:     End of window, 24H format HHMMSS
        //
        //    NOTE: window assumed to be less than 24 hours, if Start>Stop spans over midnight
        //
        //   Returns true if m_Time is within window
        //   Returns false if m_Time is outside window
        // --------------------------------------------------
        
        private bool Filter_TimeWindow(string m_Time,string m_StartWindow,string m_StopWindow)
        {
            bool m_FilterReturn=false;

            if (Convert.ToInt64(m_StartWindow) < Convert.ToInt64(m_StopWindow)) 
            {        // Within the same day since Start<Stop
                if ((Convert.ToInt64(m_StartWindow)<=Convert.ToInt64(m_Time)) &&
                    (Convert.ToInt64(m_StopWindow)>=Convert.ToInt64(m_Time)))
                         m_FilterReturn=true;
            }
            else
            {        // Wraps over midnight, window start time to Midnight and then next morning to stop
                if ((Convert.ToInt64(m_StartWindow)<=Convert.ToInt64(m_Time)) ||
                    (Convert.ToInt64(m_StopWindow)>=Convert.ToInt64(m_Time)))
                         m_FilterReturn=true;
            }
            
            return m_FilterReturn;
        }
#endregion
You might be able to use the "Time[0].Hour" which returns an Int.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #9 (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
Also one quick update... to be clear, I'm trying to get the strategy to execute only during certain times of days. Maybe this function isn't what this is for...

From TN Help manual


// Only trade between 7:45 AM and 1:45 PM
if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
{
// Strategy logic goes here
}

Reply With Quote
Thanked by:
  #10 (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

Crap bugs in software are fine if you can work around them and make it better for everyone, but not idiot programmers who are as efficient as a steam engine with holes telling me yet again to look at myself so their managers won't bring the hammer down on them.


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

Follow me on Twitter 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