Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

overnight margin hours

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

    overnight margin hours

    Hello, I was looking for some input on the best way to solve a problem I am having. I want to have my positions close out when overnight margins take effect not when the market closes. So say I want any open CL positions to close out at 15:45 EST and not at market close of 17:00 EST.


    So I was thinking one of these, first create a session template that thinks the market closes at 15:45 and then opens up at 15:46. This will make for bad charts as when the market is really closed (at 17:00) there will be no data. But the market on close function should do the trick here.


    Second, I thought I could set the exit on close seconds to reflect one hour and 15 minutes before 17:00. So 75 minutes * 60 seconds = 4,500 seconds before close to get all CL positions flat. This seems hack but I guess it would work.


    Lastly I could write in a close function into the code:


    Code:
    if
         (
         EMA50 > EMA100
         ||  
         ((ToTime(Time[0]) >= 154400 && ToTime(Time[0]) <= 180000)
         && Position.MarketPosition == MarketPosition.Short
         )
         {
         Close position
         }
    This last one seems the least tenable as ToTime functions seem to not do what they are supposed to do.


    Market on close is what I want to use if I can. Any thoughts?

    #2
    Hello JimPunkrockford,

    Thank you for your note.

    The code you posted should work with the exception of {Close position} which should be in the form of ExitLong(””,””).

    Another way you could have your positions closed 75 minutes before the actual close to avoid overnight margins would be to use ExitOnClose in the code. For example,

    protected override void Initialize()
    ExitOnClose = true;
    ExitOnCloseSeconds = 4500; // 75 minutes * 60 Seconds

    See ExitOnCloseSecondssection of our Helpguide:


    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    65 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    41 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    23 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    26 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    52 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X