title: how to overcome 'plot' and 'fill' function restrictions
body: <p>I am a professional C programmer and now I make my first steps in Pinescript :-)<br>
  so I wrote one simple and working script:</p>
  <pre><code>study(&quot;test - 1&quot;)
  
  var float sum = 0
  var float prev_sum = 0
  var float per = 0
  prev_sum := 0
  sum := 0
  per := 0
  
  f_print( _text, _color, _y ) =&gt;
      var _label = label.new( x=bar_index-4, y=1, text = _text, xloc = xloc.bar_index, yloc = yloc.price, color = color(na), style = label.style_none, textcolor = _color, size = size.small, textalign = text.align_right )
      label.set_xy( _label, bar_index -20, _y +5 )
      label.set_text( _label, _text )
  
  p0 = plot( 0, title=&quot;X axle&quot;, color = color.black )
  
  t1 = &quot;CRYPTOCAP:BTC.D&quot;
  per := security( t1, timeframe.period, ohlc4 )
  sum := sum + per
  p1 = plot( sum, title=t1, color = color.red )
  fill( p0, p1, color.red )
  
  f_print( &quot;BTC.D  &quot; + tostring( round( per, 3 ) ), color.red, prev_sum )
  prev_sum := sum
  
  t2 = &quot;CRYPTOCAP:ETH.D&quot;
  per := security( t2, timeframe.period, ohlc4 )
  sum := sum + per
  p2 = plot( sum, title=t2, color = color.blue )
  fill( p1, p2, color.blue )
  
  f_print( &quot;ETH.D  &quot; + tostring( round( per, 3 ) ), color.blue, prev_sum )
  </code></pre>
  <p>and it is working just fine, <br>
  the problem is that I wish to add another dozen of tickers for plotting, <br>
  so I tried to optimize my code and to make a function for the repeating part:</p>
  <pre><code>study( &quot;test - 2&quot; )
  
  var float sum = 0
  sum := 0
  
  f_print( _text, _color, _y ) =&gt;
      var _label = label.new( x=bar_index, y=1, text=_text, xloc=xloc.bar_index, yloc=yloc.price, color=color(na), style=label.style_none, textcolor=_color, size=size.small, textalign=text.align_right )
      label.set_xy( _label, bar_index -20, _y +5 )
      label.set_text( _label, _text )
  
  
  plot_domin( _ticker, _sum, _pl, _color ) =&gt;
      per = security( _ticker, timeframe.period, ohlc4 )
      loc_sum = _sum + per
      pl_ret = plot( loc_sum, title=_ticker, color = _color )
      fill( _pl, pl_ret, color.red )
      f_print( _ticker + &quot; &quot; + tostring( round( per, 3 ) ), _color, _sum )
      [ loc_sum, pl_ret ]
  
  
  p0 = plot( 0, title=&quot;X axle&quot;, color = color.black )
  [ sum, p1 ] = plot_domin( &quot;CRYPTOCAP:BTC.D&quot;, sum, p0, color.red  )
  [ sum, p2 ] = plot_domin( &quot;CRYPTOCAP:ETH.D&quot;, sum, p1, color.blue  )
  
  </code></pre>
  <p>but here I hit two restrictions:</p>
  <pre><code>line 23: Cannot use 'plot' in local scope.;
  line 24: Cannot call 'fill' with arguments (&lt;plot_domin_arg2_type&gt;, plot, const color); available overloads: fill(hline, hline, series[color], input integer, const string, const bool, const bool, string) =&gt; void; fill(plot, plot, series[color], input integer, const string, const bool, input integer, const bool, string) =&gt; void;
  </code></pre>
  <p>and the most strange is that it is complaining that</p>
  <pre><code>line 31: 'sum' is already defined.
  </code></pre>
  <p>so I even can not use a one and the same variable for 'sum' and I have to use 'sum1', 'sum2', ...
  <br><br>
  Any idea, how to avoid the repeating part of code and <br>
  to avoid the multiplication of usage of different variables on every return value from a function?
  <br><br>
  thank you in advance! :-)</p>