Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

closing positions 1 hour before rollover

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

    closing positions 1 hour before rollover

    Hi

    Reading the NT help guide and multiple posts on this forum (and special thanks to Chelsea's example that he gave in a previous post), I can get the rollover date of the current contract by using something like this:


    Rollover contractRollover = null;
    for (int i = 0; i < Instrument.MasterInstrument.RolloverCollection.Cou nt; i++)
    {
    if (Instrument.Expiry == Instrument.MasterInstrument.RolloverCollection[i].ContractMonth)
    {
    contractRollover = Instrument.MasterInstrument.RolloverCollection[i];
    break;
    }
    }
    DateTime rolloverDate = contractRollover.Date;


    I need some help to extend code logic: (1) today's date is the rollover date, AND, (2) during the penultimate 1-hour bar before the rollover, I want to send a market order to close out all my positions for the final 1-hour bar before rollover.

    Can someone help me write this code logic?

    Many thanks.


    #2
    Hello uday12,

    Thanks for your post.

    To exit at or after a certain time, you would want to create a time filter where you can then just issue an ExitLong() and ExitShort(), those methods will close any existing positions and if no positions then no action would be performed so you can use these exit methods without concern.

    To create a time filter, please review the working example here: https://ninjatrader.com/support/help...to_limit_t.htm

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X