code: def trade_system(model, system, space, intraday, name, quantity):
      r"""Trade the given system.
  
      Parameters
      ----------
      model : alphapy.Model
          The model object with specifications.
      system : alphapy.System
          The long/short system to run.
      space : alphapy.Space
          Namespace of instrument prices.
      intraday : bool
          If True, then run an intraday system.
      name : str
          The symbol to trade.
      quantity : float
          The amount of the ``name`` to trade, e.g., number of shares
  
      Returns
      -------
      tradelist : list
          List of trade entries and exits.
  
      Other Parameters
      ----------------
      Frame.frames : dict
          All of the data frames containing price data.
  
      """
  
      # Unpack the model data.
  
      directory = model.specs["directory"]
      extension = model.specs["extension"]
      separator = model.specs["separator"]
  
      # Unpack the system parameters.
  
      longentry = system.longentry
      shortentry = system.shortentry
      longexit = system.longexit
      shortexit = system.shortexit
      holdperiod = system.holdperiod
      scale = system.scale
  
      # Determine whether or not this is a model-driven system.
  
      entries_and_exits = [longentry, shortentry, longexit, shortexit]
      active_signals = [x for x in entries_and_exits if x is not None]
      use_model = False
      for signal in active_signals:
          if any(x in signal for x in ["phigh", "plow"]):
              use_model = True
  
      # Read in the price frame
      pf = Frame.frames[frame_name(name, space)].df
  
      # Use model output probabilities as input to the system
  
      if use_model:
          # get latest probabilities file
          probs_dir = SSEP.join([directory, "output"])
          file_path = most_recent_file(probs_dir, "probabilities*")
          file_name = file_path.split(SSEP)[-1].split(".")[0]
          # read the probabilities frame and trim the price frame
          probs_frame = read_frame(
              probs_dir, file_name, extension, separator
          )
          pf = pf[-probs_frame.shape[0] :]
          probs_frame.index = pf.index
          probs_frame.columns = ["probability"]
          # add probability column to price frame
          pf = pd.concat([pf, probs_frame], axis=1)
  
      # Evaluate the long and short events in the price frame
  
      for signal in active_signals:
          vexec(pf, signal)
  
      # Initialize trading state variables
  
      inlong = False
      inshort = False
      h = 0
      p = 0
      q = quantity
      tradelist = []
  
      # Loop through prices and generate trades
  
      for dt, row in pf.iterrows():
          # get closing price
          c = row["close"]
          if intraday:
              bar_number = row["bar_number"]
              end_of_day = row["end_of_day"]
          # evaluate entry and exit conditions
          lerow = row[longentry] if longentry else None
          serow = row[shortentry] if shortentry else None
          lxrow = row[longexit] if longexit else None
          sxrow = row[shortexit] if shortexit else None
          # process the long and short events
          if lerow:
              if p < 0:
                  # short active, so exit short
                  tradelist.append((dt, [name, Orders.sx, -p, c]))
                  inshort = False
                  h = 0
                  p = 0
              if p == 0 or scale:
                  # go long (again)
                  tradelist.append((dt, [name, Orders.le, q, c]))
                  inlong = True
                  p = p + q
          elif serow:
              if p > 0:
                  # long active, so exit long
                  tradelist.append((dt, [name, Orders.lx, -p, c]))
                  inlong = False
                  h = 0
                  p = 0
              if p == 0 or scale:
                  # go short (again)
                  tradelist.append((dt, [name, Orders.se, -q, c]))
                  inshort = True
                  p = p - q
          # check exit conditions
          if inlong and h > 0 and lxrow:
              # long active, so exit long
              tradelist.append((dt, [name, Orders.lx, -p, c]))
              inlong = False
              h = 0
              p = 0
          if inshort and h > 0 and sxrow:
              # short active, so exit short
              tradelist.append((dt, [name, Orders.sx, -p, c]))
              inshort = False
              h = 0
              p = 0
          # if a holding period was given, then check for exit
          if holdperiod and h >= holdperiod:
              if inlong:
                  tradelist.append((dt, [name, Orders.lh, -p, c]))
                  inlong = False
              if inshort:
                  tradelist.append((dt, [name, Orders.sh, -p, c]))
                  inshort = False
              h = 0
              p = 0
          # increment the hold counter
          if inlong or inshort:
              h += 1
              if intraday and end_of_day:
                  if inlong:
                      # long active, so exit long
                      tradelist.append((dt, [name, Orders.lx, -p, c]))
                      inlong = False
                  if inshort:
                      # short active, so exit short
                      tradelist.append((dt, [name, Orders.sx, -p, c]))
                      inshort = False
                  h = 0
                  p = 0
      return tradelist
  
imports: from alphapy.frame import Frame
  from alphapy.frame import frame_name
  from alphapy.frame import read_frame
  from alphapy.frame import write_frame
  from alphapy.globals import Orders
  from alphapy.globals import BSEP, SSEP
  from alphapy.variables import vexec
  from alphapy.space import Space
  from alphapy.portfolio import Trade
  from alphapy.utilities import most_recent_file
  import logging
  import numbers
  import pandas
  from pandas import DataFrame
label_desc: Use image node_id 1 for calling a global function with example usage: trade_system(model, system, space, intraday, name, quantity) and returns: tradelist