PDA

View Full Version : Reset variables on reconnect


poseidon_sthlm
03-01-2010, 03:24 AM
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.

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);
}

NinjaTrader_Bertrand
03-01-2010, 09:55 AM
poseidon_sthlm, please reset them directly in OnConnectionStatus() and not in the OnBarUpdate().

poseidon_sthlm
03-01-2010, 01:17 PM
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?

NinjaTrader_Josh
03-01-2010, 03:48 PM
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.