> For the complete documentation index, see [llms.txt](https://optix-ai.gitbook.io/optix-ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://optix-ai.gitbook.io/optix-ai/trading-bot/example.md).

# Example

Here's a simplified example of a trading bot that uses historical price data based on the sample data provided for Optix AI. This example will demonstrate a basic trading decision based on moving averages:

<figure><img src="https://960623622-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9QN82elwMglbCpIGrdN4%2Fuploads%2FMADoykeX3tmpF7hTKfQg%2F9i78cv8c.PNG?alt=media&amp;token=bd8fb22f-d23e-41c5-be50-a7a232c588fe" alt=""><figcaption></figcaption></figure>

This example uses historical price data, calculates short-term and long-term moving averages, and generates buy and sell signals based on a simple moving average crossover strategy. It then prints the signals in the console.

AI-powered models within Optix AI can execute more complex strategies based on real-time data and advanced algorithms.&#x20;

**Explanation:**

In this code snippet, we simulate a basic trading strategy based on historical price data. The strategy uses two moving averages, a short-term moving average (SMA) and a long-term moving average, to generate buy and sell signals.

1. **Historical Price Data:** We start with simulated historical price data for an asset, including dates and closing prices. This data represents the asset's price over a specific time period.
2. **Moving Averages:** We calculate two moving averages, a short-term (3-day) and a long-term (7-day) moving average. Moving averages are used to smooth out price data and identify trends.
3. **Signal Generation:** We create a 'Signal' column in the DataFrame to represent trading signals. A value of '1' indicates a buy signal, '-1' indicates a sell signal, and '0' indicates no action (hold).
4. **Trading Strategy:** We implement a simple moving average crossover strategy, which is a common technical analysis approach. The strategy generates buy signals when the short-term moving average crosses above the long-term moving average, and sell signals when the short-term moving average crosses below the long-term moving average.

**Illustration:**

Here's an illustration of how the code works using a simplified dataset:

<figure><img src="https://960623622-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9QN82elwMglbCpIGrdN4%2Fuploads%2FscAcELaymqqk0ztDTrqz%2Fh998vp%5B98v.PNG?alt=media&amp;token=33215f35-7f69-46ab-ae69-4724e6e8772c" alt=""><figcaption></figcaption></figure>

In this illustration, the trading strategy generates a 'Buy' signal on January 14, 2022, when the short-term moving average (SMA) crosses above the long-term moving average. It generates a 'Sell' signal when the SMA crosses below the long-term moving average. The 'Signal' column reflects these buy and sell signals.

Please note that this is a simplified example Optix AI is much more sophisticated and relies on advanced AI models and real-time data analysis.
