OpenPendingorderAfterPositionGetStopLoss
This EA uses the Stochastic oscillator to generate momentum-based entry signals, placing Buy Stop or Sell Stop pending orders when the main line crosses above or below its lagged value. When a position is closed by stop loss, it automatically opens a reversal pending order in the opposite direction, creating a continuous trading cycle that re-enters after every SL hit.
Open the interactive view (equity curve, symbol switch)Key facts
Backtest results (H1, about 1 year)
| Symbol | P&L | Annual | Max DD | Trades | Win rate | Sharpe | Recovery | Losing streak | Per trade | Status |
|---|---|---|---|---|---|---|---|---|---|---|
| EURUSD | -0.64% | -0.56% | 0.80% | 144 | 46.20% | -1.29 | -0.80 | 7 | −$0.47 | Reliable |
| GBPUSD | -1.08% | -0.94% | 1.32% | 143 | 39.90% | -1.77 | -0.82 | 10 | −$0.76 | Reliable |
| USDJPY | -0.13% | -0.12% | 0.47% | 234 | 50.20% | -0.25 | -0.28 | 7 | −$0.05 | Reliable |
| XAUUSD | -1.71% | -1.41% | 13.66% | 151 | 53.00% | -0.15 | -0.12 | 9 | −$1.13 | Reliable |
Profitable on 0 of 4 markets with reliable results.
Converted from MQL5 to Python and run with the same rules for every EA. Positions use MT5 lot sizes (100,000 units per FX lot, 100 oz per gold lot) with 1:100 leverage, one order at a time, and a stop-out below 10% of the starting balance. Sharpe is computed from the equity curve. Results marked as unreliable are shown for completeness only.
Against the other Momentum EAs with a reliable result on the same market: EURUSD: better than 46% of 68 · GBPUSD: better than 55% of 66 · USDJPY: better than 57% of 68 · XAUUSD: better than 56% of 75
Month by month
| Market | Months with a gain | Best month | Worst month |
|---|---|---|---|
| EURUSD | 46% | +0.08% 2026-09 | -0.29% 2026-02 |
| GBPUSD | 23% | +0.27% 2026-07 | -0.33% 2026-05 |
| USDJPY | 54% | +0.19% 2026-08 | -0.19% 2026-01 |
| XAUUSD | 46% | +4.52% 2026-01 | -4.51% 2026-07 |
From the backtest equity curve, sampled about every two days; only reliable results.
Blow-up risk: No blow-up pattern found
None of the usual blow-up patterns were found in the code, and the account was not stopped out in our backtests. That is not a guarantee: any EA can lose money.
High: stopped out in our backtest, or martingale/grid sizing without a stop loss. Elevated: martingale or grid sizing with a stop loss, or several positions at once without a stop loss. What the label means and what we found →
Strategy analysis
The EA's strategy concept is based on the Stochastic momentum indicator to determine trend direction: when the main line value is below its value 2 bars ago, it identifies bearish momentum and places a Sell Stop pending order; when above, it identifies bullish momentum and places a Buy Stop pending order. Entry conditions rely on Stochastic main line momentum shifts, with pending order prices set beyond the current price plus the stop level distance, ensuring entry after a breakout. Exit conditions are stop loss and take profit, with a fixed-pip trailing stop also supported via CTrailingFixedPips. Position sizing uses a fixed lot size (PriceVolume) with a maximum position count controlled by the Maxposition parameter. Money management includes the CheckMoneyForTrade function to verify available margin and CheckVolumeValue to validate lot size compliance with broker requirements. The distinctive feature is in OnTradeTransaction where it detects stop loss deal events (DEAL_REASON_SL): when a position is closed by stop loss, it immediately places a new pending order in the opposite direction, creating a stop-loss-then-reverse cycle. Pending orders have expiration times, with the OnTick orders using H4 expiration and the reversal orders using the user-configured Expirydate parameter.
Strengths
- Automatic reversal pending order after stop loss hit, capturing oscillating market moves
- Complete margin check and volume validation to prevent non-compliant orders
- Uses pending orders instead of market orders for entry, reducing false breakout risk
- Limits maximum position count (Maxposition) to control risk exposure
- Pending order expiration mechanism prevents stale order accumulation
Weaknesses
- Unlimited reversal pending orders after stop loss can cause consecutive losses in trending markets
- Step and TargetProfit parameters are declared but unused in core logic, creating dead parameters
- Inconsistent pending order expiration between OnTick (H4) and OnTradeTransaction (Expirydate), causing logical inconsistency
- The reversal condition (trans.price > trans.price_sl) is questionable; the relationship between deal price and SL price may be incorrectly evaluated
- No new bar detection means the EA checks indicators and potentially places orders on every tick, risking frequent repeated orders
- SumPosition iterates from PositionsTotal() but max index should be PositionsTotal()-1, causing an out-of-bounds access risk
Possible improvements
- Add a maximum consecutive stop loss count limit to prevent unlimited reversal losses in strong trends
- Add new bar detection logic to avoid recalculating indicators and placing orders on every tick
- Unify pending order expiration logic between OnTick and OnTradeTransaction to eliminate inconsistency
- Fix index out-of-bounds issue in SumPosition and CheckPendingOrder (should start from Total-1)
- Implement the Step parameter in actual logic to control distance between positions
Risk assessment
Overall risk: Caution
- Unlimited reversal pending order mechanism after stop loss can cause consecutive losses in trending markets
- No new bar detection means order attempts on every tick, increasing overtrading risk
- Array index out-of-bounds bug in PositionsTotal()/OrdersTotal() iteration may cause runtime errors
- Price comparison logic in stop loss reversal condition may be incorrect, causing unwanted reversals
Evaluation scores
Parameters
| Parameter | Default | Description |
|---|---|---|
PriceVolume | 0.01 | Trading lot size |
PriceSL | 1000 | Stop loss points (0=disabled) |
PriceTP | 900 | Take profit points (0=disabled) |
trailingstoppoint | 200 | Trailing stop trigger points |
Expirydate | PERIOD_D1 | pending orderexpirationtime period |
Step | 500 | Position spacing distance |
TargetProfit | 6 | Target profit |
RefreshTime | 60 | Refresh interval (seconds) |
HistorySL | 7 | Historical stop loss lookup days |
Slippate | 10 | Slippage tolerance in points |
KPeriod | 22 | Stochastic %K period |
DPeriod | 7 | Stochastic %D period |
STOPricemethod | STO_CLOSECLOSE | Stochasticpricecalculation method |
Slowing | 2 | Stochastic slowing period |
Maxposition | 1 | Maximum positions |
Similar Momentum EAs
Backtests are historical simulations and do not guarantee future results. Not financial advice.