[R-SIG-Finance] Quantstrat - Entering a limit order below the open price

Brian G. Peterson brian at braverock.com
Thu Feb 11 12:39:56 CET 2016


Dear 'Jimmy',

(if that is your real name, the complete lack of online footprint seems 
to suggest that it is not)

On 02/11/2016 12:50 AM, Smith Jimmy wrote:
> I'm wanting to enter a limit order at a set percentage below the open price
> if that's possible with Quantstrat.

Yes, it is.

Please do your homework, and read the documentation. Many people have 
contributed that documentation in the hopes that users will actually 
read it.

> I'm not sure if I have set this out correctly but here is an example. I was
> trying to set the limit 1% below the open price.

This is *still* not a minimal reproducible example.

http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

> I'm not quite sure how to use order.price to achieve this.

You won't use order.price, you'll use threshold.

> add.rule(strategy.st, name="ruleSignal",
>           arguments=list(sigcol="longentry", sigval=TRUE, ordertype="limit",
>                          orderside="long", replace=FALSE, prefer="Open",
> order.price=mktdata*(0.99),tmult=TRUE, orderqty=tradeSize,
> osFUN=osMaxDollar, tradeSize=tradeSize,
>                          maxSize=tradeSize),
>           type="enter", path.dep=TRUE, label="enterlong")

You most likely want

threshold=0.99, tmult=TRUE

and no order.price argument.

in your code, 'mktdata' probably doesn't exist yet, which is why you get 
no errors.  Have you noticed the use of quote() in many of the demos?  I 
suggest you look at

?quote

and the descriptions of the 'mktdata' object inside quantstrat to 
understand why mktdata is so often quoted when used inside parts of the 
strategy specification.

In your example mktdata probably doesn't exist at the time of strategy 
specification, so you are setting order.price = NULL*0.99, getting NULL. 
  quantstrat will quite reasonably set no price and enter no order.

If you had a mktdata object from a previous run or inadvisably quoted 
mktdata as it is in the other demos, you would have been multiplying 
0.99 by the entire time series of the mktdata object, and quantstrat 
would fail pointing out that order.price needs to be a scalar.

> I'd ideally like to have a trailing stop that would be based on the
> executed price.

Then please spend some time examining and working with the many demos 
which do this already.

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list