MIH8
- ago
Hi all,

can someone enlighten me on how to create an order with auto place that leads to an order that has two attached orders, take profit and stop loss.

Is the OCO option required for this?

Are there any differences when triggering this behavior from the Strategy Manager / Order Manager / Quotes and Price Triggers via the Auto-Place function?

Are there alternatives?

Thank you very much for support.
0
943
Solved
23 Replies

Reply

Bookmark

Sort
Cone8
 ( 4.72% )
- ago
#1
QUOTE:
how to create an order with auto place that leads to an order that has two attached orders, take profit and stop loss.
Just create a strategy with the two exit orders.

QUOTE:
Is the OCO option required for this?
No, but if you want OCO functionality while trading live, then you should check this.

QUOTE:
Are there any differences when triggering this behavior from the Strategy Manager / Order Manager / Quotes and Price Triggers via the Auto-Place function?
It would be hard to get a OCO to happen from Quotes and Triggers because you're triggering at a specific price. To enter an OCO manually in the Order Manager, stage both orders, select both, and Place at the same time.

NOTE!
OCO only works for orders whose prices do not change. If the strategy changes stop/limit price levels, at least for now, do not check the OCO option. (We're working on this, but brokers treat this replace operation differently.)
0
Best Answer
MIH8
- ago
#2
Hi Cone.



If i understand you correctly i only need to set the TP and SL like in the picture for example. I disabled the OCO option for now. I only checked it because the way you described does not seem to work. (or i am doing sth. wrong).

Well, there are no attached orders in the TWS environment.

What i can see in the order manager, sorted by symbols are things like that.





I selected the three relevant types sell/stop, sell/limit and buy/limit and tried to place the orders then.
0
Cone8
 ( 4.72% )
- ago
#3
In your opinion, what isn't working?

From what you're showing, it looks to me like you Staged a Buy at Limit order that was never placed. So the first question is, does your account hold a position in ABG?

When the sell orders were placed, Portfolio Sync could not find a matching ABG position, so the orders Errored out.

Incidentally, if you're trading with % of Equity sizing, you should check the Portfolio Sync option to use your account value for trading signals.
1
MIH8
- ago
#4
I have no clue for now. I will reset everything and check the process step by step.

1. The portfolio sync



2. The strategy manager

I closed everything and setup a new strategy in a new strategy window.
I activated it and ran it. I got a result and sorted it by symbol



3. I canceled all trades. I canceled all open orders in the api view.



4. I choosed a symbol from the list in the strategy monitor



What is already interesting is that at this point, for the first symbol there is only a buy entry. For the second symbol there are sells but not a buy. Now i picked the third symbol "CAR" to continue. I marked the three relevant orders and staged them to the order manager. I already checked what happens if i place them directly. Well, only the buy was placed. I cleared the api interface again.

There is another point that looks strange to me. If you look at the picture, the quantities are already not what i would expect. They differ from the buy.



5. Looking into the Order Manager



Selecting the three entries and placing them works from this point, but not as expected. The quantities are one thing. Another thing is that the stop was executed while i was making the snapshots. At least i can say, that placing the orders from the strategy manager and the order manager behave somehow different from what i can see.







I hope this information can help.

Finally i use the paper trading account where about 100K cash is available. The strategy setup is 10K and %-ofEquity for Pos-Sizing. When you update because of the broker-reported account value for % of equity Position Size, do you also update the the child orders (quantities finally)?
0
Cone8
 ( 4.72% )
- ago
#5
QUOTE:
What is already interesting is that at this point, for the first symbol there is only a buy entry. For the second symbol there are sells but not a buy.

This is your strategy's logic. It is executing hypothetically. In the first case, there is no position, so it's doing entry logic. In the second case, hypothetically it's holding a position, so it running the exit logic. I hope that makes sense!

Now something I see interesting is that the strategy is signaling a Market order exit at the same time as the stop/limit orders, presumably for the same Position. In a coded C# strategy, you'd never do that and I'm going to find out if we can prevent from occurring in a Block Strategy too.

QUOTE:
There is another point that looks strange to me. If you look at the picture, the quantities are already not what i would expect. They differ from the buy.

We're talking about the difference between Buy 431 and Sell 5? Apparently you have a 5-share position that PortfolioSync is syncing to. 431 is discussed at the end (It seems wrong from them information you're telling me).

QUOTE:
Another thing is that the stop was executed while i was making the snapshots.

Why was that a problem? The broker executed the stop and we got the filled status.

However, I don't understand the sequence of images since the Stop order was filled at 275.37 and then in the next image the order is active.

QUOTE:
The strategy setup is 10K and %-ofEquity for Pos-Sizing.

The 431 shares is wrong then. The broker sizing works for live accounts for sure (I do this every day), but I've never used the Paper Account, so maybe the problem is there.

I'll try to work with a Paper Account since this is an unknown. We've only worked with live accounts using the API.
0
MIH8
- ago
#6
Hi Cone,

i looked at the quantities of the sell positions. In the picture are "5" although the quantity for the buy order is "431". Where do you see the quantity of 431 beside the buy order?

And how can i sell something what i did not bought before.
Is here a misunderstanding? I want to implement a stop loss after a limit order was executed before. (as child order so to say).

Yes, i messed minor things up (eg the second picture which is not the one which shows the list sorted by symbols). And maybe i have a lack of understanding.

FInally i don't get the result i would like to have and there are things, i mentioned, that are confusing me right now. I am sure we will clarify these.

Thanks so far, I come back tomorrow.

Edit:
QUOTE:
This is your strategy's logic. It is executing hypothetically. In the first case, there is no position, so it's doing entry logic. In the second case, hypothetically it's holding a position, so it running the exit logic. I hope that makes sense!


I guess i understand what you mean. It is a simple signal that would be used if there were an existing trade.

But honestly, this makes no sense to me. Theoretically, there can be a signal for the exit, but you can not trigger a stop order based on this signal. For this, there must already be an executed/corresponding order.

These hypthetic signals may also be interesting for analysis, but in the order manager I don't really see the point for an exit signal without an entry or a running trade.

On the other hand, buy signals and also their execution are independent of potential exit signals/actions of course.
0
MIH8
- ago
#7
By the way. The TWS build which i use is 10.15.1d.

In the meantime i will check what is happening in TWS and if the order really was executed. It did not appear in the portfolio. I will report later in the day.

EDIT:
I had a short look. In my portfolio CAR is listed with a negative position size. (-10).
It is possible that by fiddeling around yesterday I performed the operation twice. However, it was not meant that way.
0
Cone8
 ( 4.72% )
- ago
#8
QUOTE:
Where do you see the quantity of 431 beside the buy order?

Nowhere. The buy order is 431 in WL and TWS. I can't explain the 431, but the order is based on $125K - and I cannot independently verify your settings.

QUOTE:
And how can i sell something what i did not bought before. Is here a misunderstanding?
Yes, you misunderstand how the system works (although it sounds like you understand now). Again, the strategy runs hypothetically and is holding a position based on the data you gave it. This should not be a problem when using Portfolio Sync because Wealth-Lab won't place the order since it can't find a matching position in the account.
0
MIH8
- ago
#9
Well, i will provide any information you need to solve the puzzle.

However, i think one problem are the quantities. Already in the strategy manager before placing the orders it looks like that for many entries in the list.



The settings for the sync are still like i mentioned it in the previous post.

Am i right when i say that a sell order can only attached to a parent order if quantity is the same? Are there other conditions that are mandatory if you want to place it as attached order?

Just to show you how the settings for the position size and the TWS cash status of the trading paper account looks like. May currency be a problem?





Looking at the picture i ask myself if "max open per symbol" is sensitive for the order type?
0
MIH8
- ago
#10
I disabled the sync now. The quantities seem to be fine then.
So at least one thing relates to the account sync.



There are still symbols where the quantities of the buy is not identical to the sell signals. Even if it is intended behaviour this will not help to go long and attach a stop order to it (TP,SL).
0
Cone8
 ( 4.72% )
- ago
#11
And, there's the 125,000 - it's 12.5% of the 1M in your account. The 431 shares were correct when the Portfolio Sync option for using the Broker Account Value is enabled.
Let's agree on this first and then move on to the next perceived issue.
0
MIH8
- ago
#12
Ok, that makes sense. Somehow in my mind it was 100K not 1M. You are right, that sounds reasonable.
0
Cone8
 ( 4.72% )
- ago
#13
And so that it's clear, the synchronization for positions in your account occurs when you Stage or Place the signals in the Order Manager.



Did we cover everything, or do you still have some issues?
0
MIH8
- ago
#14
That does not work here. Most of the time i get a picture like this. Sometimes i can catch a sell order that has a staged status for a short time and is canceled then.
I am not sure what i can do in a different way. The account sync is enabled. I checked it twice.

0
MIH8
- ago
#15
Ok, i think i get close to a solution.





The error for the buy occured because of a limit in the TWS settings. I can manage that. To see the order and the attached ones was possible due to changing the settings. (It is about placing the order not only to the regular trading hours)



At this point i would need to have the attached orders to be placed with the same quantities as the parent order.
0
Cone8
 ( 4.72% )
- ago
#16
Does the Paper account have 16 shares of ASH?

The order screenshots are fine, but what does Wealth-Lab think is in the Account? Use the WL Accounts tool (Ctrl+T) to see that.
0
MIH8
- ago
#17
Well, the orders have been placed in TWS but they are not attached ones. Attached ones look like this.



I just realize your last reply. It is an empty account. Everything cleaned up.
I need to come back later. As always, many thanks for now!

And for ASH quantities, they have been the same as in the order manager.
I already cleaned it up.
0
MIH8
- ago
#18
I was not able to focus on the subject yesterday and i have a couple of questions.

Although Cone advices are very helpful, i was not able to follow the instructions very long because the behaviour (for whatever reason) on my side is different. Already the sync behaviour is different looking at the strategy and order manager. I am sure that there is a plausibel reason, that can be found at some point.

My goal

It is pretty obvious that a want to setup a full automated process. For this everything needs to run absolutely properly. So i had the following ideas in mind (to start with)

scenario 1

1. place a limit order with WL in the TWS
2. using attached sell orders (TP,SL) set by TWS automatically which are configured in the preferences of TWS
3. close a filled position 100% if a condition was met

scenario 2

1. place a limit order with WL in the TWS
2. attach sell orders (TW,SL) by WL to this parent order
3. close a filled position 100% if a condition was met

scenario 3
1. place a limit order with WL in the TWS
2. place a stop order with WL (as TP) in the TWS
3. place a stop order with WL (as SL) in the TWS
4. close/cancel the orders (sync WL+TWS) after the TP or SL order was triggered.

In the first two scenarios the sell orders are linked to a parent order. If i would be able to get it to work this would be a good start.

The third scenario seems the way to go with WL and may be the most powerful/flexible way in the end. In this case stop orders can be placed for different kind of conditions. But at the moment i don't see how the orders are linked to each other.

Questions

There are some (potential) interactions between WL and TWS which are not transparent for me.

1. Thinking of the first scenario as example. What are typical conflicts between the preferences (Orders, Stocks, API) in TWS and WL order management.

2. Can someone explain to me how the sync process between WL and TWS works for the inteded simple scenario given above? (Just ignoring issues with preferences or technical problems). Not only the sync mechanism but how are orders linked to each other. I think that is the most important point for me at the moment that i need to understand.

3. However the sync mechanism works. What happens if one software component needs to be restarted for some reason?

4. Can someone point me to tutorial, youtube video or any other source that i watch,
to setup a full automated for the given scenarios.

Status - lastest test

Starting with a cleaned up TWS (no open trades, no placed orders) i did the following.
I ran the strategy manger. I stage the signals and they occure in the order manager.
From there i place the orders. There is no difference by doing it manually or with Auto-Place. Being at TWS now, at some point the placed orders were filled and the trades were running. Now i have more than 80 open positions in the portfolio. Not a single one was closed based on the idea above. This is completely out of control. At least the portfolio is +2.5%, lol. Finally i shut down my computer yesterday and before, headless as i was, i removed the order block in the order manager. No clue how TWS and WL get in sync in such a case.

Of course there are many things i do not know about WL, TWS and other things. On the other side, there are not many things that can be done wrong. I really would like to see how a simple scenario like above is working for someone.

Are there other community members who are interested in the topic and can provide some help? Or are the signals used only for manual trading or semi-automatic trading by others?

EDIT:
I found the youtube video in your channel "3 Steps to Auto-Trade with Interactive Brokers". So, placing orders automatically is not the issue. It is how the placed orders are managed from this point on. Or is my problem that auto trading is only about placing orders and managing them manually afterwards?
0
MIH8
- ago
#19
1. Coming back to some concrete issues. Somthing is wrong with the quantities and the sync mechanism. Now, i started a strategy, placed the orders from there to the order manager. I changed the position sizing from %-equity to shares. See what happens then, left are the strategy numbers, right are the ones from the order manager. Why are the quantities changed in the order manager for the shares? Compared to the cases before the sell orders are updated not the buy order. When using the %-equity in position sizing it was the other way around.



2. Thinking of my described scenarios, I think a bracket order would be one way for a solution. I think you will correct me if i am wrong. If you know another way to create a triple like limit order with a high-side sell limit order and a low-side sell stop order, please let me know.
0
MIH8
- ago
#20
I am talking of

https://interactivebrokers.github.io/tws-api/bracket_order.html
https://interactivebrokers.github.io/tws-api/order_submission.html#order_attach
0
Cone8
 ( 4.72% )
- ago
#21
1. Please notic the SYNC icons to the left of the upside-down red Sell triangles. This means that you chose for all the shares that are held the account be sync'd for exits. The account is holding 35 shares of BCC and 7,837 shares of ACT.

If you don't want to sync and let the strategy run only with the hypothetical shares it's trading, then don't select the Portfolio Sync Trading Preferences! In that case, you'll get 100 share entries and 100 share exits (because that's the sizing your chose), no matter what's in the account.

2. A bracket order is just a stop and limit order placed at the same time. If you want OCO broker functionality, then select the OCO trading preference.

Now, you keep talking about a parent order. That concept doesn't exist in a strategy. The entry and exit logic of a strategy is separate. However, in a C# Strategy (not blocks) you can also program same-bar exits. In other words, when the entry order fills, you can place a stop and limit order using AssignAutoStopTargetPrices - again only in a C# programmed strategy.
0
MIH8
- ago
#22
Although or just because the portfolio is frozen today I could clarify a point for me that was not visible yesterday. As I reported, I first completely reset the portfolio. No open positions and no open orders.

Now yesterday I could only see the placed orders in the API tab. Of course, these were not filled immediately. A few hours later, all were in the portfolio, so as open positions available.

When I now tried settings in WL, such as the quantities of shares in the position sizing I was again confused and wondered how the sell quantities came about (in WL). Now I can understand that the quantities are synced based on the open positions. I couldn't see that yesterday because I didn't have any at that time.

So that's good, although I still don't know what happens when a stop order is executed and what then happens to the associated orders. Are these then automatically cancelled? I need to check the OCO for that, am i correct?
Would it allow another exit order (beside TP, SL) and perform the same cleanup function.

Well, I can't check it now, but I think that when a sell occurs, the alternative orders are also cleaned up. Once the market is open, we can see what happens.

Hoping this works in my favor I am still wondering how the placed orders that are not filled immediately (and there is no open position) should be handled properly. Can the sell orders be executed without an open position, so you have a negative amount, or how do you prevent that?
0
MIH8
- ago
#23
Hello.

Finally, everything works as it should.

To be fair, I would like to say here that the issues raised were almost entirely due to my lack of experience with WL and TWS. In the course of the last few days, I was able to fill most of the knowledge gaps in the given context.

Specifically on the OCO orders, I would like to leave a few comments that I was able to observe. However, I did not then investigate these further, as they no longer have any practical relevance for me. At least the following points can be kept in mind, even if I should not have treated something correctly in the following two points. These are notes from last week.

* the number of shares must be manually adjusted in the orders sent as a group, since the number for the individual orders must be identical. Otherwise, no group is formed in TWS.

* Market and limit orders behave differently. This can be seen for example when a limit order 1% below close is sent and additionally a stop (SL) and limit (TP) order. It can happen that the SL is filled and this is probably not intended by the user.

In the context of SL and TP I would not use the OCO now.
This is ultimately not the basic idea of the OCO.

For manual and semi-automatic trading OCO works perfectly using it in a useful context.

Thank you for your patience and help.
0

Reply

Bookmark

Sort