> ## Documentation Index
> Fetch the complete documentation index at: https://takeprofit.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Package indie.strategies

export const Anchor = ({id}) => {
  return <div id={id} style={{
    scrollMarginTop: "var(--scroll-mt)"
  }}></div>;
};

export const Field = ({id, name, type, required, defaultVal, children}) => {
  return <div id={id} style={{
    scrollMarginTop: "var(--scroll-mt)"
  }} className="mt-4">
      <div className="pt-2.5 pb-5 my-2.5 border-gray-50 dark:border-gray-800/50 border-b">
        <div className="flex font-mono text-sm group/param-head param-head">
          <div className="flex-1 flex content-start py-0.5 mr-5">
            <div className="flex items-center flex-wrap gap-2">
              {id && <div className="absolute">
                  <a href={`#${id}`} className="-ml-10 flex items-center opacity-0 border-0 group-hover/param-head:opacity-100 py-2" aria-label={`Navigate to ${id}`}>
                    <div className="w-6 h-6 text-gray-400 rounded-md flex items-center justify-center zinc-box bg-white ring-1 ring-gray-400/30 dark:ring-gray-700/25 hover:ring-gray-400/60 dark:hover:ring-white/20">
                      <svg xmlns="http://www.w3.org/2000/svg" fill="gray" height="12px" viewBox="0 0 576 512">
                        <path d="M0 256C0 167.6 71.6 96 160 96h72c13.3 0 24 10.7 24 24s-10.7 24-24 24H160C98.1 144 48 194.1 48 256s50.1 112 112 112h72c13.3 0 24 10.7 24 24s-10.7 24-24 24H160C71.6 416 0 344.4 0 256zm576 0c0 88.4-71.6 160-160 160H344c-13.3 0-24-10.7-24-24s10.7-24 24-24h72c61.9 0 112-50.1 112-112s-50.1-112-112-112H344c-13.3 0-24-10.7-24-24s10.7-24 24-24h72c88.4 0 160 71.6 160 160zM184 232H392c13.3 0 24 10.7 24 24s-10.7 24-24 24H184c-13.3 0-24-10.7-24-24s10.7-24 24-24z"></path>
                      </svg>
                    </div>
                  </a>
                </div>}
              <div className="font-semibold text-primary dark:text-primary-light">
                {name}
              </div>
              <div className="flex items-center space-x-2 text-xs font-medium">
                <div className="flex items-center px-2 py-0.5 rounded-md bg-gray-100/50 dark:bg-white/5 text-gray-600 dark:text-gray-200 font-medium">
                  {type}
                </div>
                {required && <span className="px-2 py-0.5 rounded-md bg-red-100/50 dark:bg-red-400/10 text-red-600 dark:text-red-300 font-medium">
                    required
                  </span>}
                {defaultVal && <div className="flex items-center px-2 py-0.5 rounded-md bg-gray-100/50 dark:bg-white/5 text-gray-600 dark:text-gray-200 font-medium">
                    <span class="text-gray-400 dark:text-gray-500">default:</span>
                    {defaultVal}
                  </div>}
              </div>
            </div>
          </div>
        </div>
        <div className="mt-4 prose-sm prose-gray dark:prose-invert">
          {children}
        </div>
      </div>
    </div>;
};

Package containing trading functionality for creating and managing orders, positions, and commissions in Indie trading strategies.

***

## Types

<Anchor id="class_AmendOrderBuilder" />

### `AmendOrderBuilder`

*type*

Builder class for modifying existing trading orders with updated parameters.

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_AmendOrderBuilder_size" name="size" type="(size) -> indie.strategies.AmendOrderBuilder">
      Updates the size (quantity) of the existing order.

      <Expandable title="parameters info">
        <Field name="size" type="float" required>
          New size for the existing order.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_AmendOrderBuilder_limit" name="limit" type="(price) -> indie.strategies.AmendOrderBuilder">
      Updates the limit price of the existing order.

      <Expandable title="parameters info">
        <Field name="price" type="float" required>
          New limit price for the existing order.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_AmendOrderBuilder_stop" name="stop" type="(price) -> indie.strategies.AmendOrderBuilder">
      Updates the stop price of the existing order.

      <Expandable title="parameters info">
        <Field name="price" type="float" required>
          New stop price for the existing order.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_AmendOrderBuilder_take_profit" name="take_profit" type="(stop, *, limit) -> indie.strategies.AmendOrderBuilder">
      Updates the take profit settings of the existing order.

      <Expandable title="parameters info">
        <Field name="stop" type="float" required>
          New stop price for the take profit exit order.
        </Field>

        <Field name="limit" type="indie.Optional[float]" defaultVal="None">
          New limit price for the take profit exit order.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_AmendOrderBuilder_stop_loss" name="stop_loss" type="(stop, *, limit) -> indie.strategies.AmendOrderBuilder">
      Updates the stop loss settings of the existing order.

      <Expandable title="parameters info">
        <Field name="stop" type="float" required>
          New stop price for the stop loss exit order.
        </Field>

        <Field name="limit" type="indie.Optional[float]" defaultVal="None">
          New limit price for the stop loss exit order.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_AmendOrderBuilder_submit" name="submit" type="() -> None">
      Builds and submits the order updates to the trading system.
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_Commission" />

### `Commission`

*type*

Represents trading commission settings with configurable commission type and value.

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_Commission_init" name="__init__" type="(value, commission_type) -> None">
      Creates a new Commission object with specified value and commission type.

      <Expandable title="parameters info">
        <Field name="value" type="float" required>
          Numeric value of the commission. For percentage type, should be a decimal (e.g., 0.001 for 0.1%). For fixed type, should be the absolute amount.
        </Field>

        <Field name="commission_type" type="indie.strategies.commission_type" required>
          Type of commission calculation: `PERCENT` or `FIXED`.
        </Field>
      </Expandable>
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_ExitOrder" />

### `ExitOrder`

*type*

Represents exit order settings for take profit and stop loss.

<Steps>
  <Step title="Fields" icon="key">
    <Field id="field_ExitOrder_stop" name="stop" type="float">
      Stop price for the exit order (take profit or stop loss).
    </Field>

    <Field id="field_ExitOrder_limit" name="limit" type="indie.Optional[float]">
      Limit price for the exit order (take profit or stop loss).
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_Order" />

### `Order`

*type*

Represents a trading order with properties for tracking its status, execution type, and parameters.

<Steps>
  <Step title="Fields" icon="key">
    <Field id="field_Order_id" name="id" type="str">
      Unique identifier of the order.
    </Field>

    <Field id="field_Order_status" name="status" type="indie.strategies.order_status">
      Current status of the order.
    </Field>

    <Field id="field_Order_execution_type" name="execution_type" type="indie.strategies.order_execution_type">
      Execution type of the order (market, limit, stop, or stop-limit).
    </Field>

    <Field id="field_Order_side" name="side" type="indie.strategies.order_side">
      Side of the order (buy or sell).
    </Field>

    <Field id="field_Order_size" name="size" type="float">
      Size (quantity) of the order.
    </Field>

    <Field id="field_Order_limit" name="limit" type="indie.Optional[float]">
      Limit price for limit and stop-limit orders. `None` for market and stop orders.
    </Field>

    <Field id="field_Order_stop" name="stop" type="indie.Optional[indie.strategies.Stop]">
      Stop price for stop and stop-limit orders. `None` for market and limit orders.
    </Field>

    <Field id="field_Order_take_profit" name="take_profit" type="indie.Optional[indie.strategies.ExitOrder]">
      Take profit settings for the order. `None` if not set.
    </Field>

    <Field id="field_Order_stop_loss" name="stop_loss" type="indie.Optional[indie.strategies.ExitOrder]">
      Stop loss settings for the order. `None` if not set.
    </Field>
  </Step>

  <Step title="Methods" icon="function">
    <Field id="method_Order_cancel" name="cancel" type="() -> None">
      Cancels the order. Equivalent to calling `Trading.cancel_order()` with this order's ID.
    </Field>

    <Field id="method_Order_amend" name="amend" type="() -> indie.strategies.AmendOrderBuilder">
      Returns a builder for amending this order's parameters. Allows modification of size, limit price, and stop price.
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_PlaceOrderBuilder" />

### `PlaceOrderBuilder`

*type*

Builder class for creating new trading orders with specified parameters.

<Steps>
  <Step title="Methods" icon="function">
    <Field id="method_PlaceOrderBuilder_limit" name="limit" type="(price) -> indie.strategies.PlaceOrderBuilder">
      Sets the limit price for the order. Applicable to create limit and stop-limit orders.

      <Expandable title="parameters info">
        <Field name="price" type="float" required>
          Limit price for limit orders. If specified without `stop`, creates a limit order. If specified with `stop`, creates a stop-limit order.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_PlaceOrderBuilder_stop" name="stop" type="(price, direction) -> indie.strategies.PlaceOrderBuilder">
      Sets the stop price for the order. Applicable to create stop and stop-limit orders.

      <Expandable title="parameters info">
        <Field name="price" type="float" required>
          Stop price for stop orders. If specified without `limit`, creates a stop order. If specified with `limit`, creates a stop-limit order.
        </Field>

        <Field name="direction" type="indie.strategies.trigger_direction" defaultVal="indie.strategies.trigger_direction.AUTO">
          Trigger direction for the stop price: `RISES_TO` or `FALLS_TO`, or `AUTO`.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_PlaceOrderBuilder_take_profit" name="take_profit" type="(stop, *, limit) -> indie.strategies.PlaceOrderBuilder">
      Sets the take profit settings for the order.

      <Expandable title="parameters info">
        <Field name="stop" type="float" required>
          Stop price for the take profit exit order.
        </Field>

        <Field name="limit" type="indie.Optional[float]" defaultVal="None">
          Limit price for the take profit exit order.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_PlaceOrderBuilder_stop_loss" name="stop_loss" type="(stop, *, limit) -> indie.strategies.PlaceOrderBuilder">
      Sets the stop loss settings for the order.

      <Expandable title="parameters info">
        <Field name="stop" type="float" required>
          Stop price for the stop loss exit order.
        </Field>

        <Field name="limit" type="indie.Optional[float]" defaultVal="None">
          Limit price for the stop loss exit order.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_PlaceOrderBuilder_submit" name="submit" type="() -> indie.strategies.Order">
      Builds and submits the new order to the trading system. Returns the created `Order` object.
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_Position" />

### `Position`

*type*

Represents a current trading position with size and entry price information.

<Steps>
  <Step title="Fields" icon="key">
    <Field id="field_Position_size" name="size" type="float">
      Current position size. Positive for long positions, negative for short positions, zero for no position.
    </Field>

    <Field id="field_Position_price" name="price" type="float">
      Average entry price of the current position.
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_Stop" />

### `Stop`

*type*

Represents trigger settings for a stop-order.

<Steps>
  <Step title="Fields" icon="key">
    <Field id="field_Stop_price" name="price" type="float">
      Trigger price for the stop order.
    </Field>

    <Field id="field_Stop_direction" name="direction" type="indie.strategies.trigger_direction">
      The direction in which the market price should go trigger the price of the stop order.
    </Field>
  </Step>
</Steps>

***

<Anchor id="class_Trading" />

### `Trading`

*type*

Main class for executing trading operations including order creation, modification, and cancellation. Provides access to account cash and position information.

<Steps>
  <Step title="Fields" icon="key">
    <Field id="field_Trading_cash" name="cash" type="float">
      Available cash balance allocated to the strategy.
    </Field>

    <Field id="field_Trading_position" name="position" type="indie.strategies.Position">
      Current position object containing size and entry price.
    </Field>
  </Step>

  <Step title="Methods" icon="function">
    <Field id="method_Trading_place_order" name="place_order" type="(side, size) -> indie.strategies.PlaceOrderBuilder">
      Returns a builder for placing a new trading order with specified side and size.

      <Expandable title="parameters info">
        <Field name="side" type="indie.strategies.order_side" defaultVal="indie.strategies.order_side.BUY">
          Side of the order (buy or sell). Default is `BUY`.
        </Field>

        <Field name="size" type="float" defaultVal="1.0">
          Size (quantity) of the order. Default is `1.0`.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_Trading_amend_order" name="amend_order" type="(id) -> indie.strategies.AmendOrderBuilder">
      Returns a builder to amend an existing order's parameters by its ID.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Unique identifier of the order to update.
        </Field>
      </Expandable>
    </Field>

    <Field id="method_Trading_cancel_order" name="cancel_order" type="(id) -> None">
      Cancels an existing order by its ID.

      <Expandable title="parameters info">
        <Field name="id" type="str" required>
          Unique identifier of the order to cancel.
        </Field>
      </Expandable>
    </Field>
  </Step>
</Steps>

***

## Enums

<Anchor id="enum_commission_type" />

### `commission_type`

*enum*

Enum representing the type of commission calculation.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_commission_type_PERCENT" name="PERCENT" type="indie.strategies.commission_type">
      Commission calculated as a percentage of the trade value (e.g., 0.001 for 0.1%).
    </Field>

    <Field id="const_commission_type_FIXED" name="FIXED" type="indie.strategies.commission_type">
      Commission calculated as a fixed amount per trade (e.g., 0.01 for \$0.01).
    </Field>
  </Step>
</Steps>

***

<Anchor id="enum_intrabar_order_filter" />

### `intrabar_order_filter`

*enum*

Enum defining when orders should be executed within a bar during backtesting.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_intrabar_order_filter_ON_BAR_CLOSE" name="ON_BAR_CLOSE" type="indie.strategies.intrabar_order_filter">
      Execute orders only at bar close.
    </Field>

    <Field id="const_intrabar_order_filter_FIRST_IN_BAR" name="FIRST_IN_BAR" type="indie.strategies.intrabar_order_filter">
      Execute only the first created order in the bar.
    </Field>

    <Field id="const_intrabar_order_filter_LAST_IN_BAR" name="LAST_IN_BAR" type="indie.strategies.intrabar_order_filter">
      Execute only the last created order in the bar.
    </Field>

    <Field id="const_intrabar_order_filter_NO_FILTER" name="NO_FILTER" type="indie.strategies.intrabar_order_filter">
      Execute orders at any time within the bar without filtering.
    </Field>
  </Step>
</Steps>

***

<Anchor id="enum_market_order_price" />

### `market_order_price`

*enum*

Enum defining the price at which market orders are executed in backtesting.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_market_order_price_MARKET_PRICE" name="MARKET_PRICE" type="indie.strategies.market_order_price">
      Use the actual market price at the time of execution.
    </Field>

    <Field id="const_market_order_price_ORDER_CREATION_PRICE" name="ORDER_CREATION_PRICE" type="indie.strategies.market_order_price">
      Use the price at the moment the order was created.
    </Field>

    <Field id="const_market_order_price_BAR_OPEN_PRICE" name="BAR_OPEN_PRICE" type="indie.strategies.market_order_price">
      Use the opening price of the bar.
    </Field>
  </Step>
</Steps>

***

<Anchor id="enum_order_execution_type" />

### `order_execution_type`

*enum*

Enum representing the execution type of a trading order.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_order_execution_type_MARKET" name="MARKET" type="indie.strategies.order_execution_type">
      Market order that executes immediately at the current market price.
    </Field>

    <Field id="const_order_execution_type_LIMIT" name="LIMIT" type="indie.strategies.order_execution_type">
      Limit order that executes at a specified price or better.
    </Field>

    <Field id="const_order_execution_type_STOP" name="STOP" type="indie.strategies.order_execution_type">
      Stop order that becomes a market order when the stop price is reached.
    </Field>

    <Field id="const_order_execution_type_STOP_LIMIT" name="STOP_LIMIT" type="indie.strategies.order_execution_type">
      Stop-limit order that becomes a limit order when the stop price is reached.
    </Field>
  </Step>
</Steps>

***

<Anchor id="enum_order_side" />

### `order_side`

*enum*

Enum representing the side of a trading order.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_order_side_BUY" name="BUY" type="indie.strategies.order_side">
      Buy side for a trading order.
    </Field>

    <Field id="const_order_side_SELL" name="SELL" type="indie.strategies.order_side">
      Sell side for a trading order.
    </Field>
  </Step>
</Steps>

***

<Anchor id="enum_order_status" />

### `order_status`

*enum*

Enum representing the current status of a trading order.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_order_status_CREATED" name="CREATED" type="indie.strategies.order_status">
      Order has been created locally but not yet sent to the exchange.
    </Field>

    <Field id="const_order_status_PLACED" name="PLACED" type="indie.strategies.order_status">
      Order has been accepted by the exchange and entered the order book.
    </Field>

    <Field id="const_order_status_PENDING_PLACED" name="PENDING_PLACED" type="indie.strategies.order_status">
      Order is waiting for a trigger condition to be met and has not yet entered the order book.
    </Field>

    <Field id="const_order_status_PARTIALLY_FILLED" name="PARTIALLY_FILLED" type="indie.strategies.order_status">
      Order has been partially filled and remains open.
    </Field>

    <Field id="const_order_status_FILLED" name="FILLED" type="indie.strategies.order_status">
      Order has been completely filled.
    </Field>

    <Field id="const_order_status_PARTIALLY_FILLED_CLOSED" name="PARTIALLY_FILLED_CLOSED" type="indie.strategies.order_status">
      Order has been partially filled and then closed without full execution.
    </Field>

    <Field id="const_order_status_REJECTED" name="REJECTED" type="indie.strategies.order_status">
      Order has been rejected by the exchange.
    </Field>

    <Field id="const_order_status_CANCELED" name="CANCELED" type="indie.strategies.order_status">
      Order has been canceled by the strategy or by the exchange.
    </Field>
  </Step>
</Steps>

***

<Anchor id="enum_trigger_direction" />

### `trigger_direction`

*enum*

Enum representing the direction of a stop order trigger.

<Steps>
  <Step title="Static fields" icon="cubes">
    <Field id="const_trigger_direction_RISES_TO" name="RISES_TO" type="indie.strategies.trigger_direction">
      Stop order is triggered when the market price rises to or above the stop price.
    </Field>

    <Field id="const_trigger_direction_FALLS_TO" name="FALLS_TO" type="indie.strategies.trigger_direction">
      Stop order is triggered when the market price falls to or below the stop price.
    </Field>

    <Field id="const_trigger_direction_AUTO" name="AUTO" type="indie.strategies.trigger_direction">
      The system automatically determines the trigger direction based on the current market price and specified stop price. If the stop price is above the current market price, it triggers on rise; if below, it triggers on fall.
    </Field>
  </Step>
</Steps>

***
