title: tradingview's pine script convert python
body: <p>Now convert to python from tradingview pine script.
  But have some problem.
  under function.</p>
  <p>reso(exp, use, res) =&gt; use ? security(tickerid, res, exp) : exp</p>
  <p>I don't understand to pine script security function. and don't convert to python.</p>
  <p>original url:
  <a href="https://www.tradingview.com/script/X227SKSM-Open-Close-Cross-Strategy-R6-1-revised-by-yourmattie/" rel="nofollow noreferrer">https://www.tradingview.com/script/X227SKSM-Open-Close-Cross-Strategy-R6-1-revised-by-yourmattie/</a></p>
  <p>pine script source code:</p>
  <pre><code>//@version=2
  
  strategy(title = &quot;Open Close Cross Strategy&quot;, shorttitle = &quot;OCC Strategy&quot;, overlay = true, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
  
  
  // === INPUTS ===
  useRes      = input(defval = true, title = &quot;Use Alternate Resolution? ( 
  recommended )&quot;)
  stratRes    = input(defval = &quot;120&quot;, title = &quot;Set Resolution ( should not be lower than chart )&quot;, type = resolution)
  useMA       = input(defval = true, title = &quot;Use MA? ( otherwise use simple Open/Close data )&quot;)
  basisType   = input(defval = &quot;DEMA&quot;, title = &quot;MA Type: SMA, EMA, DEMA, TEMA, WMA, VWMA, SMMA, HullMA, LSMA, ALMA ( case sensitive )&quot;, type = string)
  basisLen    = input(defval = 14, title = &quot;MA Period&quot;, minval = 1)
  offsetSigma = input(defval = 6, title = &quot;Offset for LSMA / Sigma for ALMA&quot;, minval = 0)
  offsetALMA  = input(defval = 0.85, title = &quot;Offset for ALMA&quot;, minval = 0, step = 0.01)
  useStop     = input(defval = true, title = &quot;Use Trailing Stop?&quot;)
  slPoints    = input(defval = 200, title = &quot;Stop Loss Trail Points&quot;, minval = 1)
  slOffset    = input(defval = 400, title = &quot;Stop Loss Trail Offset&quot;, minval = 1)
  // === /INPUTS ===
  
  // === BASE FUNCTIONS ===
  // Returns MA input selection variant, default to SMA if blank or typo.
  variant(type, src, len, offSig, offALMA) =&gt;
      v1 = sma(src, len)                                                  // Simple
      v2 = ema(src, len)                                                  // Exponential
      v3 = 2 * v2 - ema(v2, len)                                          // Double Exponential
      v4 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)               // Triple Exponential
      v5 = wma(src, len)                                                  // Weighted
      v6 = vwma(src, len)                                                 // Volume Weighted
      v7 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len    // Smoothed
      v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))   // Hull
      v9 = linreg(src, len, offSig)                                       // Least Squares
      v10 = alma(src, len, offALMA, offSig)                               // Arnaud Legoux
      type==&quot;EMA&quot;?v2 : type==&quot;DEMA&quot;?v3 : type==&quot;TEMA&quot;?v4 : type==&quot;WMA&quot;?v5 : type==&quot;VWMA&quot;?v6 : type==&quot;SMMA&quot;?v7 : type==&quot;HullMA&quot;?v8 : type==&quot;LSMA&quot;?v9 : type==&quot;ALMA&quot;?v10 : v1
  // security wrapper for repeat calls
  reso(exp, use, res) =&gt; use ? security(tickerid, res, exp) : exp
  // === /BASE FUNCTIONS ===
  
  // === SERIES SETUP ===
  // open/close
  closeSeries = useMA ? reso(variant(basisType, close, basisLen, offsetSigma, offsetALMA), useRes, stratRes) : reso(close, useRes, stratRes)
  openSeries  = useMA ? reso(variant(basisType, open, basisLen, offsetSigma, offsetALMA), useRes, stratRes) : reso(open, useRes, stratRes)
  trendState  = closeSeries &gt; openSeries ? true : closeSeries &lt; openSeries ? false : trendState[1]
  // === /SERIES ===
  
  // === PLOTTING ===
  barcolor(color = closeSeries &gt; openSeries ? #006600 : #990000, title = &quot;Bar Colours&quot;)
  // channel outline
  closePlot   = plot(closeSeries, title = &quot;Close Line&quot;, color = #009900, linewidth = 2, style = line, transp = 90)
  openPlot    = plot(openSeries, title = &quot;Open Line&quot;, color = #CC0000, linewidth = 2, style = line, transp = 90)
  // channel fill
  closePlotU  = plot(trendState ? closeSeries : na, transp = 100, editable = false)
  openPlotU   = plot(trendState ? openSeries : na, transp = 100, editable = false)
  closePlotD  = plot(trendState ? na : closeSeries, transp = 100, editable = false)
  openPlotD   = plot(trendState ? na : openSeries, transp = 100, editable = false)
  fill(openPlotU, closePlotU, title = &quot;Up Trend Fill&quot;, color = #009900, transp = 40)
  fill(openPlotD, closePlotD, title = &quot;Down Trend Fill&quot;, color = #CC0000, transp = 40)
  // === /PLOTTING ===
  
  // === STRATEGY ===
  // conditions
  longCond    = crossover(closeSeries, openSeries)
  shortCond   = crossunder(closeSeries, openSeries)
  // entries and base exit
  strategy.entry(&quot;long&quot;, strategy.long, when = longCond)
  strategy.entry(&quot;short&quot;, strategy.short, when = shortCond)
  // if we're using the trailing stop
  if (useStop)
      strategy.exit(&quot;XL&quot;, from_entry = &quot;long&quot;, trail_points = slPoints, trail_offset = slOffset)
      strategy.exit(&quot;XS&quot;, from_entry = &quot;short&quot;, trail_points = slPoints, trail_offset = slOffset)
  // not sure needed, but just incase..
  strategy.exit(&quot;XL&quot;, from_entry = &quot;long&quot;, when = shortCond)
  strategy.exit(&quot;XS&quot;, from_entry = &quot;short&quot;, when = longCond)
  // === /STRATEGY ===
  </code></pre>