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

Strategy Always Exits on Close regardless of settings

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

    Strategy Always Exits on Close regardless of settings

    Hi,

    I Have a simple ninja trader 8 script generated from a template.

    In OnStateChange() function I set IsExitOnSessionCloseStrategy to false.

    However in the strategy analyzer it always closes my position at the end of the session. I do not want this. I want the position to remain in effect even if the ninja trader strategy is not running. (will this be different in real time settings versus backtesting?)

    Also a way to stop running the strategy while not closing positions in code would also be helpful.

    Thanks!

    #2
    Thanks for your post TrevorC and welcome to the forums!

    In OnStateChange() under State.SetDefaults, the default value for the IsExitOnSessionCloseStrategy property can be set. Upon enabling the strategy, the user can set this property as they wish.

    When testing with the SampleMACrossover strategy in the Strategy Analyzer, we can see that when we test with Exit On Session Close set to true, we get multiple exits on the session close. With the property set to false, we can see that there is one Exit On Session close to close the open position at the end of the backtest. We can expect to see this one Exit On Session close when the Strategy Analyzer backtest ends with an open position.

    It is possible to close a strategy programmatically and it is also possible to override the CloseStrategy() behaviors. If you override this method and do not call base.CloseStrategy(), the strategy positions will not be closed. Publicly available documentation on CloseStrategy() can be found below.

    CloseStrategy() - https://ninjatrader.com/support/help...sestrategy.htm

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by trilliantrader, 04-18-2024, 08:16 AM
    7 responses
    27 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by samish18, 04-17-2024, 08:57 AM
    17 responses
    64 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by rocketman7, Today, 02:12 AM
    2 responses
    17 views
    0 likes
    Last Post rocketman7  
    Started by briansaul, Today, 05:31 AM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by PaulMohn, Today, 03:49 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X