code: def runtest(
      datas,
      strategy,
      runonce=None,
      preload=None,
      exbar=None,
      plot=False,
      optimize=False,
      maxcpus=1,
      writer=None,
      analyzer=None,
      **kwargs,
  ):
      runonces = [True, False] if runonce is None else [runonce]
      preloads = [True, False] if preload is None else [preload]
      exbars = [-2, -1, False] if exbar is None else [exbar]
  
      cerebros = list()
      for prload in preloads:
          for ronce in runonces:
              for exbar in exbars:
                  cerebro = bt.Cerebro(
                      runonce=ronce,
                      preload=prload,
                      maxcpus=maxcpus,
                      exactbars=exbar,
                  )
  
                  if kwargs.get("main", False):
                      print(
                          "prload {} / ronce {} exbar {}".format(
                              prload, ronce, exbar
                          )
                      )
  
                  if isinstance(datas, bt.LineSeries):
                      datas = [datas]
                  for data in datas:
                      cerebro.adddata(data)
  
                  if not optimize:
                      cerebro.addstrategy(strategy, **kwargs)
  
                      if writer:
                          wr = writer[0]
                          wrkwargs = writer[1]
                          cerebro.addwriter(wr, **wrkwargs)
  
                      if analyzer:
                          al = analyzer[0]
                          alkwargs = analyzer[1]
                          cerebro.addanalyzer(al, **alkwargs)
  
                  else:
                      cerebro.optstrategy(strategy, **kwargs)
  
                  cerebro.run()
                  if plot:
                      cerebro.plot()
  
                  cerebros.append(cerebro)
  
      return cerebros
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import datetime
  import os
  import os.path
  import sys
  import backtrader
  import backtrader.utils.flushfile
  from backtrader.metabase import ParamsBase
label_desc: Use image node_id 2 for calling a global function with example usage: runtest(datas, strategy, runonce, preload, exbar, plot, optimize, maxcpus, writer, analyzer) and returns: cerebros