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

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
    BertrandNinjaTrader Customer Service

    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
        BertrandNinjaTrader Customer Service

        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 cutzpr, Today, 08:54 AM
          0 responses
          6 views
          0 likes
          Last Post cutzpr
          by cutzpr
           
          Started by benmarkal, Today, 08:44 AM
          0 responses
          10 views
          0 likes
          Last Post benmarkal  
          Started by Tin34, Today, 03:30 AM
          2 responses
          26 views
          0 likes
          Last Post Tin34
          by Tin34
           
          Started by sastrades, Yesterday, 09:59 AM
          2 responses
          41 views
          0 likes
          Last Post brucerobinson  
          Started by ETFVoyageur, Today, 12:52 AM
          1 response
          24 views
          0 likes
          Last Post Leeroy_Jenkins  
          Working...
          X