# Custom Strategies

## Strategy Lab Overview

Build, test, and deploy custom strategies without coding.

**Access:** Strategy Lab in main navigation

## Building Your First Strategy

### Main Components

1. **Entry Conditions** - When to open positions, 2. **Exit Conditions** - When to close positions, 3. **Risk Management** - Position sizing and stops, 4. **Indicators** - Technical analysis tools

### Creating Entry Rules

**Logical operators:** AND (all must be true), OR (any triggers), NOT (inverse)

**Example entry:**

```
IF (Price crosses above 20 EMA)
AND (RSI < 70)
AND (Volume > Avg Volume × 1.5)
THEN Open Long Position
```

### Defining Exit Rules

**Exit types:** Take profit (price/%), stop loss (price/%), trailing stop, indicator-based, time-based

**Example exit:**

```
Exit Position IF:
- Take Profit: +3% from entry
- Stop Loss: -1.5% from entry
- OR RSI crosses below 30
```

## Custom Indicators

### Built-In Indicators by Category

| Category       | Indicators                                                 |
| -------------- | ---------------------------------------------------------- |
| **Trend**      | MA (SMA, EMA, WMA), MACD, Parabolic SAR, ADX               |
| **Momentum**   | RSI, Stochastic, Williams %R, Momentum                     |
| **Volatility** | Bollinger Bands, ATR, Keltner Channels, Standard Deviation |
| **Volume**     | Volume, OBV, VWAP, Accumulation/Distribution               |

### Indicator Configuration

**Each indicator has customizable parameters:** Moving Average: Period (20 default), Type (EMA/SMA/WMA), Data source (Close/Open/High/Low), RSI: Period (14 default), Overbought (70), Oversold (30)

### Combining Indicators

**Example sophisticated signal:**

```
Entry:
- 9 EMA crosses above 21 EMA
- AND MACD histogram positive
- AND Volume > 20-period average

Exit:
- Price touches upper Bollinger Band
- OR MACD bearish divergence
```

## Position Sizing

### Sizing Methods

| Method               | How It Works                             | Best For                 |
| -------------------- | ---------------------------------------- | ------------------------ |
| **Fixed Amount**     | Exact dollar amount per position         | Simple, predictable      |
| **% of Capital**     | X% of total account                      | Auto-adjusts with growth |
| **Volatility-Based** | Larger in low vol, smaller in high vol   | Market-adaptive          |
| **Risk-Based**       | Size to risk fixed amount per trade      | Professional approach    |
| **Kelly Criterion**  | Optimal sizing from win rate/risk-reward | Advanced users only      |

### Examples

## Risk Management Rules

### Stop Loss Configuration

**Types:** Fixed %, fixed $, ATR-based, support/resistance levels, indicator-based **Trailing stops:** Trail by %, trail by ATR, activate after profit threshold

### Take Profit Strategies

| Approach               | Method                                         |
| ---------------------- | ---------------------------------------------- |
| **Single Target**      | Close entire position at one price             |
| **Multiple Targets**   | 50% at +2%, 25% at +4%, 25% trail with 1% stop |
| **Risk/Reward Ratios** | Set TP as multiple of SL (e.g., 2:1 ratio)     |

## Backtesting Custom Strategies

### Configure Backtest

**Required:** Time period, trading pair, initial capital, commission/fees, slippage assumptions **Optional:** Market hours only, exclude volatile periods, max concurrent positions

### Key Metrics

**Visualization:** Equity curve, drawdown chart, trade distribution, monthly returns heatmap

### Optimization

**Parameter tuning:** Test ranges, find optimal values, avoid overfitting **Walk-forward analysis:** Test multiple periods, verify consistency, detect parameter drift

## Strategy Templates

### Quick Start Templates

| Template            | Entry                                                      | Exit                               | Position Size       |
| ------------------- | ---------------------------------------------------------- | ---------------------------------- | ------------------- |
| **Trend Following** | Price > 50 EMA AND 20 EMA > 50 EMA                         | Price < 20 EMA OR -2% stop         | 2% risk             |
| **Mean Reversion**  | Price < Lower BB AND RSI < 30                              | Price > Middle BB OR +3% profit    | Fixed $5,000        |
| **Breakout**        | Price > 20-day high AND Volume > 2x avg                    | Trailing 2x ATR OR -1.5% stop      | Volatility-adjusted |
| **Range Trading**   | Long at support + RSI < 35, Short at resistance + RSI > 65 | Middle of range OR opposite signal | 1.5% risk           |

## Advanced Features

### Multi-Timeframe Analysis

```
Daily: Trend direction (EMA)
4-Hour: Entry timing (RSI)
1-Hour: Exact entry (price action)
```

### Market Regime Detection

```
IF Trending (ADX > 25):
  Use trend-following rules
ELSE IF Ranging (ADX < 20):
  Use mean-reversion rules
```

### Custom Formulas

```
Custom Indicator = (Close - SMA(Close, 20)) / ATR(14)

IF Custom Indicator > 2:
  Strong bullish signal
```

## Deploying Your Strategy

### Pre-Deployment Checklist


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://quantsedge.gitbook.io/quantsedge-docs/trading-strategies/custom-strategies.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
