Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy adding trades outside trade window

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

    Strategy adding trades outside trade window

    Hi,
    I have built a strategy that is supposed to trade inside a defined time window. But when I run the Strategy Analyzer I see that it takes trades outside the given window. All at >8 am and 3 pm (Local Time), and it is supposed to trade between 7:30 am and 8:00 am (Local Time).

    I have those parameters set in my strategy, and while running backtest, it gets that wrong result.

    How can I fix this?
    I and building it in the Strategy Builder, but can also make edits in the Source Code.

    Appreciate it!


    Click image for larger version

Name:	image.png
Views:	116
Size:	178.0 KB
ID:	1260099​​
    Attached Files

    #2
    Hello carlosgutierrez,

    Thank you for your post.

    When creating a strategy with the strategy builder that you would like to only trade during certain times, you should add any order actions inside of a time filter condition:


    Another item to consider is if there is an open position at the end time of the filter and that the position should then be closed. Here is an example where I create a condition that checks if the position is long and if the time for the current bar is greater than or equal to the 8:00am (as an example, you could use your end time input if you'd like), then the action is to close the open position. Here is an example video of how this could be set up in the strategy builder:
    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    You would also need to consider creating the same type of condition/action set that checks if the position is short and it is after the end time, then exit the short position.

    For the 3pm timestamps in your screenshot, I suspect that maybe there was an open position and the strategy was set to "Exit on session close" so that an exit order was submitted at that time. You could uncheck Exit on session close and run the test again to review the results and compare. For more details on backtest properties:


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

    Comment


      #3
      Thnanks Emily!

      I do have the time constraints in place. I will uncheck the "Exit on session close", I might've miss interpreted its meaning.

      On the example you shared, if I leave the Exit Long position as-is, will it kill all my orders? My strategy uses 3 position entries with respective StopLoss and Profit Target.


      TIA!!

      Comment


        #4
        Hello carlosgutierrez,

        Thank you for your reply.

        To clarify, Exit On Session Close is not the cause of the behavior you are reporting though it is likely the reason why you were seeing exits with the timestamp of 3:00 PM. If a position remains open up until the session close time minus the exit on session close seconds, an order will be submitted to close that position. My understanding from your description is that you do not want a position to remain open past 8 AM local time. This means that you could set up a condition to close any position that is open past that time.

        Although your strategy uses 3 different position entries, if you submit an ExitLong() or ExitShort() order without a specific value for fromEntrySignal then the exit will be attached to all entries to close the entire open position. There is a note about this on the following help guide pages in the description for "fromEntrySignal"Please let us know if we may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        72 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X