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

NT7 - ExitOnClose, Friday Only

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

    NT7 - ExitOnClose, Friday Only

    I am attempting to build a NT7 strategy which would stay active all week, Sunday thru Friday and Exit on close on Friday only. I have tested the following script on SIM account. It seems to keep the position open thru the week but DOES NOT close it on Friday as required. Any help would be much appreciated. Thanks!!


    protected override void Initialize()
    {
    ExitOnClose = true;
    ExitOnCloseSeconds = 30;
    }

    protected override void OnBarUpdate()
    {
    if (Time[0].DayOfWeek == DayOfWeek.Friday)
    ExitOnClose = true;
    else
    ExitOnClose = false;
    }

    #2
    Hello SamIam,

    The help guide specifically states ExitOnClose must be set in Initialize().
    https://ninjatrader.com/support/help...xitonclose.htm

    I'm not certain if changing this in OnBarUpdate will lead to unexpected results.

    I propose two alternatives.

    Either use a week long session in a session template that spans from sunday to friday.
    https://ninjatrader.com/support/help...on_manager.htm

    Or just code the exit in the script.
    if (Time[0].DayOfWeek == DayOfWeek.Friday && ToTime(Time[0]) >= 45930) && Position.MarketPosition == MarketPosition.Long)
    ExitLong();
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you ChelseaB! I will test coding the exit in script recommendation.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X