Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Close a position to a specific time

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

    Close a position to a specific time

    Hi support team,

    I want to close a possible open posititon at a time I input into the strategy.
    Let's assume that I wan't close any position 20sec before 6 pm. My strategy works with "CalculateOnBarClose = true" and the interval is 8min.

    Normally there is no chance to trigger the close with that constellation, right?

    My possible solutions are looking as follow:
    1. Using a internal Timer and the raising timer event will be checked to close the position.

    2. Implementing the code in the callback "OnMarketData"

    3. Or Developing a separate timer indicator which has the flag CalculateOnBarClose set to false; And in the ObBarUpdate I check the time and fired a event to the registered strategy. (this way I have implemented) Maybe there are some sideeffects with threadsafe data handling?

    Many Thanks....
    cicondo

    #2
    cicondo, in realtime this should work as ExitOnClose would reference your PC clock time for this. In backtesting you can submit orders to a finer datastream for execution and thus work off the finer timestamps then - http://www.ninjatrader-support2.com/...ead.php?t=6652

    Comment


      #3
      Hi Bertrand,

      thanks to your quick answer. But what I missed to explain is that I don't want to set the session start or end values. This is because the strategy starts and ends trading in several timed blocks during the day. So it is possible to trade between 9:30am to 11:am then from 1 pm until 5:30pm
      and so on...

      Hope this makes something clear...
      By the way are there any sideeffects using events to cooperate with a strategy?

      Thanks Bertrand


      Originally posted by NinjaTrader_Bertrand View Post
      cicondo, in realtime this should work as ExitOnClose would reference your PC clock time for this. In backtesting you can submit orders to a finer datastream for execution and thus work off the finer timestamps then - http://www.ninjatrader-support2.com/...ead.php?t=6652

      Comment


        #4
        cicondo, I'm not aware of side effect when using custom events in a strategy. You might want to consult this reference sample - http://www.ninjatrader-support2.com/...ead.php?t=5965

        You of course don't have to use the session linked ExitOnClose feature, you can also achieve a time exit of positions using the Time / DateTime comparisons - http://www.ninjatrader-support.com/H...deV6/Time.html

        Comment


          #5
          Bertrand!

          PERFECT!
          This is excactly what need to be sure that events will work. This will clean up my code really. Thank's for your support!

          cicondo

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X