Tarea técnica
Yes. The final “world-class” RegimeShift concept we converged on is an adaptive hybrid EA, not a single trend EA and not a pure recovery EA.
The key idea is:
Classify the market first → select the correct engine → size dynamically → stop using that engine when its market thesis is invalid.
That is the part I would preserve as the final architecture.
RegimeShift — Final Strategy Architecture
| Layer | Final role |
|---|---|
| H1 | Macro context / large directional pressure |
| M15 | Primary regime classification |
| M5 | Structure, breakout and pullback geometry |
| M1 | Execution timing, shocks and microstructure |
| M3 | Optional fast trend-danger monitor, especially for Range/recovery baskets |
| Tick data | Spread, velocity, shock, execution quality |
The EA maintains persistent states rather than switching on every candle:
RANGE → BREAKOUT_READY → TREND_UP / TREND_DOWN → TRANSITION → SHOCK/COOLDOWN.
TrendScore and RangeScore are independent scores, not opposites. Volatility, execution quality and shock risk are additional independent dimensions.
1. RANGE engine
Only operate when there is credible range structure and no accepted breakout.
The range engine uses small initial exposure and bounded same-direction recovery, but no longer follows a blind fixed martingale ladder.
After every fill it recalculates:
\[ Q_{next}=f( RangeQuality,\ Overshoot,\ ReversalEvidence,\ Volatility, TrendRisk,\ Spread,\ Margin,\ BasketStress) \]Therefore the next layer can be:
increase / same size / smaller / skipped entirely.
The latest safety direction was:
| Stage | Behaviour |
|---|---|
| P1–P2 | Normal |
| P3 | Begin enhanced observation |
| P4 | Final normal recovery layer / conditional rescue zone |
| P5 equivalent | Risk-management state, not another automatic layer |
| P6+ | No blind progression |
This is one of the most important changes from original Latex.
The historical P14-style sequence:
0.01 → .02 → .03 → .05 → .08 → .13 → .22 → ...
must never remain an automatic progression.
2. P4/P5 risk router
When a range basket deteriorates, the EA doesn't simply keep averaging.
At P3 it starts measuring velocity, trend persistence and rebound quality.
At P4, it becomes eligible for a conditional rescue/controlled exit.
If the market continues to deteriorate toward what would previously have been P5/P6, the range thesis is considered damaged.
Then RegimeShift chooses among:
natural rebound exit, small-loss exit, one directional rescue, or hard bounded exit.
The rescue is not a recurring martingale. At most one rescue campaign is allowed.
For the OCO-rescue research, our better region was around:
- rescue trigger roughly $0.30
- desired rescue continuation roughly $0.75–$1.00
- one rescue only
- strict maximum rescue lot
- close the entire campaign when liquidation P/L reaches the required BE/small-profit target.
A $0.25 recovery target was rejected because required rescue leverage became excessive.
3. BREAKOUT / TREND engine
Once an actual range breakout is accepted, the EA stops behaving like a mean-reversion system.
The final trend sequence was:
structure → breakout → sustained acceptance → pullback → reacceptance → entry.
Not:
price crosses level → immediately chase .
A trend campaign uses a structural stop and splits exposure into approximately:
Core + Anchor Runner.
The intended allocation is roughly:
\[ 65\% \ Core + 35\% \ Runner \]subject to broker-valid lot increments.
Core takes the nearer structural/R target.
Anchor stays with the trend and is managed by structural/staged trailing.
Only after profits are secured can the EA pyramid.
4. Trend pyramiding
Pyramiding is profit-funded, never loss-funded.
Each additional layer must be supported by:
- realized profit from earlier positions;
- broker-protected open profit;
- continued structural trend acceptance;
- adequate remaining room;
- acceptable execution/spread.
Maximum conceptually around four additional decreasing-risk layers, but the EA may add fewer or none.
The crucial rule:
No averaging down inside the Trend engine.
If the trend thesis fails, reduce or exit.
Do not turn a failed trend trade into a recovery basket.
5. Engine switching
This is what makes RegimeShift different from combining two unrelated EAs.
A campaign has one market thesis at a time.
For example:
RANGE → accepted upside breakout
does not mean:
keep SELL recovery + start BUY trend positions .
Instead:
freeze new range risk → evaluate/flatten damaged range exposure → require transition confirmation → then allow fresh TREND_UP campaign.
Likewise:
TREND → range
means harvest/exit the trend campaign before a new range campaign begins.
No uncontrolled strategy overlap.
6. TRANSITION and SHOCK
These are genuine NO-NEW-RISK states.
In TRANSITION:
- no fresh range basket;
- no fresh trend campaign;
- pending orders may be cancelled/recentered;
- existing exposure is managed defensively.
In SHOCK:
- cancel unfilled pending risk;
- freeze recovery additions;
- do not pyramid;
- concentrate on existing-risk reduction.
Actual XAU movement velocity is important here, not just indicators.
Our forensic work showed that very fast adverse moves are disproportionately associated with deep baskets. So RegimeShift should continuously measure:
\[ \Delta P_{3s},\Delta P_{10s},\Delta P_{30s},\Delta P_{60s} \]along with ATR-normalized versions.
7. Scheduled-news protection
News is a separate risk dimension, not part of TrendScore.
The architecture supports two set-file profiles.
Conservative: curated major USD events can block the whole trading day.
Typical Tier-A events:
NFP/main jobs report, CPI/Core CPI, FOMC rate decision, FOMC Minutes, PCE/Core PCE, GDP and major Fed Chair events.
Medium: use configurable pre/post blackout windows instead.
The original trend build used approximately 60/45 minutes for Tier-1 and 30/25 for other high-impact events, while the later Latex research showed why whole-day blocking may be preferable for the conservative profile.
Existing exposure before news is handled independently: small exposure can be flattened, pending orders cancelled, and damaged baskets prevented from adding new risk.
8. Sessions
The EA must not interpret every hour as equivalent.
The original trend research used approximately:
07:00–12:00
12:30–17:00
with first-session minutes blocked and rollover around:
23:45–00:45
excluded.
But these remain set-file parameters, not buried logic.
Session profile, news profile and risk profile should be selectable without changing strategy code.
9. Risk model
The final Trend architecture used approximately:
\[ 0.25\% \text{ planned event risk} \]with a source hard ceiling around:
\[ 0.50\% \]For the hybrid version, risk should be campaign-based rather than “risk per order”.
Before any new exposure:
\[ ProjectedWorstLoss = CurrentLiquidationLoss+ NewPositionRisk+ SlippageBuffer+ Commission+ GapStress \]and:
\[ ProjectedMarginLevel > MinimumSafeMargin \]must both pass.
The EA also needs independent:
basket hard loss, campaign hard loss, daily soft loss, daily hard loss, weekly hard loss, max time underwater, margin floor, spread guard, execution-fault guard and shock guard.
A hard daily loss means:
flatten managed exposure when required → delete pending risk → lock trading until next configured risk-day reset.
A soft loss means:
stop initiating new campaigns → manage the current one → restart only after defined stabilization criteria.
10. Restart after soft protection
This should not simply use:
wait 30 minutes → start again .
Restart should require time + market evidence.
For example:
\[ Restart = CooldownComplete \land SpreadNormal \land ShockCleared \land RegimeStable \land NoExecutionFault \]and for Range specifically:
\[ RangeScore > Threshold \land TrendRisk < Threshold \land StructureStable \]for several completed observations.
Likewise a Trend engine restart requires a fresh structural event, not reuse of the failed setup.
11. Profit protection
Campaign profit protection is monotonic.
Once a campaign earns and secures profit:
future risk cannot be allowed to convert a meaningfully secured campaign into an uncontrolled loss.
Trend pyramids are funded from secured profit.
Range rescue cannot exceed a predefined campaign-risk allowance.
Newest/additional positions are generally reduced first; strategic anchor exposure survives longest when the structure remains valid.
12. Reversal
No instant “BUY → SELL → BUY” flipping.
A reversal sequence is:
invalidate old thesis → close old campaign → verify flat/reconciled state → fresh opposite confirmation → new campaign ID.
This is especially important for rescue logic. We rejected repeated OCO/rescue flipping because it can turn into a high-volume whipsaw machine.
The final state machine
Conceptually, this is the clean version:
FLAT │ REGIME CLASSIFIER │ ┌────────────────┼─────────────────┐ │ │ │ RANGE BREAKOUT_READY TRANSITION/SHOCK │ │ │ Range Engine wait/confirm NO NEW RISK │ │ P1/P2 accepted breakout │ │ P3 ↓ Observe Pullback + Reaccept │ │ P4 TREND CAMPAIGN │ │ Risk Router Core + Anchor / | \ │ rebound rescue exit profit funded │ │ │ pyramids └──────┴─────┘ │ │ Harvest/Exit FLATTEN │ └──────────→ FLAT ←──┘
Machine learning / deep learning
We deliberately did not make ML the live decision-maker for version 1.
The production engine should remain explainable and deterministic.
ML can run in shadow mode, initially something like an HMM/regime model or calibrated classifier, taking features such as:
\[ TrendScores,\ RangeScores,\ ATR,\ ER,\ ADX,\ velocity, spread,\ session,\ news,\ depth,\ basket MAE,\ rebound \]and predicting things such as:
\[ P(\text{trend continuation}) \]\[ P(\text{return to basket BE before next adverse level}) \]\[ P(\text{P8-style tail} \mid current state) \]Only after strong walk-forward evidence would ML be permitted to alter live routing. Initially it merely logs:
RULE_DECISION versus ML_SHADOW_DECISION .
That protects us from building a sophisticated overfit model.
The two set files I would ultimately maintain
RegimeShift_CONSERVATIVE.set would use full-day Tier-A blocking, stricter Range acceptance, P4 as the last normal recovery layer, smaller campaign/daily risk, stronger stabilization requirements and no discretionary deeper recovery.
RegimeShift_MEDIUM.set would use narrower news windows, allow slightly broader Range participation, possibly permit one rigorously qualified rescue/extra recovery action, and use somewhat less restrictive regime thresholds.
The strategy code remains identical. Only the risk envelope changes.
So, in one sentence, the final RegimeShift philosophy is:
Exploit mean reversion only while the market demonstrably remains a range; switch to structural continuation only after a breakout proves itself; when neither thesis is reliable, do nothing; and never allow recovery sizing to substitute for an invalidated market thesis.
That is the architecture I would use as the master design for the world-class RegimeShift EA.