Hi, trying to get a handle on quantstrat and was hoping somebody could
explain the what I'm doing wrong.
The strategy itself is simple enough (and just for testing purposes - buy
when RSI goes below 30, sell back out when RSI goes above 70.
What is unintended, is that short trades (exit) are processed before long
trades (entry) ever are. Why is this happening?
Also, I was playing around with order sizing - it seems like one should be
able to specify "all" for exit trades, but that doesn't seem to work for me
when I make the substitution in the below code... the issues may be
related, though, so I am putting this on the back burner for now.
You're not going short, you're selling a long position. Those are
different things. Going short in an equity requires a margin account
and a short locate at least, and will incur interest charges on the
In any case, your strategy is trying to enter long, and then exit your
long position. Both the entry and exit orders are on the same
side='long' of the market.
See the demo script rsi.R in the demo directory for a long/short
version of the same idea.
The other thing that is likely tripping you up is rule order. Rules
are evaluated in a specific order, as described in the documentation
for add.rule and other places. exits are evaluated before entries.