I have a strategy that is producing over fills.
The scenario is the following:
- I have an open position
- The strategy has several conditions to exit
- If any of the conditions are met, the strategy flattens the position using market orders using ExitLong() or ExitShort()
I get an overfill error. Looking at the log, I can see that it results in getting two exit orders like one after the other - the first one is ok, the second raises the over fill error.
This happens when two exit conditions turn true almost at the same time.
One thing I don't know, is whether the OnBarUpdate method is re-entrent from a threading perspective. (I.e., can it be called at the same time from two different threads and context switch in the middle.) If not, I can guard against multiple exit calls using a state variable so I wouldn't need to use the unmanaged approach - right?
Thoughts?
Hope this makes sense.
Onn
Comment