Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit on Close Fridays Only

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

    Exit on Close Fridays Only

    I want to have a strategy exit on close only if its Friday, so I don't hold positions over the weekend.

    Since ExitOnClose must be set in initialize, I don't think I can have any logic that uses ExitOnClose only if its Friday. Or can I?

    So I came up with this.

    if ((ToTime(Time[0]) >= 150000) && (Time[0].DayOfWeek == DayOfWeek.Friday))
    {
    if (Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong(
    100000);
    }

    if (Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort(
    100000);
    }
    }

    I have some instances on backtest that show that it is not working as expected....

    Example

    CalculateOnBarClose = true;

    Timestamps are at close of bar.

    Position.MarketPosition == MarketPosition.Long

    A bar closes with a closing timestamp of 15:45:57

    I expected to be taken flat on the close of that bar.

    But that isn't what happens. What am I doing wrong?

    #2
    Crassius, that's correct ExitOnClose could then not be used in your case here for an exit only before the weekend.

    How's your entry signal named?

    If you add TraceOrders = true in Initialize() and open the output window while running the strategy would you see any errors / notifications for this action then?

    Comment


      #3
      is exitonclose more effective than using conditional times to exit? the reason that i may want to exit on conditionals instead of the session is that i want to keep the data of the session on the chart, but exit before the session end.

      also, if i exit on close, does it exit on the close of the bar or right at the exact time?, if my chart is not time based

      Comment


        #4
        ExitOnClose is comparable to custom time coded conditions, however if you custom code it you would have more flexibility. The ExitOnCloseSeconds property defines how many seconds before the Session end to exit with ExitOnClose (works realtime only!).

        ExitOnClose takes the current time in realtime trading as reference and bar time in backtesting.

        Comment


          #5
          i see, so if i coded manually to the second precision-wise, backtesting would reflect that i closed on the bar close time, which may well be beyond the time i wanted a definite close by..

          Comment


            #6
            Originally posted by Crassius View Post


            I have some instances on backtest that show that it is not working as expected....

            Example

            CalculateOnBarClose = true;

            Timestamps are at close of bar.

            Position.MarketPosition == MarketPosition.Long

            A bar closes with a closing timestamp of 15:45:57

            I expected to be taken flat on the close of that bar.

            But that isn't what happens. What am I doing wrong?
            Is there another bar opened on Friday after your action bar? If not, then that bar is not yet closed. The bar is only closed at the start of the next bar. If there is no bar after that bar on friday, there will be no action.

            Comment


              #7
              Correct, for a manual code exit you could add a low granular series and then access it's timestamps (Times property) to achieve a higher precision exit. For realtime running you would need to keep in mind orders can take their time to fill depending on size & market liquidity.

              Comment


                #8
                so even a manual exit (no matter how granular) on time would have a bad exit timestamp in this instance?

                Comment


                  #9
                  No, the real-time executed exit would give you the time of the execution, which is stamped according to your local PC clock.

                  Comment


                    #10
                    oops i meant in the backtesting scenario would give you a false timestamp..

                    Comment


                      #11
                      I see, thanks for clarifying - the timestamp in backtesting seen is limited by the series you execute on.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      647 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      368 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      108 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      571 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      573 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X