I have this code in my sys and I want it to run 'perpetually' ... I am using the onorderupdate to manually manage my stops and targets, and found that if I have this following code in 'onbarupdate', it doesn't cancel my stops (most importantly) and targets [not really necessary, but i have it here anyway] until the next bar:
if (Position.MarketPosition == MarketPosition.Flat && stopOrder != null)
{
CancelOrder(targetOrder);
CancelOrder(stopOrder);
stopOrder = null;
targetOrder = null;
}
Is this perfect code to have in OnOrderUpdate() to clear out old junk? If so, how 'often' does onorderupdate() actually run? Is it a perpetual loop based on seconds, or only when an Iorder variable gets changed?
or should I leave it in onBarupdate and put the cancelorder(stopOrder) right in my early exit routines that exist in onBarUpdate immediately after I issue the early sell commands? I figure they are better off in OnOrderUpdate if I elect to use ExitLongLimits that don't immediately filll. As I would not look to be without a stop if I'm in an unexited position.
I just want to post this to check that my understanding of this mechanism is indeed complete ... I am learning by trial and error, visual confirmation of behavior on paper test, and my Output window debug until then.
Comment