 (1).png)
This C Bot (RSTI_Ausama)
This C Bot (Robot) is written in C# using the cAlgo.API platform and is designed for automated trading in the Forex market. The bot relies on signals from technical indicators (Simple Moving Averages) to make buy and sell decisions. Below is a detailed explanation of the bot's components and how it works:
---
### 1. **Parameters**
The bot includes a set of customizable parameters to tailor its trading behavior:
- **RSTI Settings**:
- `Source`: The data source used for calculations (e.g., closing price).
- `Length`: The period length for the Simple Moving Average (SMA).
- `Signal Length`: The period length for the signal SMA.
- **Risk Management**:
- `Trade Direction`: The trading direction (Buy Only, Sell Only, or Both).
- `Lot Size`: The lot size used for trades.
- `Target Percentage (%)`: The percentage target for Take Profit.
- `Target Partial (%)`: The percentage for partial profit-taking.
- `Stop Loss Percentage (%)`: The percentage for Stop Loss.
---
### 2. **Technical Indicators**
The bot uses the following technical indicators:
- **Simple Moving Average (SMA)**: A simple moving average based on the closing price.
- **SMA Diff**: A simple moving average of the difference between the price and the SMA.
- **SMA Diff Abs**: A simple moving average of the absolute difference.
- **SMA Signal**: A simple moving average of the relative strength signal.
---
### 3. **Main Functions of the Bot**
#### a. **OnStart()**
- This function is executed when the bot starts.
- Initializes the indicators and calculates the initial values for the moving averages.
- Stores the last signal value (`_previousSignalValue`) for later comparison.
#### b. **OnBar()**
- This function is executed when a new bar closes.
- Updates the moving averages based on new data.
- Checks for changes in the trading signal:
- If the signal crosses above 60 (Buy) or below 40 (Sell), trades are executed.
- Updates the previous signal value (`_previousSignalValue`).
#### c. **OnTick()**
- This function is executed on every price change (Tick).
- Checks if the partial Take Profit level is reached (`HandleCloseOnTPReached`).
#### d. **ExecuteTrades()**
- Executes trades based on the trading signal:
- If the signal is greater than 60, a Buy trade is opened.
- If the signal is less than 40, a Sell trade is opened.
- Calculates Take Profit and Stop Loss levels based on the specified percentages.
- Executes trades using `ExecuteMarketOrder`.
#### e. **HandleCloseOnTPReached()**
- Checks if the partial Take Profit level is reached:
- If the trade reaches the specified profit level, the position size is reduced by 50%.
#### f. **HandleCloseOnSignal()**
- Closes trades if the trading signal changes:
- If the trade is a Buy and the signal drops below 50, the trade is closed.
- If the trade is a Sell and the signal rises above 50, the trade is closed.
#### g. **DrawSignalOnChart()**
- Displays the current signal value on the chart:
- If the signal is above 50, it is displayed in blue.
- If the signal is below 50, it is displayed in red.
---
### 4. **Risk Management**
- The lot size (`LotSize`) is determined based on the account size.
- Target (`TargetPercentage`) and Stop Loss (`StopLossPercentage`) levels are set as percentages of the current price.
- Partial profit-taking (`Target Partial`) is executed when a specific level is reached.
---
### 5. **Trade Direction**
- The trading direction can be set using the `TradeDirection` parameter:
- `Both`: Trade in both directions (Buy and Sell).
- `Buy_Only`: Trade only in the Buy direction.
- `Sell_Only`: Trade only in the Sell direction.
---
### 6. **How to Use the Bot**
1. Add the bot to the cTrader platform.
2. Adjust the parameters according to your strategy (e.g., lot size, target, and stop-loss levels).
3. Run the bot on the desired chart.
4. The bot will automatically open and close trades based on the trading signals.
---
### 7. **Strengths**
- Relies on clear signals from moving averages.
- Provides flexibility in setting trade direction and risk management.
- Supports partial profit-taking and closing trades based on signal changes.
---
### 8. **Weaknesses**
- Relies entirely on moving averages, which may not be effective in all market conditions.
- Requires parameter optimization to suit specific currency pairs and timeframes.
---
### 9. **Tips for Improvement**
- Backtest the bot on historical data to optimize parameters.
- Add additional technical indicators to improve signal accuracy.
- Monitor the bot's performance regularly and make necessary adjustments.
---
This bot is a powerful tool for automated trading, but it should be used with caution and a thorough understanding of its mechanics and risk management.