3

I've been playing around with the Life Analytics trading with R tutorial (http://lifeanalytics.blogspot.com/2011/01/forex-trading-with-r-part-1.html) and keep getting stuck on a problem related to building the data model.

So I start with a bunch of functions:

myATR <- function(x) ATR(HLC(atrx))[,'atr']
mySMI <- function(x) SMI(HLC(smix))[,'SMI']
myADX <- function(x) ADX(HLC(x))[,'ADX']
.
.

Then try to build a model passing the data to the functions:

data.model <- specifyModel(myATR(AUDCAD)+mySMI(AUDCAD)...)

And keep getting the following error:

Error in formula.default(object, env = baseenv()) : invalid formula

I've read the following post, but do not understand it well enough to implement a solution: formula error inside function

Can anyone explain this in simpler terms? I need some help getting my hook into understanding environments better.

Community
  • 1
  • 1
Mark C
  • 427
  • 2
  • 7
  • 16
  • 6
    This doesn't have anything to do with environments. The problem is that you haven't passed a formula to `specifyModel`. In R, a formula is a _symbolic_ expression giving the terms that make up a model. What you've passed it is an actual expression, ie one that will be evaluated to give a numerical result. See `?formula` for how to specify a formula. – Hong Ooi Jun 02 '13 at 11:22
  • Okay. I had to research this, but it seems I have fixed the problem. Thank you for the help. – Mark C Jun 03 '13 at 20:57
  • 4
    @MarkC Then you can post an answer :) – Felipe Augusto May 26 '20 at 05:16

0 Answers0