Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
what exactly are you looking for? Code for a signal that closes a trade at the end of the session?
In backtesting you can use "SetExitOnClose". However you need to be aware of it's limitations as it will use the closing price of the session that is market as session end in Quotemanager. In realtime this obviously can't work and it even might skew your backtesting as it will not represent an accurate test (as how often would you get filled at the exact closing tick).
I have not had luck with that code for the reason you stated.
Henry at Multicharts posted the code below at the Multicharts.net forum to overcome the problem and to allow you to set your trading times with a time filter.
I was looking for a similar thing in easylanguage.
The example above has been provided for Realtime trading:
Code:
bool _Condition = DateTime.Now.TimeOfDay >= _tStart && DateTime.Now.TimeOfDay <= _tEnd;
For Backtesting please use the following code:
Code:
bool _Condition = Bars.TimeValue.TimeOfDay >= _tStart && Bars.TimeValue.TimeOfDay <= _tEnd;
Nice !
And that has worked for you on both live and backtesting ?
Excellent. Thank you.
That will work on most.
On one of my strategies, I use an indicator for entries into the market. One problem I ran into is that the indicator can get changed with custom session times.
That is why I was hoping to code trading times into the strategy. That way, I can leave the chart on full globex session times so as not to change the indicator.
The reason I asked: Just be careful that there actually is trading going on after endtime and stoptime. For instance, if last bar of the day is at 1600, then the statement if time = endtime and MP > 0 then sell this bar on close;
won't work in real time (market will be closed by the time order is sent)...