# Running a simulation

Before risking real capital, you should always test your trading strategy against historical market data. Tradecraft's backtesting simulator runs your strategy against actual past signals and price movements, showing you exactly how it would have performed.

**Why backtest your strategies?**

* **Validate your strategy** works as expected
* **See real performance** on historical data
* **Build confidence** before going live
* **Identify issues** in your trading logic
* **Compare different approaches** to find what works best

### What is a Backtest?

A backtest simulation:

1. Takes your strategy code
2. Replays the signals your strategy received over the time period you specify
3. Simulates buying and selling based on your strategy rules
4. Shows you the profit/loss you would have made

The simulator uses **real historical prices** and **actual signals** that your data sources sent, so results accurately reflect what would have happened if you had been trading live during that time period.

### How to Run a Backtest

#### Step 1: Open the Development Tab

<figure><img src="https://3175477167-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYCh2t4HDhRRiAIqY93vK%2Fuploads%2FYi8280v3G6BUHI4mzSZQ%2Fimage.png?alt=media&#x26;token=47e82900-200d-4bab-b387-7abb8dc24758" alt=""><figcaption><p>The simulation runs the strategy over the selected time period.</p></figcaption></figure>

Navigate to your strategy and click the **Development** tab. You'll see:

* **Strategy Editor** (left side) - Your strategy code, including the **Run** button to start a simulation
* **Start and End** (right side) **-** Select the start and end simulation period in the signal table
* **Results** (bottom) - The simulation results after running

#### Step 2: Run the Simulation

Click **Run** and wait for the results. The simulator will:

1. Load all your historical signals from the selected data sources
2. Run your strategy against each signal's price history
3. Calculate your profit/loss and performance metrics

**Note:** Large date ranges with many signals takes longer time to complete.

### Understanding Your Results

After the simulation completes, you'll see several key metrics

<figure><img src="https://3175477167-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYCh2t4HDhRRiAIqY93vK%2Fuploads%2FG8D9nJ2lRfT7peoibFUM%2Fimage.png?alt=media&#x26;token=e04d7e2f-7ce3-4074-a7b7-2b4f6831b04d" alt="" width="563"><figcaption><p>Result table after the simulation has completed. This is a chronological log of the actions taken and portfolio evolution.</p></figcaption></figure>

#### Summary Metrics

**Initial Wallet**

* The starting capital you configured (e.g., 5 SOL)

**Total Remaining**

* How much SOL you have left in your wallet, plus the SOL value of the tokens held in the wallet but not yet sold

**Unrealized**

* Value of tokens you're still holding at the last known price
* These are open positions that haven't been sold yet

#### Trade Details

For each token traded, you'll see:

* **Token Address** - Which token was traded
* **Entry Price** - Price when you bought
* **Amount** - The amount in SOL that was bought
* **Unrealized** - The sum of the SOL value of all the tokens held in the wallet at that point and not yet sold.
* **Wallet** - The SOL balance of the wallet at that point in time
* **Decision** - Whether it's a buy or a sell
* **Price gain** - The multiplier when selling, for instance a 100% price increase is a 2x.
* **Price** - The USD price at the time of the buy or sell
* **Event time** - When the buy or sell took place

### Tips for Effective Backtesting

#### Start with Recent Data

When first testing a strategy:

* Use the **last 2-5 days** of data
* Verify your strategy logic works correctly
* Check that you're seeing the trades you expect

Once validated, expand to longer time periods for more comprehensive testing.

#### Test Different Market Conditions

Markets behave differently at different times. Test your strategy on:

* **Trending markets** - When prices are generally going up or down
* **Volatile periods** - High price swings and rapid changes
* **Quiet periods** - Low volatility with stable prices

A good strategy should work reasonably well in different conditions, not just one type of market.

#### Compare Trade Sizes

Try your backtest with different trade size settings:

* **Small fixed amounts** (0.1 SOL) - Lower risk, steadier growth
* **Larger fixed amounts** (0.5-1 SOL) - Higher risk, bigger wins and losses
* **Percentage-based** (2-5%) - Dynamic sizing that scales with your wallet

See which approach gives you the best balance of profit and risk for your style.

#### Check Signal Volume

Look at how many signals your strategy received during the test period:

* **Too few signals** (< 5 per day) - Your strategy or filters might be too restrictive
* **Too many signals** (> 50 per day) - You may be overtrading, which increases costs in live trading

#### Review Individual Trades

Don't just look at overall profit - examine individual trades:

* **Which tokens performed well?** - Look for patterns in successful trades
* **Which tokens lost money?** - Understand what went wrong
* **Are you exiting too early?** - Check maximum price vs. your exit price
* **Are you holding too long?** - See if profits evaporated after peaks

Use these insights to refine your strategy's buy and sell logic.

### What Backtesting Can and Cannot Tell You

#### Backtesting IS Good For:

✅ Validating your strategy logic works correctly ✅ Seeing how your strategy would have performed historically ✅ Comparing different strategy approaches ✅ Identifying obvious flaws or bugs in your code ✅ Building confidence in your trading approach

#### Backtesting CANNOT:

❌ Predict future performance with certainty ❌ Account for all real-world trading costs and slippage ❌ Guarantee you'll make the same returns live ❌ Replace careful live monitoring ❌ Tell you when market conditions will change

**Golden Rule:** Use backtesting as **one tool** in your strategy validation process, not as a guarantee of success.

#### Avoiding "Overfitting"

**Overfitting** means optimizing your strategy so specifically for historical data that it fails on new data.

**Warning Signs:**

* Extremely high returns (>1000% ROI) that seem too good to be true
* Strategy with very complex rules tailored to specific past events
* Works great on training data but fails immediately when live

**How to Avoid:**

* Keep your strategy simple - simpler is often better
* Test on multiple different time periods
* Don't over-optimize to squeeze out every last percentage point
* If it seems too good to be true, it probably is
