code: def _handle_buy_sell_decision(context, data, signal, price):
      orders = get_open_orders(context.asset)
      if len(orders) > 0:
          log.info("skipping bar until all open orders execute")
          return
  
      positions = context.portfolio.positions
      if context.position is None and context.asset in positions:
          position = positions[context.asset]
          context.position = dict(
              cost_basis=position["cost_basis"],
              amount=position["amount"],
              stop=None,
          )
  
      # action = None
      if context.position is not None:
          cost_basis = context.position["cost_basis"]
          amount = context.position["amount"]
          log.info(
              "found {amount} positions with cost basis {cost_basis}".format(
                  amount=amount, cost_basis=cost_basis
              )
          )
          stop = context.position["stop"]
  
          target = cost_basis * (1 + context.TARGET)
          if price >= target:
              context.position["cost_basis"] = price
              context.position["stop"] = context.STOP
  
          stop_target = (
              context.STOP_LOSS if stop is None else context.STOP
          )
          if price < cost_basis * (1 - stop_target):
              log.info("executing stop loss")
              order(
                  asset=context.asset,
                  amount=-amount,
                  limit_price=price * (1 - context.SLIPPAGE_ALLOWED),
              )
              # action = 0
              context.position = None
  
      else:
          if signal == "long":
              log.info("opening position")
              buy_amount = context.MAX_HOLDINGS / price
              order(
                  asset=context.asset,
                  amount=buy_amount,
                  limit_price=price * (1 + context.SLIPPAGE_ALLOWED),
              )
              context.position = dict(
                  cost_basis=price, amount=buy_amount, stop=None
              )
  
file_path: catalyst/catalyst/examples/rsi_profit_target.py
imports: from datetime import timedelta
  import pandas
  import numpy
  import talib
  from logbook import Logger
  from catalyst.api import order, symbol, record, get_open_orders
  from catalyst.utils.run_algo import run_algorithm
label_desc: Use image node_id 2 for calling a global function with example usage: _handle_buy_sell_decision(context, data, signal, price) without return types