[R-SIG-Finance] quantstrat - trailingStop offsets?

Mark Knecht markknecht at gmail.com
Mon Oct 13 17:32:38 CEST 2014


On Mon, Oct 13, 2014 at 7:52 AM, Brian G. Peterson <brian at braverock.com> wrote:
> On 10/13/2014 09:29 AM, Mark Knecht wrote:
>>
>> Good morning,
>>     Base question: Are there any quantstrat examples showing how to set
>> a minimum profit target before a trailing stop kicks in?
>>
>>     For example, for a risk stop of 5% and a trailing stop of 3%, I
>> don't want to the trailing stop to be executed until I have met a
>> minimum profit of at least 2% resulting in a maximum approximate loss
>> of 1% if the trailing stop executes.
>
>
> If your risk stop is 5% and your trailing stop is 3%, there's no reason not
> to just enter the trailing stop at 3%, thus limiting your loss to 3% or
> less.  The risk stop would never be triggered.
>

If the entry is 'efficient' to the extent that the entry price within
3% of the low
before the market starts moving in my direction then, yes, you are right. There
wouldn't be any advantage.

On the other hand, if the entry is not efficient and I'm in too early
then I want
to give it more breathing room (5%) before it starts moving. In this example
I define 'moving' as 2% in my favor.

Granted, position size for a fixed dollar risk is smaller.


> Or am I missing what you're asking to do?
>

No, I think you do understand based on the last idea at the end.

> There are a number of ways to trigger orders in quantstrat.
>
> Simple signals trigger a rule.  This is how your entry most likely works.
>
> 'chain' rule orders are triggered by a fill.  for example, your entry order
> is filled, and the chain rule for that entry will trigger. You can see
> examples of this in the luxor scripts where stop loss and take profit orders
> are entered after a position is initiated.
>
> order sets create an OCO relationship between related orders.  in the
> example above, your stop and profit taking order would be an orderset. if
> one is filled, the other is canceled.
>

OK, Joshua pointed me at order sets in luxor.5.strategy.ordersets.R so
I'm looking there.

> in the case of 'I only want to enter an order if my existing position has
> moved x% in my favor', I guess I'd ask 'why?' and 'how do you plan to do
> this in production?'.  I see very little difference in your example between
> 'enter my trailing stop at -3% after I've gone up 2%, but until then, use a
> 5% stop' and the much simpler 'enter a trailing stop at 3% when I get my
> entry fill'.
>

Maybe I'm driven too much by TradeStation history but many traders
there look for some sort of a 'break even' exit if the trade doesn't meet
a profit target. I.e - I'm targeting a 5% win. I'l accept a 5% loss until I get
to a 3% profit at which time I will expect to break even worst case.

(That's different than what I proposed at the outset where I would accept a
1% loss if I make it to 2% gain max before it falls back, but I am pretty sure
you see the idea.)

> All that said, you could do what I think you say you want by triggering a
> signal for 2% above your entry signal.  The rule for that signal would
> cancel the 5% risk stop and add the 3% trailing stop.
>

So I'll need to figure out what you mean by 'cancel' but the wording
seems like what I'm looking for.

General code idea?

If (MaxGain < 2%){
   enable.rule('luxor','chain','StopLoss',enabled=TRUE)
   enable.rule('luxor','chain','StopTrailing',enabled=FALSE)
}else{
  enable.rule('luxor','chain','StopLoss',enabled=FALSE)
   enable.rule('luxor','chain','StopTrailing',enabled=TRUE)
}

Does quantstrat allow the state of a rule be dynamic like that?

> Regards,
>
> Brian
>

Much thanks!

Cheers,
Mark



More information about the R-SIG-Finance mailing list