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, Yesterday, 03:01 PM
    3 responses
    30 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by cmtjoancolmenero, Yesterday, 03:58 PM
    4 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Brevo, Today, 01:45 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by rjbtrade1, 11-30-2023, 04:38 PM
    2 responses
    74 views
    0 likes
    Last Post DavidHP
    by DavidHP
     
    Started by suroot, 04-10-2017, 02:18 AM
    5 responses
    3,022 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X