Your original question title has been updated. You entered a title of "Automatic Trading oco/ bracket" which did not correctly describe what you are trying to accomplish. Automated trading pertains to the automation of order execution in a live market. Whereas you are working with the AddOrder() statement which can only be applied to a Chart Strategy used to back-test trading setups. It can NOT be used to automate any trades on Thinkorswim.
If you are interested in learning to use Chart Strategies for back-testing trading setups on Thinkorswim you will want to review the following videos:
Now let's get to the solution to your request. If you want to simulate the use of an OCO bracket order on Thinkorswim you can add the following built-in strategies to your chart:
Each of these also have an "SX" version for matching with a short entry strategy. Just add those to your charts, select the "offset type" and adjust the "target" parameters as needed. Done. If you want to incorporate these directly into your existing custom Chart Strategy you can examine the code for those built-in profit target and stop loss strategies.
Its very important the rest of our viewers are not mistaken as to how this solution can be applied so that we don't mislead them into believing this solution might be used to automate live trades on Thinkorswim in any way. The only tool used to automate trade execution on Thinkorswim is through the Conditional Order tool. This tool is in no way associated with the AdddOrder() statement used in Chart Strategies. For a complete explanation and demonstration of what is possible for automated trading on Thinkorswim please review the following video: