code: def risk_managed_order(
      side: "TradeSide",
      trade_type: "TradeType",
      exchange_pair: "ExchangePair",
      price: float,
      quantity: "Quantity",
      down_percent: float,
      up_percent: float,
      portfolio: "Portfolio",
      start: int = None,
      end: int = None,
  ):
      """Create a stop order that manages for percentages above and below the
      entry price of the order.
  
      Parameters
      ----------
      side : `TradeSide`
          The side of the order.
      trade_type : `TradeType`
          The type of trade to make when going in.
      exchange_pair : `ExchangePair`
          The exchange pair to perform the order for.
      price : float
          The current price.
      down_percent: float
          The percentage the price is allowed to drop before exiting.
      up_percent : float
          The percentage the price is allowed to rise before exiting.
      quantity : `Quantity`
          The quantity of the order.
      portfolio : `Portfolio`
          The portfolio being used in the order.
      start : int, optional
          The start time of the order.
      end : int, optional
          The end time of the order.
  
      Returns
      -------
      `Order`
          A stop order controlling for the percentages above and below the entry
          price.
      """
  
      side = TradeSide(side)
      instrument = side.instrument(exchange_pair.pair)
  
      order = Order(
          step=portfolio.clock.step,
          side=side,
          trade_type=TradeType(trade_type),
          exchange_pair=exchange_pair,
          price=price,
          start=start,
          end=end,
          quantity=quantity,
          portfolio=portfolio,
      )
  
      risk_criteria = Stop("down", down_percent) ^ Stop(
          "up", up_percent
      )
      risk_management = OrderSpec(
          side=TradeSide.SELL
          if side == TradeSide.BUY
          else TradeSide.BUY,
          trade_type=TradeType.MARKET,
          exchange_pair=exchange_pair,
          criteria=risk_criteria,
      )
  
      order.add_order_spec(risk_management)
  
      return order
  
file_path: tensortrade/tensortrade/oms/orders/create.py
imports: from tensortrade.oms.instruments import ExchangePair
  from tensortrade.oms.wallets import Portfolio
  from tensortrade.oms.orders import Order, OrderSpec, TradeSide, TradeType
  from tensortrade.oms.orders.criteria import Stop, Limit
label_desc: Use image node_id 4 for calling a global function with example usage: risk_managed_order(side, trade_type, exchange_pair, price, quantity, down_percent, up_percent, portfolio, start, end) and returns: order