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 cre8able, Yesterday, 01:16 PM
    3 responses
    11 views
    0 likes
    Last Post cre8able  
    Started by ChartTourist, Today, 08:22 AM
    0 responses
    4 views
    0 likes
    Last Post ChartTourist  
    Started by LiamTwine, Today, 08:10 AM
    0 responses
    2 views
    0 likes
    Last Post LiamTwine  
    Started by Balage0922, Today, 07:38 AM
    0 responses
    5 views
    0 likes
    Last Post Balage0922  
    Started by JoMoon2024, Today, 06:56 AM
    0 responses
    6 views
    0 likes
    Last Post JoMoon2024  
    Working...
    X