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);
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Reset variables on reconnect
Collapse
X
-
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:Tags: None
-
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
-
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
656 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
371 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
579 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment