by ABXK.AIAI Trading

Building an AI Trading System: Our Progress So Far

machine-learningtradingneural-networkspythonpytorch

What Is This Project About?

We are building a trading system called NeuralTradeZ. It uses artificial intelligence to help make better trading decisions. The special thing about it is that it learns from its own mistakes and gets better over time.

In this article, we will show you what we have done so far and what challenges we still face.

How Does It Work?

Our system has four main parts:

  1. Neural Network - This learns patterns from past trades
  2. Transformer Model - This checks if trading signals are good
  3. AI Analyzer - This looks at different market indicators
  4. Backtester - This tests trades on old data to see if they would work

The clever part is that when a trade wins or loses, the system remembers this and adjusts itself. This means it should get smarter over time.

Our Results: Before and After

Where We Started

When we first measured our system, the results were not good:

Initial System Performance
What We MeasuredResult
Win Rate16.6%
Average Profit-0.04%
Trades Hitting Stop Loss65%
AI Accuracy51.9%

With only 16.6% of trades winning, we were losing money.

Where We Are Now

After making several improvements, our results are better:

Performance Comparison
MeasurementBeforeAfterChange
Win Rate16.6%20.1%+3.5%
Average Profit-0.04%+0.01%Now Positive
Stop Loss Rate65%62.8%-2.2%
AI Accuracy51.9%54.2%+2.3%

The system now makes a small profit instead of losing money. This is an important step forward.

What Changes Did We Make?

1. We Made Stop Losses Wider

The biggest problem was that 65% of our trades were stopped out too early. The price would move against us a little bit, trigger the stop loss, and then move in the direction we wanted.

We changed the stop loss distance from 1.2 to 1.5 times the average price movement. This gave trades more room to work.

# Before: Stop loss was too close
risk_distance = atr * 1.2

# After: Stop loss has more room
risk_distance = atr * 1.5

This one change reduced failed trades from 65% to 62.8%.

2. We Chose Better Stocks

We found that some stocks work much better than others for our system:

Stocks That Work Well:

  • JPM (bank): 31.3% win rate
  • BTC-USD (bitcoin): 28.1% win rate
  • HD (home improvement): 26.3% win rate
  • AMZN (amazon): 23.1% win rate

Stocks We Removed (Too Many Losses):

  • NFLX: 0% win rate
  • PG: 0% win rate
  • GS: 4.2% win rate
  • ETH-USD: 6.7% win rate
  • GOOGL: 8.3% win rate

By only trading stocks that work well with our system, we improved our results.

3. We Found the Best Time Period

We tested different time periods for our charts. The results were very different:

Time Period Comparison
Time PeriodWin Rate
4 hours21.2% [Best]
1 hour19.7%
1 day16.7%

The 4-hour chart gives the best results. It is not too fast (like 1 hour) and not too slow (like 1 day).

4. We Improved How the AI Learns

We made several changes to help the AI learn better:

  • More patience - We let the AI train longer before stopping
  • Balanced data - We gave it equal amounts of winning and losing examples
  • Smaller steps - The AI makes smaller adjustments, which is more accurate
  • Save best version - We keep the best version of the AI, not the last one

Problems We Still Have

Problem 1: Win Rate Is Still Low

A 20.1% win rate is better than 16.6%, but professional systems usually aim for 30% or higher. We are looking at:

  • Moving stop losses up when trades go well
  • Using multiple time periods together
  • Adding news and social media analysis

Problem 2: Not Enough Training Data

We only have 293 completed trades to learn from. AI systems usually need thousands of examples to learn well.

Our solution: We keep running more tests to create more training data.

Problem 3: Markets Change

A system that works in a rising market might not work in a falling market. We are working on ways to detect what kind of market we are in.

Problem 4: Learning the Wrong Things

With limited data, the AI might learn patterns that do not really exist. We prevent this by:

  • Stopping training before it memorizes the data
  • Testing on data the AI has never seen
  • Retraining regularly with new data

The Technology We Use

Here is what we built the system with:

  • Programming Language: Python 3.12
  • Web Server: Flask 3.0
  • AI Library: PyTorch 2.0
  • Market Data: yfinance
  • Database: SQLite with SQLAlchemy
  • AI Models: LSTM and Transformer networks

What We Will Do Next

Our plans for the next few weeks:

  1. Moving Stop Losses - Automatically move stop losses up to lock in profits
  2. More Data - Get to 1000+ test trades before training again
  3. Focus on 4h Charts - Use our best-performing time period
  4. Combine Models - Use both AI models together for better predictions

What We Learned

Here are the most important lessons from this project:

  1. Understand the problem first. Before writing code, we needed to understand why trades were failing.
  2. Give trades more room. Making stop losses wider worked better than making entry rules stricter.
  3. Some stocks just do not work. It is better to remove bad performers than to try to fix them.
  4. AI needs time to learn. Stopping training too early meant the AI could not learn complex patterns.
  5. Measure everything. Without good data, you cannot know if changes help or hurt.

Final Thoughts

Building a profitable AI trading system takes a long time. We have made good progress - the system now makes money instead of losing it. But we still have work to do before it is ready for real trading.

We will continue to improve it and share our progress.

Important: This is an experimental project. Results from testing do not mean you will make money in real trading. Never invest money you cannot afford to lose.