code: def runstrat(args=None):
      args = parse_args(args)
  
      cerebro = bt.Cerebro()
      cerebro.broker.set_cash(args.cash)
      comminfo = bt.commissions.CommInfo_Stocks_Perc(
          commission=args.commperc, percabs=True
      )
  
      cerebro.broker.addcommissioninfo(comminfo)
  
      dkwargs = dict()
      if args.fromdate is not None:
          fromdate = datetime.datetime.strptime(
              args.fromdate, "%Y-%m-%d"
          )
          dkwargs["fromdate"] = fromdate
  
      if args.todate is not None:
          todate = datetime.datetime.strptime(args.todate, "%Y-%m-%d")
          dkwargs["todate"] = todate
  
      # if dataset is None, args.data has been given
      dataname = DATASETS.get(args.dataset, args.data)
      data0 = bt.feeds.YahooFinanceCSVData(dataname=dataname, **dkwargs)
      cerebro.adddata(data0)
  
      cerebro.addstrategy(
          TheStrategy,
          macd1=args.macd1,
          macd2=args.macd2,
          macdsig=args.macdsig,
          atrperiod=args.atrperiod,
          atrdist=args.atrdist,
          smaperiod=args.smaperiod,
          dirperiod=args.dirperiod,
      )
  
      cerebro.addsizer(FixedPerc, perc=args.cashalloc)
  
      # Add TimeReturn Analyzers for self and the benchmark data
      cerebro.addanalyzer(
          bt.analyzers.TimeReturn,
          _name="alltime_roi",
          timeframe=bt.TimeFrame.NoTimeFrame,
      )
  
      cerebro.addanalyzer(
          bt.analyzers.TimeReturn,
          data=data0,
          _name="benchmark",
          timeframe=bt.TimeFrame.NoTimeFrame,
      )
  
      # Add TimeReturn Analyzers fot the annuyl returns
      cerebro.addanalyzer(
          bt.analyzers.TimeReturn, timeframe=bt.TimeFrame.Years
      )
      # Add a SharpeRatio
      cerebro.addanalyzer(
          bt.analyzers.SharpeRatio,
          timeframe=bt.TimeFrame.Years,
          riskfreerate=args.riskfreerate,
      )
  
      # Add SQN to qualify the trades
      cerebro.addanalyzer(bt.analyzers.SQN)
      cerebro.addobserver(
          bt.observers.DrawDown
      )  # visualize the drawdown evol
  
      results = cerebro.run()
      st0 = results[0]
  
      for alyzer in st0.analyzers:
          alyzer.print()
  
      if args.plot:
          pkwargs = dict(style="bar")
          if args.plot is not True:  # evals to True but is not True
              npkwargs = eval(
                  "dict(" + args.plot + ")"
              )  # args were passed
              pkwargs.update(npkwargs)
  
          cerebro.plot(**pkwargs)
  
file_path: backtrader/samples/macd-settings/macd-settings.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import argparse
  import datetime
  import random
  import backtrader
label_desc: Use image node_id 1 for calling a global function with example usage: runstrat(args) without return types