NexusFi: Find Your Edge


Home Menu

 





Timed exit in auto strategy


Discussion in NinjaTrader

Updated
    1. trending_up 3,099 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Timed exit in auto strategy

  #1 (permalink)
 
nanobiotech's Avatar
 nanobiotech 
Brisbane, Australia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-Fire
Trading: CL
Posts: 670 since Jun 2009
Thanks Given: 134
Thanks Received: 430

I know you can set the Session begin and end time in Chart properties - is this a reliable way to limit the time an auto strategy runs?

Also, is there a practical way to code this in the strategy? Say to limit the time the strategy runs for 2 hours or a time variable only?

Nano

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Build trailing stop for micro index(s)
Psychology and Money Management
NexusFi Journal Challenge - April 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
 
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
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #2 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


nanobiotech View Post
I know you can set the Session begin and end time in Chart properties - is this a reliable way to limit the time an auto strategy runs?

Also, is there a practical way to code this in the strategy? Say to limit the time the strategy runs for 2 hours or a time variable only?

Nano

Sure. Here's how the OnBarUpdate() of all of my strats look like

 
Code
                            
protected override void OnBarUpdate()
{
    if (
TimeToTrade)
    {
        if (
InPosition)
            
ManageTrade();
    
        if (!
InPosition)
            
LookForTrade();
    }
    else
    {
        if (
InPosition)
            
FlattenPosition();
    }
}

.........


private 
bool TimeToTrade
{
    
get
    
{
        if (
_tradeTimeBegin == || _tradeTimeEnd == 0)
            return 
true;
        else
        {
            if (
_tradeTimeBegin _tradeTimeEnd)    // sessions that begin previous day and end next day
              
return ToTime(Time[0]) >= _tradeTimeBegin || ToTime(Time[0]) <= _tradeTimeEnd;
            else
              return 
ToTime(Time[0]) >= _tradeTimeBegin && ToTime(Time[0]) <= _tradeTimeEnd;
        }
    }
}    

...............

private 
int _tradeTimeBegin 0// Default setting for TTB
[Description("Beginning trading time")]
[
Category("Parameters")]
public 
int TTB
{
    
get { return _tradeTimeBegin; }
    
set _tradeTimeBegin Math.Max(0value); }
}

private 
int _tradeTimeEnd 0// Default setting for TT
[Description("Ending trading time")]
[
Category("Parameters")]
public 
int TTE
{
    
get { return _tradeTimeEnd; }
    
set _tradeTimeEnd Math.Max(0value); }

So when I run/backtest the strat I set the TTB and TTE to the times I want trading to begin/end, regardless of the session time as defined by Ninja because often you have indicators that rely on previous bars of data that are outside of your trading range.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
 
nanobiotech's Avatar
 nanobiotech 
Brisbane, Australia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-Fire
Trading: CL
Posts: 670 since Jun 2009
Thanks Given: 134
Thanks Received: 430


Thanks Shodson, I appreciate your help. I'll give this a go.
Nano

Started this thread Reply With Quote




Last Updated on December 28, 2009


© 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