Placing trail stops? How?

Hi,



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.



Thank you!

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:



http://www.collective2.com/cgi-perl/signal. mpl?cmd=signal&

systemid=1234&pw=abcd&instrument=forex&action=BTO&quant=1&

symbol=eurusd&duration=GTC&stoploss=1.3



I know how to cancel an order:



http://www.collective2 .com/cgi-perl/signal. mpl?cmd=cancel&signalid=654321&systemid=123&pw=abc



That’s easy.



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 ?







anyone?

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.



Again, thanks.



Wouter:



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:



http://www.collective2.com/cgi-perl/signal.mpl?cmd=signal&systemid=12345

&pw=mypassword&instrument=forex&action=BTO&quant=1&symbol=USDJPY

&duration=GTC&stoploss=101.90



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:



<collective2>

<ack>Signal Received</ack>

<status>OK</status>

<signalid>35584023</signalid>

<comments>Signal 35584023 accepted for immediate processing.</comments>

<oca></oca>

<delay></delay>

<stoplosssignalid>35584025</stoplosssignalid>

</collective2>





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:



http://www.collective2.com/cgi-perl/signal200.mpl?cmd=signal&systemid=12345

&pw=mypassword&instrument=forex&action=STC&quant=1&symbol=eurusd

&duration=GTC&xreplace=35584025&stop=101.80



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).



C2 responds:



<collective2>

<ack>Signal Received</ack>

<status>OK</status>

<signalid>35584086</signalid>

<comments>Signal 35584086 accepted for immediate processing.</comments>

<oca></oca>

<delay></delay>

</collective2>





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 :wink: