Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Place order on the 2nd to last bar of the session

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

    Place order on the 2nd to last bar of the session

    Hi,

    In my strategy, is there a way to place an order on the close of the 2nd to last bar of the session or open of the last bar of the session? i.e if the session ends at 4:00pm and I'm on the M5 timeframe then the order would be placed on the close of the 3:55pm candle / open of the 4:00pm candle.

    I have a work around using times but wondered if there was a simpler way. I'm not sure if I can use Bars.IsLastBarOfSession as the order may not be able to be executed if the session has ended at the daily maintenance period at 5:00pm.

    Thanks,

    Neil
    Last edited by burtoninlondon; 03-22-2023, 03:17 AM.

    #2
    Hello Neil,

    Thank you for your note.

    As noted on the help guide page for IsLastBarOfSession, "When running Calculate.OnEachTick / OnPriceChange, this property will always return true on the most current real-time bar since it is the last bar that is updating in the trading session. If you need to find a bar which coincides with the session end time, please use the SessionIterator.ActualSessionEnd.​"

    Your workaround using times is the best way to achieve what you are looking for. If you want the order to happen on the open of the last bar of the session (which is the same as the close of the second to last bar - a bar is considered closed when the first tick of a new bar occurs) then you set your strategy to calculate OnEachTick and create a condition that checks if the candle's time is 4:00pm and also if it is the first tick of the bar using IsFirstTickOfBar. This could look like the following:
    if (ToTime(Time[0]) == 160000 && IsFirstTickOfBar)
    // place order here
    If you have logic that you would like to separate between calculating on bar close vs. on each tick, you could implement the ideas demonstrated in the following reference sample:


    Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    80 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X