NexusFi: Find Your Edge


Home Menu

 





Timed exit in auto strategy


Discussion in NinjaTrader

Updated
    1. trending_up 3,107 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?
How to apply profiles
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #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