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

trades opening after ExitOnSessionCloseSeconds

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

    trades opening after ExitOnSessionCloseSeconds

    I discovered in certain cases when a position is closed due to the ExitOnSessionCloseSeconds setting, it appears that sometimes an opening trade condition happens to be true and so the strategy immediately opens a new trade the very next second. I'd rather it waited till the next session. Is that not enforced by ExitOnSessionClose behind the scenes?

    I've tried controlling it myself with logic that looks like this:

    /// Market Hours Filter
    //
    DateTime t = DateTime.Now;
    bool tradeable = t > Convert.ToDateTime("4:00:00 PM") || t < Convert.ToDateTime("2:00:00 PM") ? true : false; /// 2pm - 2:30pm closing only
    if (!tradeable) Print("Prepping day end. Closing only"); /// control in openTrades section

    ​But it seems that doesn't work when running replay I believe perhaps because DateTime.Now grabs the current time instead of the time from the market replay. Is there another way?

    Mark
    Last edited by markdshark; 06-12-2023, 12:03 PM.

    #2
    Hello, thanks for writing in. The session time is always defined by the Session Template, so it would be possible for the strategy to enter another order after exiting from the session close signal. The DateTime.Now will not work because this will always reference your computer's clock. The Time[] array would need to be used to read the timestamps coming from the Playback connection. One would need to make a time filter so that the strategy only trades during a certain time. There is an example on how to make this here:

    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by StockTrader88, 03-06-2021, 08:58 AM
    45 responses
    3,992 views
    3 likes
    Last Post johntraderuser2  
    Started by TAJTrades, Today, 09:46 AM
    0 responses
    7 views
    0 likes
    Last Post TAJTrades  
    Started by rhyminkevin, Yesterday, 04:58 PM
    5 responses
    62 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by realblubb, Today, 09:28 AM
    0 responses
    8 views
    0 likes
    Last Post realblubb  
    Started by AaronKoRn, Yesterday, 09:49 PM
    1 response
    19 views
    0 likes
    Last Post Rikazkhan007  
    Working...
    X