Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by AaronKoRn, Today, 09:49 PM
    0 responses
    1 view
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    6 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    8 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,974 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X