Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reset variables on reconnect

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

    Reset variables on reconnect

    Hi! In case my strategy would be disconnected during a trading session, I want to reset some variables when reconnected again. How can I do this? I'v tried the following code, but that doesn't seam to work.

    Code:
    Variables:
    private ConnectionStatus dataFeed = ConnectionStatus.Connected;
    private ConnectionStatus broker = ConnectionStatus.Connected;
    
    protected override void OnBarUpdate()
    {
    
        if ( (dataFeed != ConnectionStatus.Connected) || (broker != ConnectionStatus.Connected) 
    
    }
    
    protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus) 
    {
        dataFeed = priceStatus;
        broker = orderStatus;
                    
         Print(DateTime.Now + " Orderstaus: " + orderStatus + " Pricestatus: " + priceStatus);        
    }

    #2
    poseidon_sthlm, please reset them directly in OnConnectionStatus() and not in the OnBarUpdate().

    Comment


      #3
      Eventually I managed to trigger the OnConnection method when i set IB as primary datafeed and then shut down TWS. But that was the only way I could test this.

      Actually I need an event to reset variables on connecting to a datafeed, no matter if it is a reconnection due to an interuption of some kind or if I do shut down an restart NT myself in the middle of a trading session. Is there another alternative than OnConnectionStatus? If I'm not misstaken this wont work the way I want since the datafeed has to be connected before one can start a new strategy? What other options are there to catch the "datafeed connection event"? FirstBarOfSession only triggers at the time specified in the chart properties, doesn't it?

      Comment


        #4
        poseidon_sthlm,

        Catch the reconnect from disconnect form OnConnectionStatus(). For your other requirements, you can use something like if (!Historical). Use that along with a bool that is only true for the for the first real-time tick. Reset your values and then you are good to go after that.
        Josh P.NinjaTrader Customer Service

        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
        369 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
        572 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