Search code examples
rquantmod

R quantmod chartSeries: Add multiple TA overlay to single chart


I'm trying to add multiple TA's to my main chartSeries chart, and they all add below instead of overlaying each other. Is it possible to add multiple TA overlays?

chartSeries(GE, theme="white",
TA="addTA(GE1);addTA(GE2);addTA(GE3)") 

I've tried with the variables below;

on=1 and overlay=TRUE

I'm looking for all the TA's to be in a single chart.

Thank you in advance for your time.


Solution

  • Well, on=1 is what you need. I'm having trouble getting the TA="" to work, with the data I had to hand, but this did work:

    chartSeries(x,TA=NULL);addTA(EMA(x$Close),on=1)
    

    (The TA=NULL is to remove the volume chart.)

    Or, use newTA to define your TA with all the desired parameters in advance, and then the TA argument does accept it:

    myEMA = newTA(EMA, Cl, on=1, col=7)
    chartSeries(x, TA="myEMA()")
    

    (See ?newTA, which is where I stole that first line from!)