How to create a forex trading bot in Python using AI
This article and video demonstrate how to create a free Python trading bot for cTrader with AI.
Note
cTrader is the only major platform offering native Python support, allowing anyone to create powerful Python robots to automate trading strategies. No adapter or complex workaround is involved.
While ChatGPT is used for the demonstration, the same steps for creating trading bots with AI apply to Gemini, Claude, DeepSeek and others.
Select a Python template
Open cTrader Algo in cTrader Windows or Mac, then click New to start creating a new trading bot.

In the algorithm creation wizard, build a new algorithm and give it a name.

Choose Python as the programming language, then select the Using a template option.
cTrader provides a wide variety of Python templates, covering every strategy type, analysis style or automated trading activity. These pre-built algorithms already contain full trading logic and adjustable parameters, so they are ready to use once you save and build them.
Note
The full collection of algorithm templates is available in the algo creation wizard in cTrader Windows or Mac, and you can also access them in our public repository.
Suppose we specialise in breakout trading. Therefore, we choose Sample Breakout cBot.

Note
Detailed descriptions of popular algorithm templates, including Breakout cBot, are available in our Knowledge Base.
Breakout cBot takes advantage of price movement beyond a pre-defined support or resistance level, and the Bollinger Bands indicator drives its decisions. Let's build the trading bot and backtest it.
Press Ctrl+B or click Build at the top of the code editor.
Once the build succeeds, click any available instance under the cBot name.

In the main grid, navigate to the Backtesting tab. Perform a one-year backtest using the default parameters to evaluate the robot results. The cBot produces a 22% gain for this period, delivering 74 winning trades from 194 as recorded in the Trade statistics tab.

Upgrade the cBot with AI
With AI assistance, you can upgrade the trading bot's code for better results and identify parameter combinations that produce higher returns.
RSI is a momentum indicator that filters out weak breakouts or false signals. This indicator should blend perfectly and complement the Bollinger Bands used in Sample Breakout cBot. For reference, you can get the RSI integration for Super cBot provided in a Help Centre article.
Take the RSI integration snippet, attach it to a prompt containing all the necessary information, then feed everything to the AI tool:
Prompt
Study the RSI integration in Super cBot, then implement the same RSI filters in Special cBot.
[Special cBot code]
[Super cBot integrated with RSI code]
AI thinks and then provides the code for Special cBot integrated with RSI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
Next, ask AI to recommend optimal parameter settings for the trading bot based on our strategy.
Prompt
I want the cBot to generate smoother, slower signals that pair naturally with the RSI filter.
I prefer fewer trades but cleaner breakouts.
I am setting the consolidation period to 1 because I want the cBot to act immediately when
volatility compresses.
Which moving average type is best for this?
AI thinks and then provides some useful information. It recommends Wilders Smoothing as the best moving average type for our strategy.
Apply AI recommendations
Return to the code editor in cTrader and apply the recommended changes. Paste the updated code, then build the upgraded cBot.
Open the Backtesting tab again. Set the moving average to Wilders Smoothing, as recommended by the AI, then run a backtest for the same one year period.

This time, the backtesting report over the same period shows a 97% gain, a massive improvement when compared to the 22% delivered by the original cBot logic.
The new result demonstrates how effective AI guidance can be in refining the performance of trading bots and optimising their parameters to deliver excellent results. The win rate of the robot also improved significantly, delivering 51 winning trades from a total of 93.
Start the cBot in Cloud
Thanks to cloud synchronisation, the new cBot is automatically available from all cTrader apps where your cTrader ID is active. You can even start the trading bot in cTrader Mobile or Web.
Simply tap the Start icon.
Because the cBot runs in Cloud, it continues trading 24 hours non-stop, even if your cTrader app is closed or your device is off. No VPS is needed.
Monetise the cBot
Optionally, you can monetise your cBot in cTrader Store, a secure and dynamic marketplace that connects buyers and sellers of trading products.
To publish a product, select the cBot you want to sell directly from Cloud or upload a file, then provide the necessary details. Once published, the algorithm goes live in cTrader Store, becoming available for millions of cTrader users to purchase.
Note
Algo distribution via cTrader Store is completely secure, as your source code is never revealed or uploaded anywhere. Your intellectual property is also respected, as each product purchase is single-user and non-transferable.
