code: def btrun(pargs=""):
      args = parse_args(pargs)
  
      if args.flush:
          import backtrader.utils.flushfile
  
      stdstats = not args.nostdstats
  
      cer_kwargs_str = args.cerebro
      cer_kwargs = eval("dict(" + cer_kwargs_str + ")")
      if "stdstats" not in cer_kwargs:
          cer_kwargs.update(stdstats=stdstats)
  
      cerebro = bt.Cerebro(**cer_kwargs)
  
      if args.resample is not None or args.replay is not None:
          if args.resample is not None:
              tfcp = args.resample.split(":")
          elif args.replay is not None:
              tfcp = args.replay.split(":")
  
          # compression may be skipped and it will default to 1
          if len(tfcp) == 1 or tfcp[1] == "":
              tf, cp = tfcp[0], 1
          else:
              tf, cp = tfcp
  
          cp = int(cp)  # convert any value to int
          tf = TIMEFRAMES.get(tf, None)
  
      for data in getdatas(args):
          if args.resample is not None:
              cerebro.resampledata(data, timeframe=tf, compression=cp)
          elif args.replay is not None:
              cerebro.replaydata(data, timeframe=tf, compression=cp)
          else:
              cerebro.adddata(data)
  
      # get and add signals
      signals = getobjects(
          args.signals, bt.Indicator, bt.signals, issignal=True
      )
      for sig, kwargs, sigtype in signals:
          stype = getattr(bt.signal, "SIGNAL_" + sigtype.upper())
          cerebro.add_signal(stype, sig, **kwargs)
  
      # get and add strategies
      strategies = getobjects(
          args.strategies, bt.Strategy, bt.strategies
      )
      for strat, kwargs in strategies:
          cerebro.addstrategy(strat, **kwargs)
  
      inds = getobjects(args.indicators, bt.Indicator, bt.indicators)
      for ind, kwargs in inds:
          cerebro.addindicator(ind, **kwargs)
  
      obs = getobjects(args.observers, bt.Observer, bt.observers)
      for ob, kwargs in obs:
          cerebro.addobserver(ob, **kwargs)
  
      ans = getobjects(args.analyzers, bt.Analyzer, bt.analyzers)
      for an, kwargs in ans:
          cerebro.addanalyzer(an, **kwargs)
  
      setbroker(args, cerebro)
  
      for wrkwargs_str in args.writers or []:
          wrkwargs = eval("dict(" + wrkwargs_str + ")")
          cerebro.addwriter(bt.WriterFile, **wrkwargs)
  
      ans = getfunctions(args.hooks, bt.Cerebro)
      for hook, kwargs in ans:
          hook(cerebro, **kwargs)
      runsts = cerebro.run()
      runst = runsts[0]  # single strategy and no optimization
  
      if args.pranalyzer or args.ppranalyzer:
          if runst.analyzers:
              print("====================")
              print("== Analyzers")
              print("====================")
              for name, analyzer in runst.analyzers.getitems():
                  if args.pranalyzer:
                      analyzer.print()
                  elif args.ppranalyzer:
                      print("##########")
                      print(name)
                      print("##########")
                      analyzer.pprint()
  
      if args.plot:
          pkwargs = dict(style="bar")
          if args.plot is not True:
              # evaluates to True but is not "True" - args were passed
              ekwargs = eval("dict(" + args.plot + ")")
              pkwargs.update(ekwargs)
  
          # cerebro.plot(numfigs=args.plotfigs, style=args.plotstyle)
          cerebro.plot(**pkwargs)
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import argparse
  import datetime
  import inspect
  import itertools
  import random
  import string
  import sys
  import backtrader
label_desc: Use image node_id 1 for calling a global function with example usage: btrun(pargs) without return types