Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Effected exit after certain time of day

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Effected exit after certain time of day

    Hi,

    I'm currently using the following snippet of code:

    if(ToTime(Time[0])>=235500)
    {
    ExitLong();
    }

    The strategy runs on Range bars, and COBC is true. I am using a similar bit of code (as above) to take the first entry of the day after some specific time. That works okay. Once entered, the strategy is always in the market and reverses only. The reversals occur using limit orders. There is no stop loss or profit target orders.

    The problem is, the end of day exit (code above) is not effecting an exit. I think the problem has to do with operating on bar close, each bar is always less than 235500, until some bar closes after that; which is almost always some bar into the next day, say 000100; which of course is not >=235500.

    Any way to work around this?

    #2
    Hello coolmoss,

    Thanks for writing in. I am happy to help.

    Yes, you are correct that it is because of the COBC is true and using Range bars you may not always see a bar time stamped in range of 11:55:00 PM to 12:00:00 AM. Now, you can always set COBC to false so that way it can calculate on a tick by tick basis. One problem that you may run into though is if there is no tick data in that time frame your order will not get filled.

    If you are using that strategy in a backtest you can view the following post for intrabar granularity.
    You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


    If there is no data incoming, OnBarUpdate() will not be ran. You could increase the time frame to manage your orders by either moving the time frame back or check early the next day to get a better chance of having data to managing your order. Otherwise, you could use a TriggerCustomEvent() to help manage your orders by a set time frame instead of having to wait the next tick. See Link below. See Link below.


    Please let me know if I can be of further assistance.
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    666 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    377 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    110 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    575 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    580 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X