The exit is as follows
if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Ticks, Close[0]) >= Target) { ExitLong(Convert.ToInt32(Contracts)); ExitShort(Convert.ToInt32(Contracts)); Waiting = false; //after ghost target hit, setting waiting state = false = disarmed state, doesn't allow for unnecessary extra entries after exit. }
My question is this.
1) While running the strategy and editing code for different strategies in the code editor, does compiling code affect the currently running strategies? I've noticed this happen when I'm editing backup versions of strategies then recompiling them.
When the strategy is supposed to exit with the code written above, the orders would get out of sync.
This error is what happens in the execution window (for example a long position closing):
E/X: Exit
Position: - (denotes flat position)
Name: Sell
At the same time, this happens as a result of the wrong execution
E/X: Entry
Position: 1S (denotes short position)
Name: Sell
The correct outcome should be as follows.
E/X: Exit
Position: - (denotes flat position)
Name: Close Position
Then the position waits flat until a new signal triggers another trade.
Given I'm trading this live, could there be an error or delay when the market order gets sent out to the exchange? The correct outcome should be just "sell to close".
I'm deducing that NT;
- sends out 2 sell market orders that are out of sync one should be just "sell to close" but gets assigned as a sell short order and the sell to close becomes "1S" or a short position that shouldn't exist.
- I notice this because I keep an eye on the strategies tab as the take profit happens and the sync becomes false due to the unnecessary extra short position in this case. Then I have to right-click and synchronize the strategy and it closes the erroneous position.
Is there a way I can code something that checks the current position if not flat and forces a synchronization?
For example:
if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Ticks, Close[0]) >= Target) { ExitLong(Convert.ToInt32(Contracts)); ExitShort(Convert.ToInt32(Contracts)); Waiting = false; //after ghost target hit, setting waiting state = false = disarmed state, doesn't allow for unnecessary extra entries after exit. [B]Line of code that: 1 checks account if long/short and forces it to synchronize and go flat as the strategy position, is there a Synchronize command I can put in after the 3 previous lines are executed just to make sure that the account is in SYNC at all times so I don't have to check the strategy window and re-enable the strategy if it goes out of sync?[/B] }
I prefer not to use the typical pending take profit orders as a means of exit since at times they either don't get filled, I'd rather get out at the market with guaranteed execution.
Is there a way I can improve the exit code above and add an account synchronize command as I proposed in the bold section? I searched if such a command exists in the help guide, I presume there has to be a command that can be called to have the same effect as right-clicking in the strategies window and selecting "Synchronize all Strategies".
Thanks in advance for your assistance.
Comment