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 Rapine Heihei, 04-23-2024, 07:51 PM
      2 responses
      30 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by Shansen, 08-30-2019, 10:18 PM
      24 responses
      942 views
      0 likes
      Last Post spwizard  
      Started by Max238, Today, 01:28 AM
      0 responses
      9 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by rocketman7, Today, 01:00 AM
      0 responses
      4 views
      0 likes
      Last Post rocketman7  
      Started by wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      28 views
      0 likes
      Last Post wzgy0920  
      Working...
      X