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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        55 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        142 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        160 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        96 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        276 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X