4

When I use enable.rule I cannot override the rule's internal enabled=FALSE.

For example:

## Stop Loss Rule
stratstocky <- add.rule(stratstocky,
                        name = "ruleSignal",
                        arguments = list(sigcol = "sdH", 
                                         sigval = TRUE,
                                         replace = FALSE,
                                         orderside = "long",
                                         ordertype = "stoptrailing",
                                         tmult = TRUE,
                                         threshold = quote(stopLossPercent),
                                         orderqty = "all",
                                         orderset = "ocolong"),
                        type = "chain",
                        parent = "getLong",
                        label = "StopTrailingLong",
                        enabled = FALSE
)

When I place this code before applyStrategy:

enable.rule(stratstocky, type="chain", "StopTrail", enable=TRUE)

The rule will not become enabled or active. The only way to activate the rule it to change it's internal enable to TRUE. I have tried exact spelling but it is not working for me.

This is not a big issue as I can just parameterize the rule's internal enable and control it this way but would prefer to use the existing code to run my system.

Any insight into enable.rule issues?

Brian G. Peterson
  • 3,531
  • 2
  • 20
  • 21
int64
  • 81
  • 4

1 Answers1

5

Your example is not reproducible, but I can reproduce your problem with some assumptions.

It appears that you are mixing up store=TRUE and store=FALSE

Your add.rule call appears to assume store=FALSE, and then you pass your stratstocky object to enable.rule.

When store=FALSE , enable.rule will return the strategy object. I believe that in your use case, you probably want:

stratstocky <- enable.rule(stratstocky, type="chain", "StopTrail", enable=TRUE)

to update your object with the now-enabled rule.

To create a reproducible example, try

demo('macross',ask=FALSE)

which will run the demo, and create some objects. Like what I presume to be your example, the macross demo uses store=FALSE.

now:

stratMACROSS <- enable.rule(stratMACROSS,type='exit',label='ruleSignal.rule',enable=FALSE)

will disable the exit rule, and

stratMACROSS <- enable.rule(stratMACROSS,type='exit',label='ruleSignal.rule')

will enable it again.

Brian G. Peterson
  • 3,531
  • 2
  • 20
  • 21