title: How to plot only within a range defined by x number of bars?
body: <p>I understand that I can contingently plot on the chart using range of date and time values.</p>
  <p>However, I would like to be able to plot using a <em><strong>specific number of candlesticks</strong></em>.</p>
  <p>For example, I would like to be able to say something like</p>
  <pre><code>// Within the most recent 10 bars
  // If close[0] &gt; close[1]
  // plotshape()
  </code></pre>
  <p>I have tried implementing numerous variations using <code>barstate.isrealtime</code> or <code>barstate.islast</code> but I keep running into limitations.</p>
  <p>One major problem is that, although <code>bar_index[#]</code> works by indexing backwards from <strong>the most recent bar</strong>, the value of <code>bar_index[10]</code> is not 10 but some number in the thousands (depending on the timeframe of the chart — for me its Daily = 2,616 candles, 1hr = 6,217 candles, 15m = 5,222, etc.).  In other words, it counts the number of bars from <strong>the oldest bar</strong> available.</p>
  <p>Since referencing of the bars (starting from most recent) and the index values (starting from the oldest) are conflicting--due to counting from opposite ends--I am not sure how to specify: plotshape() for the most recent 10 bars.</p>
  <p>I am also running into trouble due to the fact that <code>bar_index[0]</code> occurs every single iteration of the chart's timeframe--so I am getting caught in recursive calculations when trying to do <code>bar_index[0]-bar_index[10]</code>.</p>
  <p>It seems that what I need is something like <code>bar_index.islast[10]</code></p>
  <p>The reason that I would like to call a plotshape() based on the <strong>number of specified candles</strong> versus <strong>since x date/time</strong> (or <strong>within date range (x,y)</strong>), is because I want my indicator to function properly regardless of which timeframe my chart is displaying:</p>
  <p>If I am showing a monthly chart, I want to plot across the last 10 monthly bars; If I am showing a daily chart, I want to plot across the last 10 daily bars; etc.</p>
  <p>If I am forced to use a date range, then this functionality breaks down, since I will be shown increasingly more bars for smaller timeframes.</p>
  <p><strong>Caveat</strong>**
  I am able to <em><strong>kinda</strong></em> make this work by specifying the number of bars from the oldest candlestick by stating something like:</p>
  <p><code>bar_index &gt; 2600 ? color=color.black : na</code></p>
  <p>However, given the fact that every single time frame displays a different number of bars, this is not a workable solution for me.</p>
  <p>Thanks for any advice.</p>
  <p><strong>UPDATE</strong>
  I have been hunting around and and found that the functionality I desire is already built into the <code>show_last</code> argument of the various plot()functoins.</p>
  <p>Ill leave my question posted, in case it helps someone else.</p>