I have a strategy that is designed to close a trade and immediately enter the opposite trade if the opposite signal is detected. The issue I am having is that the strategy is also using an exit criteria to get out of a trade instead of a stop loss, so when an opposite trade is detected, the system will 1. close the original position correctly, 2. enter the opposite direction correctly but also 3. try to exit the position which no longer exists incorrectly, causing a doubling up of contracts in the opposite direction since there is no offset for the exit. This will also generate the error "Cancellation rejected by the Order Management System - Order is complete. Further cancellations on this order may lead to logoff/disable" which will sometimes turn the strategy off completely.
I have tried to put checks in place to check for the below logic to avoid the strategy submitting the exit execution since the close position already accomplishes that. Below is an example of the strategy going from a long position to a short position:
Once the long is closed and the opposite short is entered:
1. Check if the strategy is already in a short and if so, set checkshort to true.
2. For the exit long criteria, checkshort must = false to execute which I was hoping would not allow this set to place a sell order if the strategy has already closed the long position with a sell order.
This should only allow 2 orders to be submitted - the close of the long position and the opening of the short entry. However looking at the log this doesn't work as it seems that the strategy first submits all 3 orders (close long, enter short, exit long) from the strategy before the executions actually get submitted, so my checks are bypassed because the strategy does not detect being in a position when all 3 orders are initialized. The position executions happen after all 3 orders are submitted.
So I assume this leaves me with needing to create a check that detects if the "close position" order has already been submitted. If so, then the strategy needs to not submit the "exit long" order. I don't see any option for this in the strategy builder and was wondering if this can be accomplished within the script editor?
I have the log with the order of events for your reference but this post will not let me upload a .xlsx file so please advise which format I can upload the log in for you to review.
Thank you,
Jim
Comment