← Back to list

Code-Level Autopsy of SniperJaw EA: When Flawed Wiring Destroys Trading Logic

Introduction

Semura Lab. · 2026-05-30 23:03 · 0 claps · 7.9 min read
#algorithmic-trading #mql4 #backtesting #code-audit #repaint
Open on Medium ↗
Wiki topics: 💻 · Programming ⚖️ · Law & Justice

Code-Level Autopsy of SniperJaw EA: When Flawed Wiring Destroys Trading Logic

Introduction

The quality of an automated trading program (EA) cannot be measured by the bravado of its name.

This is a record of the autopsy of a trend-following EA named “SniperJaw EA,” which claims to execute precision sniping. While the previous specimen 004 handled by Semura Lab was a logically broken grid-martingale, this specimen 005 is a complete turnaround: a “classical trend follower” with single positions and no martingale. At first glance, it looks like a very orthodox and sound logic.

However, upon opening it up, a “fatal wiring error” lies within, precluding any discussion of the strategy’s edge.

To be precise — the way it references indicators for entries and the processing of its close loop contain fatal bugs that cause undefined program behavior and fundamentally distort backtest figures. What is actually operating is a mere illusion: “It paints beautiful trading histories only on completed past charts, while self-destructing by chasing phantoms in live execution.”

“The backtest is perfect, but signals disappear in live trading,” or “When run with other EAs, positions are closed arbitrarily” — behind such complaints, this kind of “faulty wiring” is often the culprit. This article reveals that structure directly from the relevant lines of code. Before debating the superiority of the logic, we must first question the “foundation for measuring facts.”

[Disclaimer] This article is a technical diagnosis of widely distributed design “patterns” as a general concept. It is not intended to evaluate specific individuals or products; countless EAs share this identical logic. All descriptions are based on objective facts found in the code.

Specimen Overview — Design Intent Reverse-Engineered from Code

This specimen claims to utilize “sniper-style entries.” However, the design philosophy reverse-engineered from the code is a “heavy, lagging trend-following” approach, which is the exact opposite of sniping.

  • Core Indicators: Bill Williams’ Alligator / 3 SMMAs (Jaw 13/8, Teeth 8/5, Lips 5/3)
  • Entry: Perfect alignment of all 3 lines + matching slopes / Confirmation of a strong trend breakout
  • Exit: UseEntryToExit=true / Stop-and-reverse (SAR) on an opposing signal (Fixed TP=0)
  • Money Management: Single position / Strict exclusion of grids (Nanpin) and Martingale

The essence of the design intent is as follows:

  1. Initial Entry: Executes a market order the moment all 3 Alligator moving averages perfectly align in the order of Jaw < Teeth < Lips and tilt in the same direction.
  2. Profit Maximization: Holds the position as long as the trend continues, without a fixed Take Profit (TP) width.
  3. Exit: Executes a close (and reverses) the moment the trend breaks and an opposing signal lights up.

In short, the initial design aimed for the royal road of trend following: “Even with a low win rate, catch a massive trend and ride it to the very end to maximize the reward.” The pedigree itself is not bad.

Chapter 1: Specification Reconciliation — The Gap Between Presentation and Implementation

We reconcile the design philosophy with how it is actually handled in the implementation.

The Contradiction Between the “Sniper” Name and Lag

The Alligator uses three Smoothed Moving Averages (SMMA). Waiting for these to perfectly align and match slopes means the trend in the market is already mature or reaching its final stages. Contrary to the early and precise imagery of a “sniper,” it is a typical sluggish (lagging) logic burdened with the fate of frequently “buying at the top and selling at the bottom.”

Abandoned Cost Management (Dead Code)

A variable named spreadValue is declared inside the code, but no value is ever assigned or evaluated; it is left unused. This is a remnant (dead code) of an abandoned attempt to implement a filter to avoid entries during widened spreads.

Exit Asymmetry and SL as Insurance

While it has no fixed TP (tp=0), a stop loss of sl=20 (20 pips) is set. This functions as insurance to prevent a fatal wound from a sudden reversal before a trend reversal signal is generated.

Chapter 2: Fatal Structure — Three Points that Cripple Operation

The skeleton (heart) of this EA’s logic is beating, but the wiring connecting it is catastrophic.

A. The Repainting Trap via Forming Bar (Index 0) Referencing

When calling the Alligator values, it uses iAlligator(..., 0), referencing the unconfirmed, currently forming candlestick (index 0). As a result, the signal flashes with every tick movement, repeatedly meeting and losing the entry conditions. During a backtest, it processes using the data at the "close of the bar (or a convenient moment during ticks)," leaving a beautiful result, but in live trading, it causes "repainting" where signals vanish. This is the biggest factor completely destroying the reliability of the test results.

B. Index Destruction in the Close Loop (Ascending Processing)

When closing positions, it executes an ascending loop with OrdersTotal() as the limit: for (int i = 0; i < OrdersTotal(); i++). In MQL4, when a close is successful, the position indexes are shifted forward. In an ascending loop, the moment the list shifts, the "next position" is skipped—a classic array destruction bug. Positions that should be closed are left behind, inviting unintended losses.

C. Risk of Friendly Fire Due to Missing Magic Number

In the order function, like OrderSend(..., 0, 0, Green), the Magic Number (EA identification number) is not set (it remains 0). The EA can only identify its own orders by "Currency Pair" and "Order Type." If discretionary trades or other EAs are running on the same account, it will drag their positions in and mistakenly close them. This is a structural flaw that absolutely prohibits deployment in a live-money account.

Chapter 3: CAP Audit — Verdict on Fact Distortion

Semura Lab determines whether the code contains “Distortion of Facts (CAP)”.

  • Future Leaks (Referencing Unconfirmed Bars): BLACK As mentioned above, it references iAlligator(..., 0). Even if it isn't an intentional future leak (peeking), the flashing of signals (repainting) based on unconfirmed bars is the very definition of "distortion of facts" that creates a massive divergence between backtesting and live execution.
  • Profit/Loss Capping Manipulation: WHITE There is no structure to hide floating losses through grids or hedging. It uses a single position, and losses are taken cleanly.
  • Placebos (Decorations that look functional but don’t work): BLACK The spreadValue intended for spread management is left completely unused.
  • Mismatch Between Presentation and Implementation: GRAY There is a severe divergence between the agile name “Sniper” and the reality of an extremely lagging trend follower using the Alligator.
  • Curve Fitting (Over-optimization): PENDING The three moving averages of the Alligator have a total of 6 parameters (periods and shifts). It has an extremely high degree of freedom and is an indicator easy to over-optimize to a specific historical period. Without unmanipulated out-of-sample test data, a definitive verdict is withheld at this time.

Chapter 4: The Mathematics of Friction — The Outcome Indicated by Expected Value

This specimen, by the fate of being a trend follower, falls into a distribution of “low win rate, high payoff ratio (risk-reward).”

However, in ranging (choppy) markets — which are said to make up 70% of the market — the Alligator’s 3 lines will repeatedly align and collapse. When this happens, the stop-and-reverse (SAR) logic triggers continuously, piling up losses from so-called “whipsaws.”

Furthermore, because spreadValue is dead code, its defenselessness against costs exacerbates this. The friction of the 0.6 pips average spread assumed by Semura Lab will certainly shave away account equity during continuous SARs in a ranging market. The continuous "buying the top, selling the bottom" caused by lagging indicators accelerates these cost-induced losses.

Chapter 5: Specification Compliance — Reconciliation with Semura Lab Standards

We check the code against the strict standards Semura Lab requires for a sound trading logic.

  • Monthly Profit 10%: Unmeasurable. Backtest figures cannot be trusted due to repainting.
  • Win Rate ~55%: FAIL. Due to the structure of trend following (SAR exits), the win rate will converge around 30–40%.
  • PF 1.2–1.5: Unmeasurable.
  • RR 1:1 (5–8 pips): FAIL. Due to the design philosophy of maximizing profits (tp=0), it fundamentally does not meet the tight 1:1 risk-reward specification.
  • Absolute Friction (Spread Management): FAIL. The spread filter has been left as dead code.
  • Position Management: PASS. A sound design that only holds a single position via dual canBuy && canSell checks.
  • No Grid/Martingale: PASS. Completely excluded.
  • 13-Year Walk-Forward Robustness: Unmeasurable. Meaningful testing is impossible unless the code’s wiring is repaired.

Specification Compliance: PENDING (Conditional room for survival, but currently unusable in live environments).

The heart of this specimen’s strategy (the trend-following philosophy) is indeed beating, and it shouldn’t be rejected out of hand. However, due to “wiring defects” like the missing magic number, referencing index 0, and the broken close loop, both live execution and accurate performance measurement are impossible. We must first repair the code (transition to confirmed bars, use descending loops, assign a magic number) and restart by measuring its pure baseline capability.

Physical Evidence — Structural Excerpts

Below are code excerpts that reconstruct the problematic areas named in the diagnosis to the minimum extent necessary to convey the structure.

C++

// +------------------------------------------------------------------+
// | Semura Lab - Extracted Vulnerable Logic (Simplified Model)       |
// | *This code is an abstracted model to explain the broken structure|
// | *It cannot actually run, nor does it point to specific copyright.|
// +------------------------------------------------------------------+
// Defect 1: The "Repaint Bug" via Unconfirmed Bar Referencing (Future peeking / CAP)
void DetectTrend_Flawed() {
    // [FATAL FLAW] "0 (currently forming unconfirmed bar)" is specified for the shift value (12th argument).
    // The value fluctuates with every tick, causing the signal to flash/reverse.
    // This completely disconnects the backtest from live operation (a fatal wound making verification impossible).
    double jawNow   = iAlligator(Symbol(), 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW, 0);
    double teethNow = iAlligator(Symbol(), 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, 0);
    double lipsNow  = iAlligator(Symbol(), 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, 0);
}
// Defect 2: Complete Omission of Magic Number (Collateral damage to other orders)
void SendOrder_Flawed() {
    double lots = 0.1;

    // [FATAL FLAW] "0" is specified for the 9th argument (Magic Number) of OrderSend.
    // Because no unique EA ID is assigned, it cannot distinguish its orders from 
    // discretionary trades or other EA positions, causing severe conflicts like false recognition/exits.
    int ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, 2, 0, 0, "Sniper", 0, 0, clrGreen);
}
// Defect 3: Index Destruction in Close Function (Ascending Loop)
void CloseOrders_Flawed() {
    // [FATAL FLAW] Using an "ascending (i++)" loop against OrdersTotal().
    // When OrderClose succeeds and a position vanishes, the array index shifts forward,
    // causing the immediate next order to be skipped. A classic beginner's MQL bug.
    for (int i = 0; i < OrdersTotal(); i++) {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
            // Because it doesn't even check the magic number, it destroys positions from other systems too.
            if (OrderSymbol() == Symbol() && OrderType() == OP_BUY) {
                OrderClose(OrderTicket(), OrderLots(), Bid, 2, clrRed);
            }
        }
    }
}
// Defect 4: Abandoned Dead Code (Defenseless against friction costs)
void CheckSpread_Flawed() {
    // [SUPPLEMENTARY FLAW] A variable to manage/restrict spread is declared, but...
    double spreadValue;

    // There is no calculation, assignment, or evaluation process anywhere in the code (Dead code).
    // As a result, it is defenseless against the "physical friction" of 0.6 pips expected by Semura Lab,
    // allowing the account to be shaved down by spread losses during signal spam in ranging markets.
}

Conclusion

The EA calling itself a “Sniper” was, in reality, a sluggish trend follower that takes a long time to get moving.

But that is not the issue. The real problem is that the “basic program structure” — the foundation for verifying its edge — was completely broken.

Beautification of backtests via repainting, friendly fire risks from missing magic numbers, and missed exits from ascending loops. These are process issues that precede any discussion of the strategy’s merits. You cannot obtain correct data with a miswired instrument.

First, fix the wiring and measure the facts using confirmed bars. Optimization and discussions of edge start from there.

The material for judgment is always in the code. Physical evidence and mathematics are more eloquent than self-proclaimed titles.

Diagnostic Agency: Semura Lab, Trading Logic Diagnostics Dept.

Are “fatal implementation flaws” or “repainting traps” like the ones in this article lurking in the logic you are developing? If you are concerned, our lab accepts requests for diagnosis.

[Free Diagnosis Here]

— Semura Lab.


메타데이터
post_id
991c9424533c
slug
code-level-autopsy-of-sniperjaw-ea-when-flawed-wiring-destroys-trading-logic-991c9424533c
url
https://medium.com/@griffice3/code-level-autopsy-of-sniperjaw-ea-when-flawed-wiring-destroys-trading-logic-991c9424533c
canonical_url
https://medium.com/@griffice3/code-level-autopsy-of-sniperjaw-ea-when-flawed-wiring-destroys-trading-logic-991c9424533c
author_url
https://medium.com/@griffice3
status
ok
fetched_at
2026-06-20 20:29:01