title: How to create custom indicator? Slope of the line of 50 day EMA
body: <p>I have been creating a few technical indicators using Quantmod's NewTa function.
  I've been trying to create a custom indicator that ideally should be charted using <code>ChartSeries</code>. This indicator should show the slope of the line of the 50 day EMA of the adjusted closing price.</p>
  
  <pre><code>getSymbols("NOVO-B.CO")
  p &lt;- na.omit('NOVO-B.CO')
  FiftyEMA &lt;- function(x){
  
  
  MA &lt;- removeNA((EMA(p[,6],n=50)))
  
  }
  SlopeFiftyEMA &lt;- function(x){
    run=(FiftyEMA(y)/FiftyEMA(x))
  }
  Slope.Indicator &lt;- newTA(SlopeFiftyEMA,legend.name = "50 Day EMA Slope of Line Indicator")
  Slope.Indicator()
  </code></pre>
  
  <p>This gives me the error: Error in get.current.chob() : improperly set or missing graphics device</p>
  
  <p>I also tried a new code that gives me an actual INDICATOR! Please let me know what you think (if you think it looks correct or not):</p>
  
  <p>First I export the data to excel: (the stock data is still denoted as <code>p</code>)</p>
  
  <pre><code>write.csv(p,"data")
  </code></pre>
  
  <h1>import data</h1>
  
  <pre><code>x &lt;- data[,1]
  y &lt;- data[,7]
  MA &lt;- removeNA(EMA(y,n=50))
  length(MA)
  </code></pre>
  
  <h1>length of MA = 1923</h1>
  
  <pre><code>l=1:1923
  SlopeFiftyEMA &lt;- function(x){
  (diff(MA)/diff(l))
  }
  Slope.Indicator &lt;- newTA(SlopeFiftyEMA,legend.name = "50 Day EMA Slope of Line Indicator")
  twelvemonths="last 12 months"
  chartSeries(p,subset = twelvemonths,theme = 'white',up.col = 'blue',dn.col = 'grey',name ="Custom Indicators")
  Slope.Indicator()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HkyVe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HkyVe.png" alt="Custom Indicator on the Chart"></a></p>
  
  <p>Any Input anyone? Last time I posted there was no indicator</p>
  
  <p>Thanks in advance!</p>