# Placing trail stops? How?

**URL:** <https://forums.collective2.com/t/placing-trail-stops-how/1110>\
**Category:** C2 Software Development\
**Created:** [October 2, 2008, 7:05am UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110 "2008-10-02T07:05:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![WD](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@WD](https://forums.collective2.com/u/WD)\
**Post date:** [October 2, 2008, 7:05am UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/1 "2008-10-02T07:05:26Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![MatthewKlein](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/matthewklein/32/21382_2.png) [@MatthewKlein](https://forums.collective2.com/u/MatthewKlein)\
**Post date:** [October 2, 2008, 8:52am UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/2 "2008-10-02T08:52:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![WD](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@WD](https://forums.collective2.com/u/WD)\
**Post date:** [October 2, 2008, 1:22pm UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/3 "2008-10-02T13:22:36Z")

</div>

I still have a problem with r **eplacing** 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](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](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 ?

---

<div class="post-metadata">

**Author:** ![WD](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@WD](https://forums.collective2.com/u/WD)\
**Post date:** [October 6, 2008, 2:58pm UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/4 "2008-10-06T14:58:02Z")

</div>

anyone?

---

<div class="post-metadata">

**Author:** ![MatthewKlein](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/matthewklein/32/21382_2.png) [@MatthewKlein](https://forums.collective2.com/u/MatthewKlein)\
**Post date:** [October 6, 2008, 2:58pm UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/5 "2008-10-06T14:58:54Z")

</div>

I promise to respond to this by the end of the day. - MK

---

<div class="post-metadata">

**Author:** ![WD](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@WD](https://forums.collective2.com/u/WD)\
**Post date:** [October 6, 2008, 3:07pm UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/6 "2008-10-06T15:07:29Z")

</div>

Many thanks Matthew!  
  
  
  
Just disregard our email from earlier today and share your answer here please.  
  
  
  
Again, thanks.

---

<div class="post-metadata">

**Author:** ![MatthewKlein](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/matthewklein/32/21382_2.png) [@MatthewKlein](https://forums.collective2.com/u/MatthewKlein)\
**Post date:** [October 7, 2008, 1:14am UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/7 "2008-10-07T01:14:18Z")

</div>

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](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](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.

---

<div class="post-metadata">

**Author:** ![WD](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@WD](https://forums.collective2.com/u/WD)\
**Post date:** [October 7, 2008, 3:39am UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/8 "2008-10-07T03:39:33Z")

</div>

Thanks for your answer.  
  
  
  
I’m sure this is going to solve my problem and hopefully that of others too.

---

<div class="post-metadata">

**Author:** ![WD](https://avatars.discourse-cdn.com/v4/letter/w/7bcc69/32.png) [@WD](https://forums.collective2.com/u/WD)\
**Post date:** [October 7, 2008, 6:53am UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/9 "2008-10-07T06:53:50Z")

</div>

BTW, we always have a good laugh with your funny comments and vids. Thanks!  
  
  
  
Martijn & Wouter

---

<div class="post-metadata">

**Author:** ![DuncanMcQueen](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@DuncanMcQueen](https://forums.collective2.com/u/DuncanMcQueen)\
**Post date:** [October 14, 2008, 2:20pm UTC](https://forums.collective2.com/t/placing-trail-stops-how/1110/10 "2008-10-14T14:20:50Z")

</div>

See, Matthew - my nagging you on that xreplace command bore fruit elsewhere!  
  
  
  
I’ll take my $1 Million royalty for it elsewhere 😉
