Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitOnSessionClose On/Off Boolean

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

    ExitOnSessionClose On/Off Boolean

    Hey,

    I am trying to have an option to toggle between IsExitOnSessionCloseStrategy = true/false, and check whether strategy performs better intraday (with ExitOnSessionClose) or swing (without ExitOnSessionClose).

    I am using this code in State == State.SetDefauls
    Code:
     SXOSCBool = false; // Bool to toggle between ExitOnSessionClose
    SXOSCMin = 15; // integer for minutes that are multiplied by 60 to get seconds.
    I am using this code in State == State.Configure
    Code:
     if (SXOSCBool) // Bool to toggle between ExitOnSessionClose
    {
    IsExitOnSessionCloseStrategy = true; 
    ExitOnSessionCloseSeconds = SXOSCMin*60; // integer for minutes that are multiplied by 60 to get seconds. 
    }
    if (! SXOSCBool)
    {
    IsExitOnSessionCloseStrategy = false;
    }
    However, it doesn't work. It still exits all the positions at the end of the day, with exit name Exit On Session Close. How can this be achieved?

    #2
    Hello UltraNIX,

    Thank you for your post.

    Our help guide on these mentions IsExitOnSessionCloseStrategy and ExitOnSessionCloseSeconds may be set in State.Configure. Note that with backtesting, ExitOnSessionCloseSeconds has no effect and will exit on the last bar of session - it is a real time only property.

    Now, if you're seeing Exit on Session Close set to false and are still seeing those exits, that would be unexpected. If this is the case do you see the same testing with the built in Sample MA CrossOver on the Sim101 account?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      I got it to work.

      However, I want your help with other thing that is with conditional that depends on that SXOSCBool.

      I want my strategy to adjust default values of various parameters, depending on whether I set SXOSCBool to TRUE or to FALSE, Default value for ATRTarget would be 20 (if SXOSCBool is set to TRUE, meaning, it would exit on session close) and ATRTarget would be 40 (if SXOSCBool is set to FALSE, meaning, it would NOT exit on session close).

      Because I don't think it would support setting something like this in State == State.SetDefaults, and I want to use those "conditional parameters" in optimization, meaning I could optimize my strategy for both Intraday and Swing methods:
      Code:
       if (SXOSCBool)
      {
      ATRTarget= 20;
      }
      if (! SXOSCBool)
      {
      ATRTarget= 40;
      }

      Comment


        #4
        Hello UltraNIX,

        Thank you for your reply.

        Yes, you can actually set that in State.SetDefaults. I've created a very simple example strategy that uses your bool input to set a value for an ATRTarget int variable. It will print the current value of the bool and the ATRTarget to the lower right corner of the chart so you can easily confirm (this is all it does, it does not enter any orders).

        Please let us know if we may be of further assistance to you.
        Attached Files

        Comment


          #5
          Yes, it works, thanks. Another question I wanted to ask for some time.

          How is the data processed/loaded in NinjaTrader. I mean. If I have a conditional with SMA 20 period on daily chart, does that mean the strategy will not make any trades until 20 bars pass to calculate that 20 period SMA on daily chart, or will it look back to the past (historical data) and will start placing trades real time as soon as loaded (if entry conditions are met)?

          Comment


            #6
            Hello UltraNIX,

            Thank you for your reply.

            It would start calculations on whatever historical bars you have on the chart.

            Strategies have a concept of BarsRequiredToTrade, which is set to 20 by default. You can change this to 1, however, keep in mind you'll have to load at least 20 historical bars on the chart for an SMA(20) to be calculated fully. So make sure you have at least 20 days to load on your daily chart and you should be fine and the calculation accurate once you hit real time.

            Please let us know if we may be of further assistance to you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X