title: Plotting manual levels for daily high,low,close
body: <p>As I've already asked a couple of questions here in an attempt to solve my problem, this new question ties them all together and provides some context.<br>
  Previous questions related to this:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/60659820/is-it-possible-to-draw-a-line-into-the-future">Is it possible to draw a line into the future?</a></li>
  <li><a href="https://stackoverflow.com/questions/61060015/edit-series-only-on-certain-dates">Edit series only on certain dates</a> </li>
  <li><a href="https://stackoverflow.com/questions/61217589/set-2-series-at-once">Set 2 series at once</a> </li>
  <li><a href="https://stackoverflow.com/questions/61258554/var-does-not-keep-its-value-across-bars">var does NOT keep it's value across bars</a> </li>
  <li><a href="https://stackoverflow.com/questions/61302696/function-returning-2-values-to-global-variable">function returning 2 values to global variable</a> </li>
  </ul>
  
  <p>I have a program (outside of TradingView) that tries to estimate the high/low/close levels of the ticker <code>SPX</code> for the next trading day.<br>
  I'm planning to plot this only on intraday timeframes (anything from 1 minute to 4 hours).<br>
  The only ticker I'm going to plot this on is <code>SPX</code>.  </p>
  
  <p>Now I'm trying to plot these levels in TradingView, to have a visual representation on how accurate the predicted levels are.<br>
  This means that I have a <code>high/low/close</code> value for every trading day.<br>
  The current dataset contains about 50 entries (so 50 days where I have a high/low/close level to plot) and will grow by 1 entry every trading day.<br>
  So in 1 year, the dataset will contain about 200 entries.  </p>
  
  <p>Because the dataset is larger than the number of drawing objects that can be displayed by TradingView, I've ruled out the use of drawing objects like <code>line.new()</code>.<br>
  The garbage collecter would cause only the last 50 or so drawn objects to be shown, and I'd like the full dataset to be displayed.<br>
  Therefore, I think I will need to resort to the <code>plot()</code> function.  </p>
  
  <p>This means I will end up with 3 series to plot: <code>high</code>, <code>low</code> and <code>close</code>.<br>
  Each will have a different value per trading date.<br>
  So essentially, I'm trying to manually create these 3 series by assigning them a value for each date.<br>
  But so far, I've failed to accomplish that.<br>
  I'm also trying to have only 1 data entry line per trading date to avoid clutter and to keep the code clean and maintainable.<br>
  Therefore, I'm trying to set these 3 data points per trading date with only 1 function.  </p>
  
  <p>The below script is my latest attempt with a reduced dataset of only 5 trading days for clarity.<br>
  I know the script below is wrong, because a variable cannot be re-used.<br>
  That's why it says <code>line 19: 'h' is already defined</code>.<br>
  I don't have a workaround for this, and I'd really like to find one.  </p>
  
  <pre><code>//@version=4
  study("Study", overlay=true)
  
  // Variables    
  var float dh = na
  var float dl = na
  var float dc = na
  
  // Functions
  isDate(y,m,d) =&gt; y==year and m==month and d==dayofmonth ? true:false 
  d(y,m,d,h,l,c) =&gt; // Daily Levels
      if isDate(y,m,d)
          [h,l,c]
      else
          [na,na,na] 
  
  // Set data for Daily High,Low,Close
  [h,l,c] = d(2020,04,13,2800,2700,2725), dh:=h,dl:=l,dc:=c
  [h,l,c] = d(2020,04,14,2850,2810,2825), dh:=h,dl:=l,dc:=c
  [h,l,c] = d(2020,04,15,2800,2750,2710), dh:=h,dl:=l,dc:=c
  [h,l,c] = d(2020,04,16,2850,2700,2790), dh:=h,dl:=l,dc:=c
  [h,l,c] = d(2020,04,17,2900,2800,2850), dh:=h,dl:=l,dc:=c
  
  // Plot Daily High,Low,Close
  plot(dh, color=color.red)
  plot(dl, color=color.green)
  plot(dc, color=color.blue)
  </code></pre>
  
  <p>Another attempt is this code below, which does compile ok.  </p>
  
  <pre><code>//@version=4
  study("Functions test", overlay=true)
  
  var float h = na
  var float l = na
  var float c = na
  
  isDate(y,m,d) =&gt; y==year and m==month and d==dayofmonth ? true:false
  setData() =&gt; 
      if isDate(2020,04,13)
          [2800,2700,2725]
      if isDate(2020,04,14)
          [2850,2810,2825]
      if isDate(2020,04,15)
          [2800,2750,2710]
      if isDate(2020,04,16)
          [2850,2700,2790]
      if isDate(2020,04,17)
          [2900,2800,2850]
  
  [h1,l1,c1] = setData()
  
  h := h1
  l := l1
  c := c1
  
  plot(h,color=color.red)
  plot(l,color=color.green)
  plot(c,color=color.blue)
  </code></pre>
  
  <p>The problem here is that it only plots the values for the last date. </p>
  
  <p><a href="https://i.stack.imgur.com/ONOMG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ONOMG.png" alt="enter image description here"></a></p>