Please note just by re-arranging the SEQUENCE of the LEGS UP OR DOWN, our requirements will not be fulfilled.
Actually a function should be created at the bottom of all the legs, wherein:
1) ALL SALES ORDER ENTRY SHOULD BE DELAYED BY X SECONDS ( X IS FILLED BY THE USER) so that all buy orders are executed first before executing SALE Orders
2) ALL BUY ORDER EXIT SHOULD BE DELAYED BY Y SECONDS ( Y IS FILLED BY THE USER) so that all sale orders are squared off first before squaring off Buy Orders
This will help the user to get the margin benefit since all the hedges are executed first at the time of ENTRY and
all SALE legs are squared off first at the time of exit.
Please implement this at the earliest.