PDA

View Full Version : Close at particular bar


jlm0@infionline.net
09-18-2007, 07:46 AM
What coding do i need to close either a long or short position at the close of a particular bar such as the 11:00 Am bar?

NinjaTrader_Ray
09-18-2007, 07:58 AM
Hi,

You can use the ToTime() method to compare the time of a bar. See the following Help Guide information.

http://www.ninjatrader-support.com/HelpGuideV6/ToTime.html

jlm0@infionline.net
09-19-2007, 03:45 AM
Hi,

You can use the ToTime() method to compare the time of a bar. See the following Help Guide information.

http://www.ninjatrader-support.com/HelpGuideV6/ToTime.html

Tried this code, for closing out at 4:00PM but it doesn't work?

if (ToTime(Time[0]) == ToTime(16,0,0) )
{
ExitLongLimit(Bars.CurrentBid);
ExitShortLimit(Bars.CurrentAsk);
}

ceesvh
09-19-2007, 05:02 AM
Jlm,

I think you should try

if (ToTime(Time[0]) >= ToTime(16,0,0) )

It might be that a tick is received 1 second after 16:00 hours and at that moment barclose is calculated. Time has passed 16:00:00 and the condition is not met.

Mike Winfrey
09-19-2007, 05:11 AM
This is what I use...

if (ToTime(Time[0]) >= 150000)) do something...

Mike

jlm0@infionline.net
09-19-2007, 06:22 AM
[quote=ceesvh;16266]Jlm,

I think you should try

if (ToTime(Time[0]) >= ToTime(16,0,0) )

It might be that a tick is received 1 second after 16:00 hours and at that moment barclose is calculated. Time has passed 16:00:00 and the condition is not met.


That sounds right.
Will try.
Thanks

jlm0@infionline.net
09-19-2007, 06:22 AM
[quote=Mike Winfrey;16268]This is what I use...

if (ToTime(Time[0]) >= 150000)) do something...

Mike



Sounds good.
Thanks

jlm0@infionline.net
09-19-2007, 06:23 AM
Not sure if I am replying correctly, but thanks for all the help!