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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    57 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    133 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X