jcl,

Suppose new functions were defined, setLongPosition(), setShortPosition(), and flatten(). To be used with NFA plugins only.

What it will do is guarantee that the broker plugin will do its best to force a position upon both the virtual and pool trades. This is to stop runaway trades.

It will follow these steps:
1) Exit all virtual trades, but send nothing to the broker yet.
2) If setting a long or short position, create a single long or short virtual trade to replace the previous trades. For flatten(), do nothing here. Still send nothing to the broker.
3) Check GET_POSITION to confirm actual position.
4) If GET_POSITION is not equal to the desired position, a pool order will be submitted to compensate.
5) When all is done, the desired position, broker position, virtual trades, virtual position, pool trades, and pool position will all be synchronized.

It is critical that all of the above steps take place **instantly** rather than at the end of run().