Timed exit in auto strategy - futures io
futures io futures trading



Timed exit in auto strategy


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Timed exit in auto strategy

(login for full post details)
  #1 (permalink)
Brisbane, Australia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-Fire
Trading: CL
 
nanobiotech's Avatar
 
Posts: 670 since Jun 2009
Thanks: 134 given, 429 received

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 futures io?
Help Needed: TOS Options Chain IV & IMPL MOVE Calcul …
ThinkOrSwim
Work with historical tcks data on MUltichart NET PowerLa …
MultiCharts
SimplerOptions
Trading Reviews and Vendors
Reading A set of Trading Signals
EasyLanguage Programming
ZigZag with Depth and Backstep
EasyLanguage Programming
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Battlestations: Show us your trading desks!
124 thanks
Big Mike in Ecuador
61 thanks
Want your NinjaTrader indicator created, free?
28 thanks
If you needed one-on-one help with any trading issue, ho …
26 thanks
Selling Options on Futures?
21 thanks
 
(login for full post details)
  #2 (permalink)
OC, California, USA
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,958 since Jun 2009
Thanks: 528 given, 3,648 received


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 futures io Trade Journal Reply With Quote
The following 2 users say Thank You to shodson for this post:
 
(login for full post details)
  #3 (permalink)
Brisbane, Australia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus/Zen-Fire
Trading: CL
 
nanobiotech's Avatar
 
Posts: 670 since Jun 2009
Thanks: 134 given, 429 received


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

Started this thread Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Timed exit in auto strategy


Last Updated on December 28, 2009


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts