This is a very strange problem. Let's start from this very simply example:
## ... some other code ...
chartSeries(y, theme='white',style="candlesticks", subset='last 12 months')
names(y) <- c("Open", "High", "Low", "Close", "Volume")
addEMA(n=3, col='red')
addEMA(n=10,col='green')
addEMA(n = 18, col = 'blue')
## ... other code ...
If the file as it is like using "source filename.R" etc, there was a chart popped but those addEMA lines weren't plotted. However, these addEMA() lines would work when manually run by highlighting the addEMA lines and run selected lines.
Both Linux and Windows see this problem.
There is a difference between interactive mode of R and sourcing a file. This is mentioned in the R faq chapter 7. There are 2 ways to get the result you want.
Instead of the separate calls to the addTA
function, you can add them all inside the chartSeries
call.
chartSeries(y, theme='white',style="candlesticks", subset='last 12 months',
TA = c(addEMA(n=3, col='red'), addEMA(n=10,col='green'), addEMA(n = 18, col = 'blue')))
When sourced this will give you the exact same result as when you would run the code interactively.
Source the file, but set echo = TRUE
.
source("path_to_file/my_R_source_file.R", echo = TRUE)
Option 1 is cleaner when sourcing as your screen will not be filled with all the code lines.