Patch committed to svn 697.<div><br></div><div>Let me know if there are still issues.</div><div><br></div><div>Garrett</div><div><br></div><div>Now, with your original test script and data (which are attached for ease of reference) you can get this:</div>
<div><br></div><div><div>> ob$FXportf$EURUSD</div><div> Order.Qty Order.Price Order.Type Order.Side Order.Threshold Order.Status Order.StatusTime Order.Set Txn.Fees</div><div>1999-01-04 00:00:00 "0" NA "init" "long" "0" "closed" "1999-01-04" "1" "0" </div>
<div>2010-11-03 11:00:00 "-1000" "1.3903" "stoplimit" "long" "-0.02" "closed" "2010-11-08 02:00:00" NA "0" </div>
<div>2010-11-03 11:00:00 "1000" "1.4103" "market" "long" NA "closed" "2010-11-03 15:00:00" NA "0" </div><div>2010-11-03 15:00:00 "-1000" "1.3923" "stoplimit" "long" "-0.02" "closed" "2010-11-07 18:00:00" NA "0" </div>
<div>2010-11-03 15:00:00 "1000" "1.4123" "market" "long" NA "closed" "2010-11-03 19:00:00" NA "0" </div><div>2010-11-03 19:00:00 "-1000" "1.3923" "stoplimit" "long" "-0.02" "closed" "2010-11-07 18:00:00" NA "0" </div>
<div>2010-11-03 19:00:00 "1000" "1.4123" "market" "long" NA "closed" "2010-11-03 23:00:00" NA "0" </div><div>2010-11-03 23:00:00 "-1000" "1.3935" "stoplimit" "long" "-0.02" "closed" "2010-11-07 18:00:00" NA "0" </div>
<div>2010-11-03 23:00:00 "1000" "1.4135" "market" "long" NA "closed" "2010-11-04 03:00:00" NA "0" </div><div>2010-11-04 03:00:00 "-1000" "1.4025" "stoplimit" "long" "-0.02" "closed" "2010-11-05 11:00:00" NA "0" </div>
<div>2010-11-04 03:00:00 "1000" "1.4225" "market" "long" NA "closed" "2010-11-04 07:00:00" NA "0" </div><div>2010-11-04 07:00:00 "-1000" "1.4052" "stoplimit" "long" "-0.02" "closed" "2010-11-05 07:00:00" NA "0" </div>
<div>2010-11-04 07:00:00 "1000" "1.4252" "market" "long" NA "closed" "2010-11-04 11:00:00" NA "0" </div><div>2010-11-04 11:00:00 "-1000" "1.4008" "stoplimit" "long" "-0.02" "closed" "2010-11-07 18:00:00" NA "0" </div>
<div>2010-11-04 11:00:00 "1000" "1.4208" "market" "long" NA "closed" "2010-11-04 15:00:00" NA "0" </div><div>2010-11-04 15:00:00 "-1000" "1.4012" "stoplimit" "long" "-0.02" "closed" "2010-11-07 18:00:00" NA "0" </div>
<div>2010-11-04 15:00:00 "1000" "1.4212" "market" "long" NA "closed" "2010-11-04 19:00:00" NA "0" </div><div>2010-11-04 19:00:00 "-1000" "1.4009" "stoplimit" "long" "-0.02" "closed" "2010-11-07 18:00:00" NA "0" </div>
<div>2010-11-04 19:00:00 "1000" "1.4209" "market" "long" NA "closed" "2010-11-04 23:00:00" NA "0" </div><div>2010-11-04 23:00:00 "-1000" "1.3985" "stoplimit" "long" "-0.02" "closed" "2010-11-07 18:00:00" NA "0" </div>
<div>2010-11-04 23:00:00 "1000" "1.4185" "market" "long" NA "closed" "2010-11-05 03:00:00" NA "0" </div><div>2010-11-05 03:00:00 "-1000" "1.3901" "stoplimit" "long" "-0.02" "closed" "2010-11-08 02:00:00" NA "0" </div>
<div>2010-11-05 03:00:00 "1000" "1.4101" "market" "long" NA "closed" "2010-11-05 07:00:00" NA "0" </div><div>> getPortfolio("FXportf")$symbols$EURUSD$txn</div>
<div> Txn.Qty Txn.Price Txn.Value Txn.Avg.Cost Pos.Qty Pos.Avg.Cost <a href="http://Gross.Txn.Realized.PL">Gross.Txn.Realized.PL</a> Txn.Fees <a href="http://Net.Txn.Realized.PL">Net.Txn.Realized.PL</a> Con.Mult</div>
<div>1999-01-04 00:00:00 0 0.0000 0.0 0.0000 0 0.000000 0.00000 0 0.00000 0</div><div>2010-11-03 15:00:00 1000 1.4123 1412.3 1.4123 1000 1.412300 0.00000 0 0.00000 1</div>
<div>2010-11-03 19:00:00 1000 1.4123 1412.3 1.4123 2000 1.412300 0.00000 0 0.00000 1</div><div>2010-11-03 23:00:00 1000 1.4135 1413.5 1.4135 3000 1.412700 0.00000 0 0.00000 1</div>
<div>2010-11-04 03:00:00 1000 1.4225 1422.5 1.4225 4000 1.415150 0.00000 0 0.00000 1</div><div>2010-11-04 07:00:00 1000 1.4252 1425.2 1.4252 5000 1.417160 0.00000 0 0.00000 1</div>
<div>2010-11-04 11:00:00 1000 1.4208 1420.8 1.4208 6000 1.417767 0.00000 0 0.00000 1</div><div>2010-11-04 15:00:00 1000 1.4212 1421.2 1.4212 7000 1.418257 0.00000 0 0.00000 1</div>
<div>2010-11-04 19:00:00 1000 1.4209 1420.9 1.4209 8000 1.418588 0.00000 0 0.00000 1</div><div>2010-11-04 23:00:00 1000 1.4185 1418.5 1.4185 9000 1.418578 0.00000 0 0.00000 1</div>
<div>2010-11-05 03:00:00 1000 1.4101 1410.1 1.4101 10000 1.417730 0.00000 0 0.00000 1</div><div>2010-11-05 07:00:00 -1000 1.4052 -1405.2 1.4052 9000 1.419122 -12.53000 0 -12.53000 1</div>
<div>2010-11-05 07:00:00 1000 1.4100 1410.0 1.4100 10000 1.418210 0.00000 0 0.00000 1</div><div>2010-11-05 11:00:00 -1000 1.4025 -1402.5 1.4025 9000 1.419956 -15.71000 0 -15.71000 1</div>
<div>2010-11-07 18:00:00 -1000 1.3923 -1392.3 1.3923 8000 1.423412 -27.65556 0 -27.65556 1</div><div>2010-11-07 18:00:00 -1000 1.3923 -1392.3 1.3923 7000 1.427857 -31.11250 0 -31.11250 1</div>
<div>2010-11-07 18:00:00 -1000 1.3935 -1393.5 1.3935 6000 1.433583 -34.35714 0 -34.35714 1</div><div>2010-11-07 18:00:00 -1000 1.4008 -1400.8 1.4008 5000 1.440140 -32.78333 0 -32.78333 1</div>
<div>2010-11-07 18:00:00 -1000 1.4012 -1401.2 1.4012 4000 1.449875 -38.94000 0 -38.94000 1</div><div>2010-11-07 18:00:00 -1000 1.4009 -1400.9 1.4009 3000 1.466200 -48.97500 0 -48.97500 1</div>
<div>2010-11-07 18:00:00 -1000 1.3985 -1398.5 1.3985 2000 1.500050 -67.70000 0 -67.70000 1</div><div>2010-11-08 02:00:00 -1000 1.3903 -1390.3 1.3903 1000 1.609800 -109.75000 0 -109.75000 1</div>
<div>2010-11-08 02:00:00 -1000 1.3901 -1390.1 1.3901 0 0.000000 -219.70000 0 -219.70000 1</div><div>> </div></div><div><br></div><div><br><br><div class="gmail_quote">
On Fri, Jul 22, 2011 at 12:13 PM, G See <span dir="ltr"><<a href="mailto:gsee000@gmail.com">gsee000@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I was wondering why you thought the bug I fixed had to do with stoplimits.<div><br></div><div>I think I understand the problem now. I'll take a look.<br><br><div class="gmail_quote"><div><div></div><div class="h5">On Fri, Jul 22, 2011 at 11:49 AM, microlino <span dir="ltr"><<a href="mailto:h.stegmann@onlinehome.de" target="_blank">h.stegmann@onlinehome.de</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5"><div>Thank you, Garrett!<br>
<br>
However, unfortunately, it still does not work... The result is not<br>
different from the original version.<br>
<br>
As you can see from the orderbook below, a buy order at Close price is<br>
placed whenever the signal is TRUE, i.e. after every bar that closes >1.41.<br>
Simultaneously, a stoplimit order is placed along with every buy order at<br>
the buy price -0.02. So far, so good.<br>
<br>
What I expect is that every stoplimit order will be closed later through the<br>
provided example data set, as price falls further. However, only one of the<br>
stoplimit orders is closed, I have highlighted it below. It seems that the<br>
stoplimits are closed only if (price < buyprice - 0.02) AND (signal ==<br>
TRUE). You can easily see this logic in my example if you use a buy<br>
threshold lower than 1.41.<br>
<br>
Closing of a simple stoplimit should be triggered by price only, at least<br>
this is what I think it should do. Are stoplimit orders defined differently<br>
in quantstrat, so I need to code another signal that controls the stoplimit<br>
orders separately, somehow?<br>
<br>
Heiko<br>
<br>
Index Order.Qty Order.Price Order.Type Order.Side Order.Threshold<br>
Order.Status Order.StatusTime Order.Set Txn.Fees<br>
1999-01-04 00:00:00 0 NA init long 0 closed 1999-01-04 1 0<br>
2010-11-03 17:00:00 -1000 1.3903 stoplimit long -0.02 open NA NA 0<br>
</div>2010-11-03 17:00:00 1000 1.4103 market long NA closed 2010-11-03 21:00:00 NA<br>
0<br>
<div>2010-11-03 21:00:00 -1000 1.3923 stoplimit long -0.02 open NA NA 0<br>
</div>2010-11-03 21:00:00 1000 1.4123 market long NA closed 2010-11-04 01:00:00 NA<br>
0<br>
2010-11-04 01:00:00 -1000 1.3923 stoplimit long -0.02 open NA NA 0<br>
<div>2010-11-04 01:00:00 1000 1.4123 market long NA closed 2010-11-04 05:00:00 NA<br>
0<br>
2010-11-04 05:00:00 -1000 1.3935 stoplimit long -0.02 open NA NA 0<br>
2010-11-04 05:00:00 1000 1.4135 market long NA closed 2010-11-04 09:00:00 NA<br>
0<br>
2010-11-04 09:00:00 -1000 1.4025 stoplimit long -0.02 open NA NA 0<br>
2010-11-04 09:00:00 1000 1.4225 market long NA closed 2010-11-04 13:00:00 NA<br>
0<br>
*2010-11-04 13:00:00 -1000 1.4052 stoplimit long -0.02 closed 2010-11-05<br>
13:00:00 NA 0*<br>
2010-11-04 13:00:00 1000 1.4252 market long NA closed 2010-11-04 17:00:00 NA<br>
0<br>
2010-11-04 17:00:00 -1000 1.4008 stoplimit long -0.02 open NA NA 0<br>
2010-11-04 17:00:00 1000 1.4208 market long NA closed 2010-11-04 21:00:00 NA<br>
0<br>
2010-11-04 21:00:00 -1000 1.4012 stoplimit long -0.02 open NA NA 0<br>
</div>2010-11-04 21:00:00 1000 1.4212 market long NA closed 2010-11-05 01:00:00 NA<br>
0<br>
<div>2010-11-05 01:00:00 -1000 1.4009 stoplimit long -0.02 open NA NA 0<br>
</div>2010-11-05 01:00:00 1000 1.4209 market long NA closed 2010-11-05 05:00:00 NA<br>
0<br>
<div>2010-11-05 05:00:00 -1000 1.3985 stoplimit long -0.02 open NA NA 0<br>
2010-11-05 05:00:00 1000 1.4185 market long NA closed 2010-11-05 09:00:00 NA<br>
0<br>
2010-11-05 09:00:00 -1000 1.3901 stoplimit long -0.02 open NA NA 0<br>
2010-11-05 09:00:00 1000 1.4101 market long NA closed 2010-11-05 13:00:00 NA<br>
0<br>
<br>
</div></div></div><font color="#888888">--<br>
View this message in context: <a href="http://r.789695.n4.nabble.com/Quantstrat-stoplimit-orders-not-triggered-tp3673706p3687209.html" target="_blank">http://r.789695.n4.nabble.com/Quantstrat-stoplimit-orders-not-triggered-tp3673706p3687209.html</a><br>
</font><div class="im"><div><div></div><div>Sent from the Rmetrics mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
<a href="mailto:R-SIG-Finance@r-project.org" target="_blank">R-SIG-Finance@r-project.org</a> mailing list<br>
<a href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a><br>
-- Subscriber-posting only. If you want to post, subscribe first.<br>
-- Also note that this is not the r-help list where general R questions should go.<br>
</div></div></div></blockquote></div><br></div>
</blockquote></div><br></div>