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 NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    89 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    152 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    80 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    53 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    63 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X