Our autotrading system here on C2 needs trailing stops & exits to perform like it should. However, we can’t find a command to do so. We can sent out a buy signal together with a stop, but somehow we don’t know how to update that stop after eacht period.
Because trailing stops require real-time access to quote feeds, you will need to manage them yourself by issuing cancel-and-replaces for existing stops. In other words, it is your software’s responsibility to determine what the new stop should be, and then to cancel the old, and submit the new.
I still have a problem with replacing the stop:
Let’s say we have an open position with signalid 123456. And a stop order that is conditional upon that order with signalid = 654321.
This order can be placed like this:
I know how to cancel an order:
http://www.collective2 .com/cgi-perl/signal. mpl?cmd=cancel&signalid=654321&systemid=123&pw=abc
I don’t know how to replace the stop on the existing order with signalid 123456 using the Signal Entry API.
Can you give me an example of that ?
I promise to respond to this by the end of the day. - MK
Many thanks Matthew!
Just disregard our email from earlier today and share your answer here please.
You asked this question a while ago, and I was slow to respond. The reason was that this problem seemed pretty easy to me - suspiciously easy. I couldn’t understand why you were asking such an obvious question.
After all, hadn’t I specifically created a Cancel-And-Replace (xreplace) command in the API a long time ago, just for this purpose? Wasn’t it described perfectly clearly in the documentation?
Well, er, no. Actually, I had added the xreplace command. I just never bothered to describe it in the documentation. Whoops.
So, then, let’s go through it.
First, you place your original order:
Notice that I’m placing an “all-in-one” order: that is, an entry to go long at the market, plus my original stop loss (set at 101.90).
C2 responds with some ugly XML:
<comments>Signal 35584023 accepted for immediate processing.</comments>
You’ll want to parse out the <stoplosssignalid> tag, because you’ll need it when it’s time to change your stop loss.
How do we do it? Well, let’s imagine you want to modify your stop loss to 101.80. You would:
You can see that basically, I’m entering a new STC @ stop 101.80 order… but I’m specifying to first cancel signalid 35584025 (by using the xreplace=35584025 parameter).
<comments>Signal 35584086 accepted for immediate processing.</comments>
Simple, right? All you needed was the ability to read my mind.
Sorry for the gaping hole in the docs. I’ll update them soon.
Thanks for your answer.
I’m sure this is going to solve my problem and hopefully that of others too.
BTW, we always have a good laugh with your funny comments and vids. Thanks!
Martijn & Wouter
See, Matthew - my nagging you on that xreplace command bore fruit elsewhere!
I’ll take my $1 Million royalty for it elsewhere