Termos de Referência
The EA/source code file is attached.
Please carefully read and analyze the complete attached code before making any changes.
This EA was developed based on my own trading strategy, rules, and indicators. I personally use these same rules for manual trading, and when I identify the required conditions manually on the MT5 chart, I open trades based on them and have been able to achieve profitable positions.
However, the attached EA is not behaving as intended in automatic trading. In some situations, it does not open a position even when the conditions appear to be present. In other situations, the EA may not correctly interpret or execute the rules that are already incorporated into the code.
My objective is therefore not to create a completely different trading strategy.
My objective is to make the attached EA correctly understand, detect, and execute the strategy that is already incorporated into the source code.
1. Carefully audit the existing code
First, read and understand the entire attached source code.
Identify exactly:
- What indicators are being used
- What timeframes are being used
- What the Buy conditions are
- What the Sell conditions are
- How candle conditions are evaluated
- How indicator values are calculated
- How signals are confirmed
- How entry conditions are triggered
- How positions are opened
- How positions are managed
- How Stop Loss and Take Profit are calculated
- How existing positions are monitored
- How exit conditions work
- How reversal conditions work
- How lot size is determined
- How the EA handles new candles and ticks
- Whether any condition is preventing valid trades from being opened
Do not assume that the code is working correctly simply because it compiles.
2. Find the actual reason why trades are not opening
One of the main problems is that the EA sometimes does not open a position when my trading rules indicate that a valid opportunity exists.
Determine exactly why this is happening.
Check for problems such as:
- Incorrect indicator calculations
- Incorrect timeframe references
- Incorrect candle indexing
- Using closed candles when the strategy requires the current candle, or vice versa
- Conditions that are too restrictive
- Conditions that contradict each other
- Incorrect Buy/Sell logic
- Incorrect comparison operators
- Incorrect signal confirmation
- Signal conditions that can never become true
- Timing problems between ticks and candles
- Incorrect symbol handling
- Incorrect price/Bid/Ask usage
- Broker-specific execution problems
- Incorrect SL/TP calculations
- Lot-size or volume restrictions
- Position-count restrictions
- Spread or trading-condition restrictions
- Any hidden filter preventing valid entries
- Any other programming error that causes the EA to ignore a valid signal
Do not simply tell me that the EA "needs improvement." Identify the actual programming or logical reason whenever possible.
3. Preserve my original trading strategy
The trading rule incorporated into this EA is my own trading rule and is the basis of my manual trading.
Therefore, do not replace it with a completely different strategy.
Do not add random indicators or unnecessary filters simply to make the code more sophisticated.
Instead:
Understand my existing rule → identify how it is supposed to generate a signal → compare that with the actual code → correct the implementation.
If the existing code does not correctly represent the intended rule, modify the code so that it does.
4. Convert my manual trading logic into reliable automatic execution
When I manually look at the MT5 chart and determine that the conditions defined by my strategy are satisfied, I can open a position.
The purpose of this EA is to perform that same decision process automatically.
The EA should continuously monitor the relevant chart data and determine whether the predefined Buy or Sell conditions are satisfied.
When the conditions are genuinely satisfied, it should:
- Detect the signal.
- Confirm the required conditions.
- Open the correct position.
- Use the correct direction.
- Apply the correct lot size.
- Apply the correct SL and TP according to the existing strategy.
- Continue monitoring the position.
- Manage the position according to the programmed rules.
- Correctly recognize weakening or reversal conditions when the strategy requires it.
- Avoid opening trades when the required conditions are genuinely not present.
The goal is for the EA to behave as a true automatic implementation of my manual strategy.
5. Buy and Sell logic must work correctly
The EA must be genuinely bidirectional.
If the conditions defined by the strategy indicate a Buy, it should be capable of opening a Buy.
If the conditions indicate a Sell, it should be capable of opening a Sell.
The EA must not become stuck in one direction or continue opening positions based on an outdated signal after the market conditions have changed.
The Buy and Sell logic should be independently checked and tested.
6. Position management must follow the programmed rules
Once a position is opened, the EA must correctly follow the position-management rules already incorporated into the code.
It must not randomly interfere with a valid position.
In particular, review whether the EA is:
- Closing trades too early
- Ignoring the intended TP
- Moving SL incorrectly
- Failing to move SL when required
- Closing profitable trades unnecessarily
- Holding losing trades because of incorrect logic
- Failing to recognize a valid reversal
- Modifying the wrong position
- Applying management rules to the wrong trade
- Losing track of an open position
If the strategy says that a position should remain open while the original signal remains valid, the EA should not prematurely close it because of an unrelated or incorrectly calculated condition.
7. Real MT5 execution is more important than theoretical code
I do not want an EA that only looks correct inside the source code.
I want the rules to actually work when the EA is attached to an MT5 chart and AutoTrading is enabled.
The implementation must therefore consider real MT5 conditions, including:
- Tick-by-tick execution
- New-candle detection
- Indicator handles and buffers
- Correct data synchronization
- Bid/Ask prices
- Symbol digits and point size
- Minimum and maximum lot sizes
- Lot-step restrictions
- Stop-level requirements
- Spread
- Trading permissions
- Position selection
- Order execution
- Trade-result/error handling
- Broker execution conditions
- Multiple positions where applicable
- EA restart/reconnection behavior where relevant
If an order is rejected, the EA should handle the trade-server response properly rather than silently failing.
8. Make the EA robust, not unnecessarily complicated
I want a strong, reliable, rule-based robot, not a complicated robot full of unnecessary features.
Do not add:
- Random indicators
- Unrequested filters
- Artificial signal restrictions
- Complex machine learning
- Unnecessary optimization
- Martingale
- Averaging-down
- Uncontrolled position multiplication
- Any strategy that was not part of my original design
Every condition in the EA should have a clear connection to the strategy.
The priority is correctness, reliability, and faithful execution.
9. Add proper diagnostics where necessary
If the EA is not opening a trade because one of the required conditions is false, the code should make it possible to identify which condition is preventing the entry.
Where appropriate, add clear diagnostic messages to the Experts/Journal log so that during testing I can understand:
- Signal detected
- Buy/Sell conditions
- Which condition passed
- Which condition failed
- Why an order was not opened
- Whether an order was sent
- Whether the broker accepted or rejected it
- Why an existing position was closed or modified
This will make it possible to verify that the EA is actually following the strategy.
10. Compile-clean and technically correct
The final source code must:
- Compile in MetaEditor without errors
- Have no avoidable warnings
- Use correct MQL5 syntax
- Use proper MQL5 trading functions
- Handle indicator data correctly
- Handle trade errors correctly
- Avoid unnecessary resource usage
- Be suitable for normal MT5 demo and live-chart testing
Do not provide code that merely compiles while the actual trading logic remains broken.
Final ObjectiveThe attached code already contains my trading strategy and rules.
I want you to:
Read the attached code → understand my strategy → identify why the EA is not correctly detecting or executing my signals → correct the underlying problems → improve the implementation → and produce a strong MT5 EA that can automatically trade according to my existing rules.
I manually trade using these rules because I understand the signals and can identify the entry conditions on the chart.
The purpose of this EA is to automate that process.
Therefore, the final EA should not merely be a theoretical demonstration or a code example. It should be a practical, robust implementation of my existing trading strategy, capable of detecting valid signals and executing them automatically on an MT5 chart.
Do not change my strategy just because the current implementation is failing. Find out why it is failing and fix the implementation so that my strategy actually works in automatic trading.
The final result should be evaluated primarily on whether the EA correctly follows the defined rules and executes valid trades in MT5, rather than simply whether the source code compiles or produces an attractive backtest.