[R-SIG-Finance] Customized indicator for quantstrat

Brian G. Peterson brian at braverock.com
Sat Dec 15 19:54:59 CET 2012

On 12/15/2012 12:52 PM, Robert A'gata wrote:
> Thanks again Brian. I understand the example well. So if I were to flip my
> position when my price crosses local VWAP on the opposite side, I will need
> to set 2 rules, one is to enter into a new position and the other is to
> exit the previous position? If so, how do I know which rule will be fired
> first? This is important because says if I was longing and my price crosses
> VWAP from above the rule to enter a new short will get fired first. Then my
> total position is 0. Next my exit signal will fire an order of zero size.
> The right order I'd like the rules to be executed is to exit the existing
> long and then execute a new short.
> If there is any better way to do, I'd much appreciate your suggestion.
> Thank you.

Rules are fired in a particular order.  By default, exits fire first. 
So a stop and reverse approach will first stop, then reverse, because 
the exit rule will be processed before the entry.  You can see that 
several of the examples follow a stop and reverse approach.

You are correct that you are best served by having separate rules for 
all of the combinations.  the 'luxor' series of demos are the most 
rigorous in demonstrating various quantstrat features, and build them up 
successively over time, in much the way that strategy authors tend to 
start with a simple idea, and then add complexity incrementally.


    - Brian

Brian G. Peterson
Ph: 773-459-4973
IM: bgpbraverock

More information about the R-SIG-Finance mailing list