Study ›
[Course] [Build an EA 3] Turning a trading idea into numeric rules
Where people get stuck most isn't the code — it's defining the rules. A computer doesn't understand "roughly," "if it rises a lot" or "feels like." Everything must become numbers and yes/no.
Vague words → numbers
- "In an uptrend" → when the 20 EMA is above the 50 EMA
- "If it drops a lot" → when RSI(14) falls below 30
- "A reasonable stop" → $30 below the entry (3,000 points)
- "Sit out busy times" → no entries 13:30–14:30 GMT
Write them down like this in a notepad.
The 7-item rule checklist
An EA needs all seven. If one is missing, you can't write the code.
- Symbol and timeframe: e.g. XAUUSD, M15
- Buy entry: e.g. 20 EMA crosses above 50 EMA
- Sell entry: e.g. 20 EMA crosses below 50 EMA
- Stop loss: e.g. $30 against the entry
- Take profit: e.g. 2× the stop ($60)
- Size (lots): e.g. lose only 1% of the account if stopped out
- How many at once: e.g. one at a time; no new entry while a position is open
The example strategy for this series
- Symbol: XAUUSD / timeframe: M15
- Buy: 20 EMA crosses above 50 EMA (golden cross)
- Sell: 20 EMA crosses below 50 EMA (death cross)
- Stop $30, target $60
- One position at a time
Note: this is a practice example, not a strategy that guarantees profit. It was chosen because it's the easiest way to learn the structure.
Only look at closed candles
The most common beginner mistake is deciding on a candle that hasn't closed. The current candle changes every second, so crosses appear and disappear. Our EA will decide once, at the moment a new candle opens, based on the candle that just closed.
Have your own idea? Fill in the 7-item checklist and post it in Q&A. We'll help check whether it can be turned into code.
