title: Draw a line segment tangent to an SMA line
body: <p>How to draw a line segment that is tangent to an SMA line for trends in pine script for tradingview.</p>
  <p>What I would really love is a small line segment of about 5 candles long, centered on current candle, that shows a tangent line of the current candle sma5.</p>
  <p>A very help fellow here gave me a code to draw a line from ohlc4 from one candle back to the ohlc4 of a candle 5 candles back. I played with it to try and get something similar to what I am trying to accomplish, but I am just not able to get it right.</p>
  <pre><code>//@version=4
  study(&quot;Lookback Trend SMA&quot;, overlay=true)
  LB1 = input(5, title=&quot;Look back candles&quot;)
  sma4 = sma(close, 1)
  sma5 = sma(close, LB1)
  var line    myLine = line.new(na, na, na, na, color = color.yellow, width = 2)
  if barstate.islast
      line.set_xy1(myLine, bar_index[1],  sma4[1])
      line.set_xy2(myLine, bar_index[LB1], sma5[LB1])
  </code></pre>
  <p>I apologize for my butcher job to his eloquent code. But I really am trying to learn, rather than have to bother others with what is probably something simple. But I have been working on it for a few days and havent figured it out.</p>
  <p>I appreciate all help, thanks for reading this.</p>