Can't figure out how to delete a specified indicator by name from TA list in R quantmod.
require("quantmod")
getSymbols("AAPL", src="yahoo", from = '2018-01-1', to = '2019-01-1')
#my custom indicator
AAPL_sma_50 <- SMA(
Cl(AAPL),
n = 50
)
candleChart(AAPL, up.col = "black", dn.col = "red", theme = "white")
addTA(AAPL_sma_50, on = 1, col = "blue")
addBBands()
listTA()
listTA()
output:
[[1]] addVo()
[[2]] addTA(ta = AAPL_sma_50, on = 1, col = "blue")
[[3]] addBBands()
I'm able to do delete built-in with dropTA('addBBands')
, but cannot delete custom indicator the same way:
dropTA('AAPL_sma_50')
Error in dropTA("AAPL_sma_50") : nothing to remove
dropTA(2) is not working by index either - it always deletes first element
How I can delete the second custom one only, or how to create it, to be able to delete later by name- e.g. dropTA('myCustomIndicator')
There are a few options to remove TA's from the plot. The trick is to know that when you use addTA(my_indicator)
, you can not use dropTA(my_indicator)
. Because you added the TA via addTA()
, so you need to call dropTA(ta = "addTA")
.
Now a few possibilies:
dropTA(all = TRUE) # removes all technical indicators
dropTA(ta = "addBBAnds") # removes the bolinger bands you added via addBBands()
If you added a few custom TA's with addTA, you can specify which version to delete if you now the order.
dropTA(ta = "addTA", occ = 2) # removes the second occurence of the TA you added
dropTA(ta = "addTA", all = TRUE) # removes all TA's added with addTA
This is useful when you have used multiple addEMA or addSMA indicators to the chart.
example with EMA indicators:
library(quantmod)
getSymbols("AAPL", src="yahoo", from = '2018-01-1', to = '2019-01-1')
candleChart(AAPL, up.col = "black", dn.col = "red", theme = "white")
addEMA(Cl(AAPL), n = 13, on = 1)
addEMA(Cl(AAPL), n = 21, on = 1)
addEMA(Cl(AAPL), n = 5, on = 1)
dropTA(ta = "addEMA", occ = 2) # removes the second occurence of the EMA's you added
dropTA(ta = "addEMA", all = TRUE) # removes all (other) EMA's added