Skip to content
Prev 7832 / 15274 Next

quantstrat & custom indicators

If you look a the strategy object, you'll see that you have four sets of
rules by the time you're done.  This is likely not what you want.
Strategies should normally be agnostic to the instrument to trade, and
you're not really doing that.

I don't have time to rewrite this for you right now, but here's what I 
suggest.

build two portfolios, one for your longs, and one for your shorts
(alternately, you could have a portfolio for each instrument, but this
shouldn't be necessary)

build one account to hold it all

Have *two* strategy objects, ignoring symbols for now.  One will be your
'long' strategy, and one will be your 'short' strategy.  use some
arbitrarily large order quantity for your entries and 'all' for your
exits. (I'll explain this in a minute). have the rules use
osFUN='osMaxPos'

Use setPosLimit to set your maximum long and short position limits by
symbol.  

This should then work as you expect when you apply the long strategy to
the longs and the short strategy to the shorts.

#############

Now...  onto something more like what I suspect you're really trying to
do ...

Normally, what you'd really want to do is have a only a single strategy
object, regardless of symbol. So forget all about the symbols when
specifying the indicators, signals, and rules.

The sophisticated part lies in (maybe) using setPosLimit or some other
function to store things like limits/direction by symbol, and *then*
writing a custom order sizing function.  The order sizing function gets
a rule fire on a symbol, checks your custom metadata, and decides how
large (if any) an order to place.

You'll notice that several times in the documentation we refer to
signals as places where you *may* want to trade.  Rules and order sizing
functions take the *may* and can then decide to turn that into an
affirmative trade action and also decide how much.

HTH,

   - Brian
On Tue, 2011-05-03 at 12:28 -0700, algotr8der wrote: