1. If NT is disconnected and then reconnects and the setting for strategies is "Keep Running" then I suppose the state (e.g. variables, etc.) of the strategy is preserved but no OnBarUpdate is called for the missing bars (i.e. OnBarUpdate is called until the last bar while NT was still connected and then form the first bar on when it's connected again). But are the data series updated after the reconnect, i.e. would Close[1] in OnBarUpdate after the reconnect refer to the bar before NT was disconnected or would it contain the value of the last "missing" bar? And what about inidcators that the strategy uses? Will they be recalculated or do they skip missing bars also (would certainly lead to strange results)?
2. What if orders were executed while NT was disconnected? Will the events (e.g. OnOrderUpdate) be fired retroactively once NT reconnects and will the status of IOrder objects be updated?
3. What if strategies are set to "Recalculate"? Will the previous state (e.g. saved IOrder objects) be lost once NT reconnects and the strategy is recalculated? And what about events? Will they be fired in the recalculated strategy if an order was executed while disconnected?
4. What happens to open orders when a strategy is recalculated? If the previous state of the strategy is lost then it can't know about open orders which might lead to uncontrolled behaviour.
5. Does the setting "wait until flat before ..." mean that the strategy position has to be flat before orders are submitted live or the account position or both?
6. Is the account position managed separately for each strategy (assuming "immediately submit live..." is set)? E.g. if strategy A is running and both the account and strategy positions are long and if I then start strategy B whose strategy position is flat, the position from strategy A will not be closed?
7. Can you tell me what would happen in the following situations (or correct me if my assumptions are wrong) so that I can understand the behaviour of NT better (SP = strategy position, AP = account position):
Assuming strategies are set to "Recalculate", "wait until flat before ..." is set and using low level order handling functions:
a. NT connected > start strategy > entry signal, submits long order > order is executed > SP=1, AP=1 > connection is lost > exit signal is missed > NT reconnects > strategy is recalculated and sees exit signal > SP=0, AP=1 > new entry signal, submits order (because SP=flat) > order is executed > SP=1, AP=2 > mismatch!
b. NT connected > start strategy > entry signal, submits long order > order is executed > SP=1, AP=1 > connection is lost > NT reconnects > strategy is recalculated > SP=1, AP=1 > exit signal > sell order is not sumbitted live because SP is not flat > SP=0, AP=1 > new entry signal, submits order > order is executed > SP=1, AP=2 > mismatch!
c. NT connected > start strategy > entry signal, submits long order, saves IOrder > connection is lost > entry order executed > NT reconnects > strategy is recalculated > IOrder still saved? OnOrderUpdate fired (e.g. to place a stop loss order)?
d. NT connected > start strategy > entry signal, submits long order > order is executed > OnOrderUpdate places stop loss order (not using the SetStopLoss function but just by placing a normal stop sell order) and saves it > connection is lost > NT reconnects > strategy is recalculated > exit signal, sell order submitted > sell order executed > can strategy still know about the stop loss order (so that it can be cancelled) or will it be executed once the stop price is hit leading to SP=0 and AP=-1?
Assuming strategies are set to "Recalculate", "immediately submit live..." is set and using low level order handling functions:
e. NT connected > start strategy > entry signal, submits long order > order is executed > SP=1, AP=1 > connection is lost > exit signal is missed > NT reconnects > strategy is recalculated and sees exit signal > SP=0, AP=1 > sell market order is generated to sync AP to SP?
f. NT connected > start strategy > entry signal, submits long order > order is executed > OnOrderUpdate places stop loss order (not using the SetStopLoss function but just by placing a normal stop sell order) and saves it > SP=1, AP=1 > connection is lost > exit signal is missed > NT reconnects > strategy is recalculated and sees exit signal > SP=0, AP=1 > sell market order is generated to sync AP to SP? (is OnOrderUpdate fired?) > stop loss order still active (leads to AP=-1 once the stop price is hit, stop loss order should have been cancelled in OnOrderUpdate when exit order is executed)?
Basically I want my strategies to behave as in case e but I want to avoid the following scenario:
g. NT connected > AP=0 > start strategy > generates historical buy order > SP=1 > buy market order triggered to sync AP to SP > market is being "chased"
I could prevent my strategy from placing entry orders on historical bars but that would then cause this:
h. NT connected > start strategy > entry signal, submits long order > order is executed > SP=1, AP=1 > connection is lost > NT reconnects > strategy is recalculated > no entry order on historical bars > SP=0, AP=1 > position closed to sync AP to SP
I.e. postitions would always be closed once NT is disconnected and then reconnects.
8. Is there any way I can enumerate open orders associated with a strategy (even if they were generated by a previous strategy instance)?
9. Can I somehow access the account position in a strategy (to check if it matches the strategy position)?
10. Could I save data (e.g. IOrder objects) in some global (static) variables once NT is disconnected (using OnConnectionStatus) and then load these values in the new (recalculated) strategy instance? Would the IOrder objects still be valid?
I hope you can clarify and have suggestions for these problems.
Comment