Lab Note (Part 4). This is the point in the series where things start to look “interesting”. And that’s exactly why this part is dangerous if you don’t keep an engineering mindset.
If you haven’t read the previous parts, start here:
- Part 1 — TradingView + Pine Script + RSI prototype
- Part 2 — Porting RSI to MT5 and backtesting in OHLC
- Part 3 — Session filters, 5-year tests, and the first step toward real optimization
In Part 3 we stopped treating RSI like a magic indicator and started building context:
- trade only during NYSE activity
- reduce noise (M5)
- increase sample size (5+ years)
- introduce a statistical dislocation filter (sigma / stdev)
In this Part 4, we continue improving structure and we run the first “real” iteration of optimization — without falling into curve fitting.
What we are trying to build (the actual concept)
By now, the strategy is no longer “RSI 30/70”.
What we are actually trying to model is:
- A sell-off during NYSE hours
- A momentum exhaustion signal (RSI oversold)
- A first sign of reversal (EMA confirmation)
- A fast mean-reversion bounce (scalping behavior)
This is important because it changes how we judge improvements. We are not optimizing a parameter. We are engineering a hypothesis.
1) Time-based exit: forcing the strategy to behave like scalping
Our prototype is structurally a scalping system. That means it should not hold trades for hours.
So we add a new rule:
Close the trade after a fixed time limit.
Based on the analysis and the nature of M5 execution, we set the time exit to:
- 30 minutes
This is a key point:
30 minutes is not chosen because it maximizes backtest profit. It is chosen because it is logically consistent with the strategy’s intended behavior, and then confirmed as reasonable by testing.
If we enter on M5 and we want a fast mean-reversion bounce, we should not expect to hold longer than half an hour. If a trade needs hours to recover, we are no longer scalping — we are hoping.

2) Adding EMA confirmation (and why the timeframe choice matters)
We introduce an EMA filter to confirm that the S&P 500 is starting to revert after the drop.
At first, the natural idea would be:
- use a higher timeframe EMA (M15)
- confirm the trend direction
But we quickly discover something important:
If we use higher timeframe confirmation, we detect the reversal too late — and we get almost no trades.
This is not a “bug”. It’s a structural feature of scalping systems: confirmation must be fast, or you miss the move.
The solution: EMA computed on M1 (used as a reversal trigger)
We keep execution on M5, but we compute the EMA on M1.
Why?
- We are not using EMA as a long-term trend filter.
- We are using EMA as a short-term “reversal alert”.
We test multiple EMA values:
- EMA 20
- EMA 50
- EMA 100
- EMA 200
- Custom EMA
We observe that EMA 20 is a good compromise.
Not because it produces the best backtest, but because it preserves trade frequency:
- From ~255 trades down to ~144 trades (still usable)
Engineering principle: a filter that “improves results” by killing trades is not necessarily improving edge. It may simply be reducing exposure.

3) Increasing trade count intentionally: oversold 30 → 40
At this stage we intentionally step back and retune parameters to increase the number of operations.
We raise RSI oversold from:
- 30 → 40
This increases signal frequency and helps us gather more statistical evidence.
Again, the goal is not “better performance”. The goal is:
More data → more reliable diagnosis.

4) The uncomfortable truth: we may be seeing the start of an edge — but it’s still weak
Results begin to look slightly better. Not spectacular, but less obviously broken.
This is the most dangerous phase of research, because weak improvement can seduce you into thinking you are close.
What we learn from the behavior is:
- we can sometimes profit from the bounce
- but we still cannot reliably filter situations where there is no real reversal
The EMA confirmation is not sufficient.
We need a better answer to a deeper question:
From what type of “zone” should we execute orders?
The next logical step: weekly volume distribution (HVN zones)
We decide to use the weekly volume distribution and trade only from HVN (High Volume Nodes).
The idea is simple:
- HVNs represent acceptance areas
- they often act as support/resistance zones
- mean-reversion has a better chance to work around them
But before implementing HVN logic, we hit a research constraint:
The sample size is too low. We need more trades before adding another layer of complexity.
To increase trade count, we temporarily relax two parameters:
- RSI oversold = 50
- Sigma (stdev) filter = 0.5
This is not meant to be the final model. It is meant to collect enough occurrences to validate the next idea.
5) A better session model: giving the market time to “fall” before we look for reversals
By now the strategy logic is clear:
- we want to buy a drop
- we need RSI oversold
- we need EMA (M1) to hint reversal
- we want NYSE open liquidity
But there’s a missing timing detail.
If NYSE opens at 09:30 NY time, and our strategy requires a sell-off, we must allow time for:
- the market to drop
- bearish momentum to exhaust
- the reversal structure to form
So we shift our entry window.
New entry window (NY time)
- Earliest entry: 10:00 NY
- Latest entry: 13:00 NY
Why not later?
- volatility typically decreases
- mean-reversion becomes weaker and slower
- the scalping hypothesis loses validity
This is a great example of “engineering alignment”: the time window matches the behavior we are trying to exploit.

6) Sample size reality check: 387 trades in 6 years is still too low
After applying all these filters, we end up with:
- 387 trades over 6 years
For this type of strategy, that is still not ideal.
In systematic research, sample size is everything. For most statistical diagnostics, you want at least:
- 1000 trades minimum
Why not just go multi-symbol?
The natural solution would be to run the same strategy across multiple correlated US indices:
- S&P 500
- Dow Jones
- Nasdaq (NQ)
That would increase sample size without violating the assumptions of the model.
However, multi-symbol execution is not native in MT5 and adds engineering complexity.
It can absolutely be done (and real production bots often do it), but it is beyond the scope of this educational exercise.
Lab takeaway: if you cannot collect enough occurrences on one symbol, the strategy may be untestable at this stage — or it may require portfolio design.
7) Adding an HVN filter (Weekly/Daily Volume Profile): trading only from “sensible zones”
At this point we have a clearer hypothesis:
- we trade only during NYSE activity
- we wait for a drop → RSI oversold
- we look for early reversal confirmation (fast EMA)
But we still lack one critical component: location.
Even if RSI and EMA agree, the trade quality changes dramatically depending on where we are on the market structure. So we add a zone filter:
We will take trades only when price is inside a High Volume Node (HVN).
What is an HVN (High Volume Node)?
HVNs are price areas where a large amount of volume has been exchanged. In market profile logic they represent “acceptance zones” — places where the market previously agreed on value. Mean-reversion setups tend to behave more consistently around these zones.
How we implement it in MT5 (research-grade approximation)
MetaTrader 5 does not provide a native TradingView-style volume profile. So we build a practical approximation:
- we choose an anchor window (Daily or Weekly)
- we build a volume-at-price histogram using bar volumes (often tick volume)
- we classify HVN bins as those above a minimum threshold (e.g., a % of the maximum bin volume)
- we allow trades only if the current price is inside an HVN band (with a small tolerance)
Important: this is not meant to be a perfect volume profile. It is a research tool that enforces a sensible idea: trade only from accepted zones.
The filter is fully controllable from the MT5 Inputs panel:
- HVN filter ON/OFF
- Anchor: D (Daily) or W (Weekly)
- HVN threshold: minimum volume required to classify a bin as HVN
With this, we reduce “random” mean-reversion attempts and start building a more structured, location-aware system.

8) Applying the refined filters: the first truly positive results
After implementing the refined session model and the updated logic, we finally see something that matters:
Positive results appear — not because we mined parameters, but because we implemented theoretical assumptions and validated them with data.
This is a critical difference.
However, the problem remains:
- the trade count is still low
So even though the curve is positive, we cannot call it “validated”. It’s an encouraging sign, nothing more.
9) Stress test: disabling EMA filter and reducing stdev filter (0.25)
To test robustness, we run an additional variation:
- Disable EMA confirmation
- Reduce stdev filter to 0.25
This is not done to improve results. It is done to observe the system’s sensitivity.
If performance collapses immediately, the EMA filter was essential.
If performance remains similar, then the EMA filter may be redundant — or the strategy is not truly selective.
This type of stress testing is how you avoid false confidence.
10) Risk analysis: scaling lots and checking margin constraints
So far, we have been testing with:
- 0.1 fixed lots
That is fine for logic validation, but it is not a meaningful risk test.
So we scale the analysis to:
- 10 fixed lots
And we enforce a critical constraint:
Margin used must never exceed 50%. Otherwise the broker would margin call the account in real conditions.
Over 6 years, the results look like this:
- ~10% total return
- ~5% maximum drawdown
This is not terrible in isolation.
But there is a final reality check that every systematic trader must do:

The final benchmark: Buy & Hold beats the strategy
Even with all the improvements, the strategy remains structurally underperforming compared to a basic benchmark.
S&P 500 buy & hold is one of the strongest baselines in finance.
If our system cannot beat it (or at least provide a different risk profile), then it does not deserve capital.
Professional conclusion: we discard the strategy.
And this is not a failure. This is exactly what research is supposed to do.
What we do next (the real process)
We take what we learned and apply the same workflow to another strategy concept.
We repeat the process until we build the portfolio we actually want:
- multiple strategies
- multiple market behaviors
- diversification by logic, not by hope
That is how systematic trading is built: not by forcing one weak strategy to work, but by engineering a portfolio of validated behaviors.
Final note: a necessary warning
Everything you’ve seen in this series is intentionally simple.
These are practical examples designed to teach the workflow: how to prototype, port, test, optimize, and interpret results like an engineer.
But we need to be honest:
The strategy we are using (basic RSI mean-reversion) is a weak strategy.
It is not meant to be traded as-is, and it is not meant to represent a real edge. It is simply a clean sandbox to demonstrate how research works.
If we see enough interest, we may replicate this exact style of analysis again — but starting from a much more powerful strategy concept, so the process becomes not only educational, but also closer to what serious systematic traders actually build.
Final chapter: MT5 inputs console — how to run the tests (and get the code)
One of the biggest advantages of MetaTrader 5 is that your strategy can be driven by a clean inputs console.
Instead of rewriting code every time you want to test a hypothesis, you change parameters directly from MT5:
- RSI thresholds (oversold level)
- ATR-based SL/TP multipliers
- session windows (when the strategy is allowed to trade)
- filters (EMA confirmation, sigma/stdev threshold)
- time-based exit (scalping time limit)
- risk settings (fixed lots for controlled experiments)
This matters because professional research is about repeatable experiments, not one-off backtests.
What the MT5 Inputs panel looks like (example)
When you attach the EA to a chart or run it in the Strategy Tester, MT5 shows an inputs panel similar to this:
RSI / Signal
- rsiLen = 14
- oversold = 30 (later: 40 for sample-size expansion)
- longOnly = true
Stops / Targets
- atrLen = 14
- slR = 1.0
- tpR = 1.0 (tested 1:2, then validated 1:1 region)
- timeExitMinutes = 30
Filters
- useEmaFilter = true/false
- emaPeriod = 20
- emaTimeframe = M1 (fast reversal confirmation)
- useSigmaFilter = true
- sigmaThreshold = 0.50 (later stress-tested down to 0.25)
Sessions (NYSE logic)
- useSessionFilter = true
- entryStartNY = 16
- entryEndNY = 22
Execution / Research settings
- lots = 0.10 (research)
- lots = 10.0 (risk stress test)
- magic = 20260208
- deviationPts = 20Important: the exact input names may differ slightly depending on your EA version, but the concept is the same: each parameter is a “knob” that lets you run a controlled experiment.
How to use it (simple workflow)
- Open Strategy Tester in MT5.
- Select the EA and the instrument (e.g., S&P 500 / US500 / ES CFD depending on broker naming).
- Choose the modelling method (OHLC vs Real Ticks depending on the test stage).
- Open the Inputs tab and set parameters for the experiment.
- Run the test and read the report like an engineer (PF, Expected Payoff, drawdown, stability across time).
This is the foundation of a research pipeline: you change one variable at a time, observe behavior, and document results.
Get the code (free) — Telegram channel
If you want the exact code used in this series, you can get it for free in our Telegram channel.
Inside you’ll find:
- the full EA code used in the article
- the bot files + inputs/settings presets
- notes on how to reproduce the same tests
Join the Telegram channel here: https://t.me/tradingengineeringlab
We share it there because it’s the easiest way to keep everything updated in one place (code, settings, fixes, and future improvements).
Important disclaimer: this is NOT a “ready-to-trade” bot
This is critical:
This EA is not meant to be used live in real markets.
It is a research tool. A sandbox strategy used to teach process:
- how to prototype
- how to port a strategy between platforms
- how to test responsibly
- how to avoid overfitting
- how to evaluate risk and benchmarks
If you’re building systematic strategies, this workflow is the real value — not the RSI bot itself.



