Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to temporarily pause trading

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

    How to temporarily pause trading

    I want to trade forex data 24 hours a day with an automated strategy except when the exchanges are closed. I get my data from IBKR and not only do they shut down data feed at the typical end of day 5:00 Eastern, they also shut down at midnight for some time. During both of those times I often get an outlier value (like 0.0 or -1.0) at the beginning of the shutdown. So I must avoid those. The obvious thing to use is the Trading Hours tool. So I set one up (below). I would prefer the EOD flag not to be set until Friday close but that apparently is not possible. One must be defined for each day. In my code I set IsExitOnSessionCloseStrategy = false; but it matters not that that is set false because at the end of each trading session, the strategy exits. My code is written to keep checking if the strategy is in or out of session with a SessionIterator, so that it would get the next session from the Trading Hours.

    Code:
       
    if (! this.sessionDefined
    ||    Bars.IsFirstBarOfSession)
    {
        this.sessionIterator.GetNextSession(Time[0], true);
        this.beginTradingTime = this.sessionIterator.ActualSessionBegin;
        this.endTradingTime = this.sessionIterator.ActualSessionEnd;
        this.sessionDefined = true;
    }
    ​
    At the end of a session I cancel all existing orders and execute Position.Close("Exiting active position at market");. Then I reset sessionDefined to false so that it would keep looking for a new session but it never gets a chance because the strategy simply exits irrespective. I gather that EOD probably forces an exit irrespective of the value of IsExitOnSessionCloseStrategy, but since EOD is not active at midnight, I wouldn't expect a shutdown then. I don't want to have to get up after the midnight shutdown to restart the strategy.

    Is there a way to keep the strategy running, iterating through each defined session until Friday, or at least until each EOD?



    Click image for larger version

Name:	Screenshot 2025-01-21 122950.png
Views:	141
Size:	24.7 KB
ID:	1331869








    Attached Files

    #2
    Hello dweems,

    Thank you for your post.

    Unfortunately if there is a forced disconnection / logout by your broker, there is no way for the strategy to keep itself from disabling. You would need to manually reconnect/reenable the strategy.

    Comment


      #3
      There is a system within the IBKR software for restarting it automatically. That's not my problem. The problem is that the strategy is disabled automatically rather than running after the session has completed. I want the strategy to keep running when the session ends and look for the next session. I don't want to have be there in person after midnight to restart the strategy.

      Comment


        #4
        Hello dweems,

        "I get my data from IBKR and not only do they shut down data feed at the typical end of day 5:00 Eastern, they also shut down at midnight for some time."

        If IB is forcing the disconnection / log out at midnight, there is nothing NinjaTrader can do to prevent the strategy from disabling after a complete disconnection. You will need to manually reenable the strategy if your broker is forcing a log out / disconnection.

        Comment


          #5
          I will test your contention that it is the data feed shutdown that is causing the strategy to exit by moving the end of session time to 10 minutes before midnight. I'm tracing all of my transactions on the output window, including a line that shows the date/time when the session ends and whether it keeps iterating after the session ends. We'll see what happens tonight.....

          Comment


            #6
            So what effect does the connection status parameters have on this? The settings for "On Connection Loss" I have "Handling -> Keep Running", "Disconnect Seconds -> 36000", "Number of restart attempts -> 1000" and "Restart within x minutes -> 5". I thought these excessive values would keep the strategy running even with the disconnection and when the connection reestablishes, it would continue. Does this mean the disconnection referred to above is simply the Internet connection and not the data stream? From what you are saying there is really nothing I can do if the data feed disconnects? That correct? Nothing can be done???

            Comment


              #7
              By the way, I want to give you the results of my test last night. I moved the trading hours to end 10 minutes earlier than midnight. According to my tracing output, the strategy shut down when my session closed, not at midnight. I did not see the strategy continue iterating through OnBarUpdate after that point, which I thought it would. From what you say, it seems to me that it would keep running until the data feed terminated and then exit the strategy. So I'm unsure what the think now.

              Comment


                #8
                Hello dweems,

                The Trading hours template would limit the hours that the chart is receiving data. OnBarUpdate() will not update outside of the session.

                The Exit on session close will close all positions and cancel any working orders at the end of the session but the strategy will keep running and ready to start processing bars once the new session has opened.

                A disconnect (and not a connection loss) would cause all strategies to become disabled and will require manually re-enabling.

                The connection loss handling is for connection losses (not disconnections) due to high latency. As long as the connection is not disconnected and there is a temporary connection loss NinjaTrader will automatically re-establish the connection and run the connection loss handling to either keep running or re-calculate.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  When you say "disconnect", is that something performed by the strategy or the data feed system from IBKR? If the latter, I'll see if there is a way to keep IBKR up even after they stop sending data, if that's possible.

                  Comment


                    #10
                    A disconnect would come from your data feed. It has to do with your actual connection to data/your broker. If there is no connection (a disconnect has occurred), the strategy will become disabled.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    81 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    149 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    79 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    52 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    59 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X