Skip to content
Prev 12902 / 15274 Next

quantstrat help

On Fri, Oct 17, 2014 at 7:31 AM, Raghuraman Ramachandran
<optionsraghu at gmail.com> wrote:
It is very bad practice to call a vectorized function (ifelse) inside
a loop.  The loop is unnecessary:
GSPC$signal <- with(GSPC,
  ifelse(Close > 1.02*Open, 1, ifelse(Close <= 0.98*Open, -1, 0)))
If you truly want to ignore those signals, simply remove them before
sending them to applyRules.
GSPC$firstSignal <- with(GSPC, ifelse(signal == lag(signal), 0, signal))