code: def runstrategy():
      args = parse_args()
  
      # Create a cerebro
      cerebro = bt.Cerebro()
  
      storekwargs = dict()
  
      if not args.nostore:
          vcstore = bt.stores.VCStore(**storekwargs)
  
      if args.broker:
          brokerargs = dict(account=args.account, **storekwargs)
          if not args.nostore:
              broker = vcstore.getbroker(**brokerargs)
          else:
              broker = bt.brokers.VCBroker(**brokerargs)
  
          cerebro.setbroker(broker)
  
      timeframe = bt.TimeFrame.TFrame(args.timeframe)
      if args.resample or args.replay:
          datatf = bt.TimeFrame.Ticks
          datacomp = 1
      else:
          datatf = timeframe
          datacomp = args.compression
  
      fromdate = None
      if args.fromdate:
          dtformat = "%Y-%m-%d" + ("T%H:%M:%S" * ("T" in args.fromdate))
          fromdate = datetime.datetime.strptime(args.fromdate, dtformat)
  
      todate = None
      if args.todate:
          dtformat = "%Y-%m-%d" + ("T%H:%M:%S" * ("T" in args.todate))
          todate = datetime.datetime.strptime(args.todate, dtformat)
  
      VCDataFactory = (
          vcstore.getdata if not args.nostore else bt.feeds.VCData
      )
  
      datakwargs = dict(
          timeframe=datatf,
          compression=datacomp,
          fromdate=fromdate,
          todate=todate,
          historical=args.historical,
          qcheck=args.qcheck,
          tz=args.timezone,
      )
  
      if args.nostore and not args.broker:  # neither store nor broker
          datakwargs.update(
              storekwargs
          )  # pass the store args over the data
  
      data0 = VCDataFactory(
          dataname=args.data0, tradename=args.tradename, **datakwargs
      )
  
      data1 = None
      if args.data1 is not None:
          data1 = VCDataFactory(dataname=args.data1, **datakwargs)
  
      rekwargs = dict(
          timeframe=timeframe,
          compression=args.compression,
          bar2edge=not args.no_bar2edge,
          adjbartime=not args.no_adjbartime,
          rightedge=not args.no_rightedge,
      )
  
      if args.replay:
          cerebro.replaydata(data0, **rekwargs)
  
          if data1 is not None:
              cerebro.replaydata(data1, **rekwargs)
  
      elif args.resample:
          cerebro.resampledata(data0, **rekwargs)
  
          if data1 is not None:
              cerebro.resampledata(data1, **rekwargs)
  
      else:
          cerebro.adddata(data0)
          if data1 is not None:
              cerebro.adddata(data1)
  
      if args.valid is None:
          valid = None
      else:
          try:
              valid = float(args.valid)
          except:
              dtformat = "%Y-%m-%d" + (
                  "T%H:%M:%S" * ("T" in args.valid)
              )
              valid = datetime.datetime.strptime(args.valid, dtformat)
          else:
              valid = datetime.timedelta(seconds=args.valid)
  
      # Add the strategy
      cerebro.addstrategy(
          TestStrategy,
          smaperiod=args.smaperiod,
          trade=args.trade,
          exectype=bt.Order.ExecType(args.exectype),
          stake=args.stake,
          stopafter=args.stopafter,
          valid=valid,
          cancel=args.cancel,
          donotsell=args.donotsell,
          price=args.price,
          pstoplimit=args.pstoplimit,
      )
  
      # Live data ... avoid long data accumulation by switching to "exactbars"
      cerebro.run(exactbars=args.exactbars)
  
      if args.plot and args.exactbars < 1:  # plot if possible
          cerebro.plot()
  
file_path: backtrader/samples/vctest/vctest.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import argparse
  import datetime
  import backtrader
  from backtrader.utils import flushfile
  from backtrader.utils.py3 import string_types
label_desc: Use image node_id 1 for calling a global function with example usage: runstrategy() without return types