SMA 50/200 Crossover EA
MT5 Expert Advisor specification · Sample snapshot · created for illustration
This packet describes what the EA should do. It is a specification for a developer, not a promise of trading results. Every value is quoted from the trader’s material or was decided by the trader; the points left to the developer and the values taken from examples are listed in the notes below.
- Material
- Request (text) + Pine Script (code)
- Handoff notes
- 4 choices are left to the developer.
Developer's choice
- Maximum slippage · Execution Rules
- Magic number · Execution Rules
- Order comment · Execution Rules
- Configurable inputs · Inputs and Parameters
Not used in this strategy
Do not implement these points or ask the trader about them.
- Terms · Strategy Intent— Not needed: the packet uses no market term without a definition.
- Additional timeframes · Trading Universe— “Only H4”
- Clock used for times · Trading Universe— Needed only together with “Trading session”, “Trading days” or “Daily loss reset time”, which are not used.
- Sell signal condition · Signal Layer— “Long only, no short trades.”
- A signal inside the candle · Signal Layer— Needed only when “When signals are evaluated” is “On every tick”; the answer is “Once per closed candle”.
- Pending order price · Entry Rules— Needed only when “Entry order type” is “Limit order” or “Stop order”; the answer is “Market order”.
- Pending order expiry · Entry Rules— Needed only when “Entry order type” is “Limit order” or “Stop order”; the answer is “Market order”.
- Moving a pending order · Entry Rules— Needed only when “Entry order type” is “Limit order” or “Stop order”; the answer is “Market order”.
- Additional entry conditions · Entry Rules— Needed only when “Extra conditions before an order is placed” is “Yes”; the answer is “No”.
- Signal lifetime · Entry Rules— Needed only when “Extra conditions before an order is placed” is “Yes”; the answer is “No”.
- Time-based exit · Exit Rules— “No time exit.”
- Trailing stop · Exit Rules— “No trailing stop.”
- Break-even move · Exit Rules— “The stop never moves to break even.”
- How often the trailing stop and break-even are checked · Exit Rules— Needed only together with “Trailing stop” or “Break-even move”, which are not used.
- How a series closes as a whole · Exit Rules— Needed only when “More positions while the first is open” is “Yes”; the answer is “No”.
- Other ways to close · Exit Rules— “Nothing else closes the position.”
- Where the next position of a series opens · Position Management— Needed only when “More positions while the first is open” is “Yes”; the answer is “No”.
- What happens after a series closes · Position Management— Needed only when “More positions while the first is open” is “Yes”; the answer is “No”.
- Adding to an open position · Position Management— Needed only when “Maximum open positions” is more than 1; the answer is “1”.
- Opposite signal while a position is open · Position Management— Needed only together with “Sell signal condition”, which is not used.
- Partial close · Position Management— “The position is closed in full.”
- How the lot changes · Risk Management— Needed only when “A lot that depends on earlier trades” is “Yes”; the answer is “No”.
- When the lot returns to the start · Risk Management— Needed only when “A lot that depends on earlier trades” is “Yes”; the answer is “No”.
- Largest lot · Risk Management— Needed only together with “How the lot changes” or “Where the next position of a series opens”, which are not used.
- Daily loss limit · Risk Management— Needed only when “Limits on losses beyond the size of one trade” is “Yes”; the answer is “No”.
- What counts toward the daily loss · Risk Management— Needed only together with “Daily loss limit”, which is not used.
- Action when the daily loss limit is reached · Risk Management— Needed only together with “Daily loss limit”, which is not used.
- Daily loss reset time · Risk Management— Needed only together with “Daily loss limit”, which is not used.
- Other risk limits · Risk Management— Needed only when “Limits on losses beyond the size of one trade” is “Yes”; the answer is “No”.
- Trading days · Filters and Restrictions— Needed only when “Restrictions on when it may trade” is “Yes”; the answer is “No”.
- Trading session · Filters and Restrictions— Needed only when “Restrictions on when it may trade” is “Yes”; the answer is “No”.
- Maximum spread · Filters and Restrictions— Needed only when “Restrictions on when it may trade” is “Yes”; the answer is “No”.
- News filter · Filters and Restrictions— Needed only when “Restrictions on when it may trade” is “Yes”; the answer is “No”.
- Other filters · Filters and Restrictions— Needed only when “Restrictions on when it may trade” is “Yes”; the answer is “No”.
- State kept across restarts · State and Memory— “Nothing has to be remembered on disk.”
- Chart display · Visual and UX Behavior— Needed only when “Anything the EA shows or writes down while it runs” is “Yes”; the answer is “No”.
- Logging · Visual and UX Behavior— Needed only when “Anything the EA shows or writes down while it runs” is “Yes”; the answer is “No”.
- Alerts and notifications · Visual and UX Behavior— Needed only when “Anything the EA shows or writes down while it runs” is “Yes”; the answer is “No”.
- Buy and sell signals at the same time · Edge Cases— Needed only together with “Sell signal condition”, which is not used.
- Other edge cases · Edge Cases— “Nothing else.”
- What to optimise, and within which ranges · Validation Pack— Needed only when “Will the EA be optimised” is “Yes”; the answer is “No”.
- How to choose the result · Validation Pack— Needed only when “Will the EA be optimised” is “Yes”; the answer is “No”.
General
The EA is named SMA 50/200 Crossover EA and runs on a hedging account.
- Account position modeDecided by the trader
Hedging
The trader's answer: Hedging account
Strategy Intent
The strategy follows the long-term trend by being long while the 50-period SMA is above the 200-period SMA. Its style is trend following.
- Strategy purposeDecided by the trader
Follow the long-term trend: be long while the 50-period SMA is above the 200-period SMA.
Wording for the developer
The EA follows the long-term trend by maintaining a long position while the 50-period SMA is above the 200-period SMA.
- Strategy styleDecided by the trader
Trend following
Trading Universe
The EA trades only the named instruments, which in this strategy is EURUSD. It uses one fixed timeframe only: H4; no additional timeframes are used.
- Instruments the EA tradesDecided by the trader
A fixed list of instruments
The trader's answer: Only the pairs I name
- SymbolsFrom the trader's material
EURUSD
- Timeframe the EA works onDecided by the trader
One fixed timeframe
- Execution timeframeFrom the trader's material
H4
“EURUSD H4”Request
Signal Layer
Calculate a 50-period SMA and a 200-period SMA, both applied to closing prices. Evaluate signals once per closed candle and open a long position when the 50-period SMA crosses above the 200-period SMA. This strategy is long only and does not open short trades.
- Indicators and parametersFrom the trader's material
SMA (period 50, applied to close); SMA (period 200, applied to close)
“ta.sma(close, 50)”Pine Script
“ta.sma(close, 200)”Pine Script
- Buy signal conditionFrom the trader's material
if ta.crossover(fast, slow) strategy.entry("Long", strategy.long)
- When signals are evaluatedDecided by the trader
Once per closed candle
Entry Rules
When a bullish crossover of the 50-period SMA above the 200-period SMA occurs, place a market order to open a long position. No additional conditions are required before placing the order.
- Entry order typeDecided by the trader
Market order
- Extra conditions before an order is placedDecided by the trader
No
The trader's answer: No, it enters on the cross itself.
- Entry momentFollows from an answer
Right at the signal
Follows from the answer “No” to “Extra conditions before an order is placed”
Exit Rules
Set a 150-pip stop loss and no take-profit order. Close the long position when the fast SMA crosses under the slow SMA. Do not use a time-based exit, trailing stop, or break-even stop move.
- Stop lossDecided by the trader
150 pips
- Take profitDecided by the trader
None
The trader's answer: No take profit; the position closes on the opposite cross.
- Other ways to close a single position or move its stop, besides its initial stop loss and take profitDecided by the trader
Yes
The trader's answer: Yes, the opposite cross closes the position.
- Signal-based exitFrom the trader's material
if ta.crossunder(fast, slow) strategy.close("Long")
Position Management
The EA allows one position for the whole EA at a time. When an exit is triggered, the position is closed in full; partial closes are not used.
- More positions while the first is openDecided by the trader
No
The trader's answer: No, positions open only on signals.
- Maximum open positionsDecided by the trader
1
The trader's answer: One position at a time
- Position limit applies toDecided by the trader
The whole EA
The trader's answer: One position for the whole EA
Risk Management
Risk 1% of account balance per trade. Do not apply any additional limits on losses beyond the 1% risk assigned to each trade.
- Position sizeDecided by the trader
Risk 1% of balance per trade
- A lot that depends on earlier tradesDecided by the trader
No
The trader's answer: No, the same lot for every trade.
- Limits on losses beyond the size of one tradeDecided by the trader
No
The trader's answer: No, the 1% per trade is the only limit.
Filters and Restrictions
The EA may trade whenever a crossover signal occurs, with no additional restrictions on when trading is permitted.
- Restrictions on when it may tradeDecided by the trader
No
The trader's answer: No, it may trade whenever a cross happens.
Execution Rules
- Maximum slippageDeveloper's choice
Developer's choice
The trader left this to you; choose a sensible value and write it down.
- Magic numberDeveloper's choice
Developer's choice
The trader left this to you; choose a sensible value and write it down.
- Order commentDeveloper's choice
Developer's choice
The trader left this to you; choose a sensible value and write it down.
- Failed order handlingDecided by the trader
Retry a rejected order once after 5 seconds, then skip the signal.
Wording for the developer
If an order is rejected, then the EA retries it once after 5 seconds. If the retry is rejected, then the EA skips the signal.
State and Memory
The strategy does not persist any state to disk. After a terminal restart, it finds the open position by its magic number and continues managing it.
- Behavior after terminal restartDecided by the trader
After a restart, find the open position by its magic number and keep managing it.
Wording for the developer
After a terminal restart, locate the open position using the EA’s magic number and continue managing that position.
Inputs and Parameters
The developer may choose which strategy inputs are configurable.
- Configurable inputsDeveloper's choice
Developer's choice
The trader left this to you; choose a sensible value and write it down.
Visual and UX Behavior
The EA runs silently and does not show or write anything while it runs.
- Anything the EA shows or writes down while it runsDecided by the trader
No
The trader's answer: No, it runs silently.
Edge Cases
- Missing or invalid indicator dataDecided by the trader
Skip the candle when either moving average cannot be calculated.
Wording for the developer
Skip the candle if either the 50-period SMA or the 200-period SMA cannot be calculated.
- Market data or trading temporarily unavailableDecided by the trader
Do not trade until prices update again.
Wording for the developer
While market data or trading is temporarily unavailable, the EA does not trade until prices update again.
Validation Pack
On EURUSD H4, when the 50-period SMA closes above the 200-period SMA, one buy position opens on the next tick; when it closes back below, that position closes. Test the EA on EURUSD H4 from 2019 to 2024 using every tick based on real ticks. In the Strategy Tester over 2023, every open must match a closed-candle cross and there must never be more than one position.
- Validation examplesDecided by the trader
On EURUSD H4, when the 50-period SMA closes above the 200-period SMA, one buy position opens on the next tick; when it closes back below, that position closes.
Wording for the developer
On EURUSD H4, when the 50-period SMA closes above the 200-period SMA, one buy position opens on the next tick. When the 50-period SMA closes back below the 200-period SMA, that position closes.
- Test matrixDecided by the trader
EURUSD H4, 2019 to 2024, every tick based on real ticks.
Wording for the developer
Test the EA on EURUSD using the H4 timeframe from 2019 through 2024 with the Every tick based on real ticks modeling method.
- Will the EA be optimisedDecided by the trader
No
The trader's answer: No optimisation.
- Acceptance criteriaDecided by the trader
In the Strategy Tester over 2023, every open matches a closed-candle cross and there is never more than one position.
Wording for the developer
In the Strategy Tester over 2023, every open must match a closed-candle cross, and there must never be more than one position.
Non-Goals
Do not add grid trading, martingale behavior, or news-based trading.
- Out of scopeDecided by the trader
Do not add a grid, a martingale, or news trading.
Wording for the developer
Do not add grid trading, martingale position sizing, or news-based trading.
Acceptance checklist
One check per settled point, in the words the trader accepted. A point without a scenario is still part of the specification: check the value as stated.
1. Buy signal condition — if ta.crossover(fast, slow) strategy.entry("Long", strategy.long)
On EURUSD H4, after a closed candle where the 50-period SMA applied to close crosses over the 200-period SMA applied to close, evaluate the buy signal once. The EA applies if ta.crossover(fast, slow) strategy.entry("Long", strategy.long) on the next tick. A market buy order for the Long entry is placed.
2. When signals are evaluated — Once per closed candle
Signals are checked once, when a candle has closed (as the next one opens), so in the “Open prices only” mode the EA opens trades on the same candles as in the “Every tick based on real ticks” mode. Exits that trigger inside a candle may differ between these modes: the result is judged in the “Every tick based on real ticks” mode, the closest to real trading.
3. Entry order type — Market order
On EURUSD H4, after a valid closed-candle buy signal and with trading available, the EA opens the position. The position must be opened with a market order.
4. Stop loss — 150 pips
With one buy position open on EURUSD H4, place its stop loss 150 pips below the entry price. The position must have a stop loss set at that 150-pip level and must close when the market reaches it.
5. Take profit — None
With one long EURUSD position opened after a closed-candle crossover on H4 and a 150-pip stop loss, the 50-period SMA closes below the 200-period SMA. No take-profit level is set, and the position closes on the opposite cross.
6. Signal-based exit — if ta.crossunder(fast, slow) strategy.close("Long")
On EURUSD H4, with a Long position open, a closed candle satisfies `if ta.crossunder(fast, slow)`. The EA executes `strategy.close("Long")` for that position. The Long position is closed by the signal-based exit.
7. Maximum open positions — 1
With the EA running on EURUSD H4 in hedging mode and no position open, a buy signal opens a market position. The EA must then allow only one position at a time for the whole EA and must not place another entry while that position remains open.
8. Position size — Risk 1% of balance per trade
On EURUSD H4, when the 50-period SMA closes above the 200-period SMA and a buy market order is opened with a 150 pip stop loss, the EA calculates the position size from the account balance. The order volume must be set so that the risk at the 150 pip stop loss is 1% of balance per trade.
9. Failed order handling — Retry a rejected order once after 5 seconds, then skip the signal.
A buy signal is active and the EA’s market order is rejected. When the EA receives the rejection, it retries that order once after 5 seconds. If the retry is rejected, the EA makes no further order attempt for that signal.
10. Behavior after terminal restart — After a restart, find the open position by its magic number and keep managing it.
An open position exists on EURUSD when the MT5 terminal is restarted, and the position is identified by the EA's magic number. After the restart, the EA finds that open position by its magic number and keeps managing it.
11. Missing or invalid indicator data — Skip the candle when either moving average cannot be calculated.
Set up EURUSD on the H4 execution timeframe with the 50-period or 200-period SMA unable to be calculated for a closed candle. When that candle is evaluated, skip the candle when either moving average cannot be calculated. No order is placed for that candle.
12. Market data or trading temporarily unavailable — Do not trade until prices update again.
With a buy signal available on a closed candle, the market data or trading is temporarily unavailable. When prices have not updated again, the EA does not place a trade. After prices update again, the EA may trade on a valid signal.
Parameters implied by these values
The settled values as EA inputs. Defaults are the trader's own values; a point they did not settle has no row.
| Input | Type | Default | Stated as | Comes from |
|---|---|---|---|---|
| InpSymbols | string | "EURUSD" | EURUSD | Symbols · Trading Universe |
| InpExecutionTimeframe | ENUM | PERIOD_H4 | H4 | Execution timeframe · Trading Universe |
| InpSMAPeriod | int | 50 | SMA (period 50, applied to close) | Indicators and parameters · Signal Layer |
| InpSMAPeriod2 | int | 200 | SMA (period 200, applied to close) | Indicators and parameters · Signal Layer |
| InpStopLossPips | int | 150 | 150 pips | Stop loss · Exit Rules |
| InpMaximumOpenPositions | int | 1 | 1 | Maximum open positions · Position Management |
| InpRiskPercent | double | 1.00 | Risk 1% of balance per trade | Position size · Risk Management |
How to read this packet
- Distances are stated in the unit written next to them. Points are the smallest price step of the instrument; on a five-digit forex quote one pip is ten points.
- A completed candle means the candle has closed; the current candle is still forming and its values change.
- Times and days use the clock named in the packet. When no clock is named, ask the trader before assuming the broker's server time.
- Every value in this packet comes from the trader’s material or from their answer, except the points left to the developer. A point marked as not discussed is not a licence to choose one: ask.
- The EA manages only the positions it opened itself, recognised by its own magic number, and never touches trades opened by hand or by another EA.
- Prices, volumes and stop levels are normalised to the instrument’s tick size, lot step and minimum stop distance before an order is sent; a value the broker rejects is never silently replaced by another.
- Nothing in this packet promises a trading result. It describes behaviour to implement and to test.