Grid Detrended Price Oscillator EA
- Experts
-
AL MOOSAWI ABDULLAH JAFFER BAQER
To trade successfully we need to go through the proven path that others had gone and reached!
Here are 17 quotes from such successful investors:
1- Limit your size in any position so that fear does not become the prevailing instinct guiding your judgment.
Joe Vidich - Version: 3.16
- Activations: 5
Try before you decide: load Grid Detrended Price Oscillator EA into the MetaTrader 5 Strategy Tester, switch visual mode on, and watch every swing it accepts and every swing it lets pass.
TREND HIDES THE SWING. REMOVE THE TREND AND THE SWING SPEAKS.
Most entry tools mix two things together: where the market is heading and how far it has swung around that heading. The Detrended Price Oscillator separates them. It subtracts a moving average from price, so what is left is the swing itself, measured against its own recent centre. Grid Detrended Price Oscillator EA opens a cycle only when that swing turns, on a finished bar, in the direction of the larger trend, and then hands the book to a full management engine that banks group closures and slices heavy old orders down step by step.
At a glance
• A cycle starts when DPO crosses its own signal line on a closed bar. The forming candle is ignored by default, so an accepted signal never repaints.
• DPO is calculated inside the EA from the chart's closes and expressed in ATR, so one setting reads the same on a currency pair and on gold. No indicator file, no DLL.
• The calculation is causal: it compares today's close with an average that ended half a period earlier, so no future bar is ever used.
• Four guards stand between a crossing and an order: Climb, Gap, Stretch and Range, plus a slow EMA 200 side filter.
• New in this product: the Settle Guard, which can refuse a crossing that comes straight after a crossing the other way. It ships switched off, and the reason is shown below.
• Past crossings are marked on the live chart: a small arrow when accepted, a grey dot when a guard refused it.
• Profits are banked by pairing the oldest and newest orders; a heavy old order can be retired in slices.
• No stop loss and no forced close-all. A limit stops new levels; open orders stay under management.
----------
How to use it
1. Attach it to EURUSD H1 with the defaults: 0.01 starting lot, additive ladder.
2. Set RunMode to Scan only for the first session. The panel shows every plan, and no order is sent.
3. When the plans make sense to you, press ARMED on the panel.
4. Before going live, repeat the tests below on your own broker's data, because spread, swap and commission change the result.
5. Give every chart its own magic numbers if you run several copies.
----------
Test results
All figures come from the Strategy Tester with default inputs, 1 minute OHLC, leverage 1:100, 2025.01.01 to 2026.09.30, on one broker's demo data. Use the same settings and you can repeat them.
• EURUSD H1, $10,000: net +912.98, maximal equity drawdown 351.06 (3.40%), 404 trades. No stop-out, no margin refusal.
• EURUSD H1, $1,000,000: net +912.98, maximal equity drawdown 351.06 (0.04%), 404 trades. No stop-out, no margin refusal.
• XAUUSD D1, $10,000: net +26.03, maximal equity drawdown 9.50 (0.09%), 8 trades. No stop-out, no margin refusal.
• XAUUSD D1, $1,000,000: net +26.03, maximal equity drawdown 9.50 (0.00%), 8 trades. No stop-out, no margin refusal.
Read these as a record of one past period, not a forecast. Eight gold trades are far too few to prove anything. The drawdown in money is the same at both deposits because lots do not grow with balance, so 351.06 is a much bigger share of a small account; deposits below $10,000 were not tested. The default guard values were picked on this same period, which flatters the numbers. Netting accounts were not verified, so treat your account type as untested until you have run it yourself.
----------
The Settle Guard: why it is off
The idea is simple. When DPO flickers around its line, crossing up and down on neighbouring bars, a crossing tells you little. The Settle Guard asks that DPO stayed on the other side of its line for a number of bars before the crossing counts. We ran one comparison with everything else at default. EURUSD H1, $10,000, Settle Guard at 3 bars: net +805.34, drawdown 351.06 (3.42%), 359 trades. Off: net +912.98, drawdown 351.06 (3.40%), 404 trades. On XAUUSD D1 it made no difference (8 trades, +26.03 both ways). It cut profit by about 12% and did not lower the drawdown, so the honest choice was to ship it off. It is there for symbols or timeframes where you see choppy flicker; set InpDPOSettleBars to 3 and compare on your own data. One test, one period: this is not proof it is useless either.
----------
Why detrend at all
A moving average follows price; DPO measures the distance between them, taken against an average that is centred half a period back. What remains is the rhythm of swings around the trend. Dividing it by ATR puts that rhythm on a common scale, so 2.5 means two and a half typical bars of stretch on any symbol. That scale lets the Stretch Guard say no to a crossing that comes after the swing is already spent. The cost: DPO is built on an average, so it describes the recent past and will be late at sudden turns.
----------
What happens in one cycle
1. Read. On each new bar DPO and its signal line are rebuilt from finished bars.
2. Cross. DPO moves above its line for BUY, below it for SELL.
3. Climb Guard. DPO must have gained enough in that direction over the last few bars.
4. Gap Guard. The distance from the line must be more than a hair.
5. Stretch Guard. DPO must not already be too far out on the signal side.
6. Settle Guard, optional. DPO must have rested on the other side of its line first.
7. Range Guard. The recent window must be wide enough in ATR; tight boxes are skipped.
8. Trend filter. By default the close must sit on the matching side of the EMA 200. It can also fade that side, or be switched off.
9. Timing. Accepted signals are kept apart by a gap of bars, and a signal may wait a few bars if the level cannot be placed at once.
10. Ladder. Levels follow ATR or fixed points, with a floor, a ceiling on spacing and an optional freeze. BUY and SELL grids can run together or alone.
11. Banking. Groups of oldest and newest orders close when their joint result, after swap and commission, clears the target. If the oldest order is too heavy, a slice of it is closed instead.
12. Safety checks. A closure that would reopen a level at once is blocked, each leg is confirmed in deal history, failed legs are retried, and a plan is dropped if the book changed before sending.
13. Hedge cycle, optional. Off by default and not exercised in our tests. When on, it keeps a balanced pair on a chosen symbol and retires it in equal slices, paid by a small surcharge on closures the grid already makes.
----------
What you see on the chart
The panel sits on the left and keeps the right side and the price scale clear. It shows symbol, magic number, a status pill, grid mode, lot step, spacing, banked result, the book, each side's closing plan and the order list. The DPO PULSE row gives the period and signal length, the current DPO and signal line in ATR, and the bars since the last crossing. The SETTLE GUARD row shows the favoured side, then Settle, Gap, Stretch and Range, each with OPEN, HOLD or off, and finally the EMA side. Buttons switch Armed / Scan only, Pause / Resume, chart marks and slicing. The Hedge Vault card is built to dock under the main panel; with the hedge off it was hidden in our screenshots, so the live dock was not checked. Nothing is drawn in a non-visual backtest.
----------
Your limits
No setting here closes the book for you; limits only stop new levels.
Every order passes a free margin check with a safety buffer before it is sent.
Caps on levels per grid, orders per side and lot per order keep the ladder finite. MinMarginLevelPercent and MaxAccountRiskPercent start at off; decide on them for your own account.
An optional margin-level timeframe safety moves the signal and spacing to a higher timeframe as margin falls. It is off by default and was not exercised in our tests.
Copies are kept apart by symbol and magic number.
Scan only shows every decision without sending orders.
----------
Who it suits
It suits you if you prefer to wait for a swing to turn rather than chase one, like many small closures, and will size lots to your balance. It does not suit you if you need a stop loss on every order, expect a fixed monthly return, or want to leave large lots unattended on a small deposit.
----------
Questions
Does it repaint? Accepted signals, chart marks and both panel rows use finished bars only.
Does the DPO look into the future? No. The textbook chart version shifts the average back in time; this EA compares each close only with an average of older closes.
Which markets were tested? EURUSD H1 and XAUUSD D1. Everything else is yours to test.
What should I adjust first? InpDPOStretchMax, then InpDPOClimbMin. One change at a time, and judge drawdown next to net result.
Why so few gold trades? The guards and the 30 bar gap leave few chances on a daily chart. Looser guards give more trades and more risk.
Can I change the period? Yes. A shorter period reacts sooner and crosses more often, so look at the guards again afterwards.
Netting accounts? A separate margin cap exists for them, but netting behaviour is unverified.
----------
Every input explained
Grid levels
TradeMode - two grids, BUY and SELL, by default, or one direction only.
GridSpacePoints - level distance in fixed spacing mode (25).
GridSpaceMultiplier - above 1.0 widens deeper levels (1.0 = even).
MaxGridLevels - most levels in one grid (1000).
UpDirectionIsBuy - which side an up move arms.
EAMagicNumber - number on grid orders (9754420).
GridOrderComment - text on grid orders (GDPO).
OneOrderPerBar - at most one new level per bar.
Lots
InitialLotSize - volume of the first level (0.01).
LotSizingMode - additive by default, multiply as the alternative.
LotMultiplier - factor per level in multiply mode (1.25).
LotAddStep - step per level in additive mode (0.01; 0 uses the starting lot).
MaxOrderVolume - largest single order (1.0).
UseAutoLot - links the starting lot to balance (off).
AutoLotBaseBalance - balance that matches the starting lot (1000).
AutoLotAllowDecrease - lets auto lot go below the starting lot (off).
ATR spacing
GridSpacingMode - ATR by default, fixed points as the alternative.
ATRTimeframe - ATR timeframe (current chart).
ATRPeriod - ATR length (14).
ATRSpacingFactor - spacing as a multiple of ATR (1.0).
ATRBarShift - ATR bar; 1 is the last finished bar.
ATRMinSpacingPts - lowest spacing in points (50; 0 none).
ATRMaxSpacingPts - highest spacing in points (5000; 0 none).
ATRFreezeOnStart - keeps one spacing for the whole cycle (off).
Profit target
DesiredProfitPerClosure - base target in account currency (2.0).
ProfitMultiplier - final scale, 1.00 to 2.00.
ProfitTargetMode - scaled by default: bigger, deeper books aim higher.
ProfitVolumePower - how closing volume lifts the target (1.0; 0 off).
ProfitDepthBonus - extra target per additional open level (0.10).
ProfitMaxMultiple - scaled target ceiling in multiples of the base (50).
ProfitMaxReachFraction - keeps the target inside this share of one grid step (0.50).
Fragment scanner
UseMultiLegScan - checks multi-order groups before the plain pair (on).
MaxOldestLegs - most old orders in one closure (3).
MaxNewestLegs - most new orders in one closure (6).
ScanPriority - ranking of qualifying groups; largest group first by default.
NeverBankLessThanPair - a group must also beat the pair target (on).
RequireCloseVolumeExceedsTarget - newest volume must be above oldest volume (on).
MinCloseVolumeRatio - required ratio of those volumes (1.5).
Target slicing
EnableTargetSlicing - allows part-closing the oldest order (on).
FragProfitWeightPower - profit weight per closing lot (1.5).
FragMinSlicePercent - smallest slice, percent of the target order (20).
FragAllowMultiCloser - several new orders may fund one slice (on).
FragPreferFullClosure - a full closure wins when both are possible (on).
Reopen guard
ReopenGuard - blocks closures that would reopen a level at once (step based).
ReopenGuardCushion - safe distance as a share of one step (0.90).
Account protection
MinMarginLevelPercent - no new levels below this margin level (0 off).
MaxAccountRiskPercent - no new levels beyond this floating loss, percent of balance (0 off).
NetMaxMarginPercent - netting only: cap on net position margin, percent of equity (5.0).
MaxTotalOrders - absolute order cap per side (1000).
Execution and checks
RunMode - Armed or Scan only.
CloseSequence - order in which legs are sent; oldest first by default.
MaxSlippagePoints - allowed slippage (30).
MaxSpreadPoints - no trading above this spread (7500).
MinSecondsBetweenClosures - pause between closures per side (5).
CloseAttemptsPerLeg - attempts before the retry queue (3).
VerifyTimeoutSeconds - how long a stuck leg is followed (90).
DeferWhenMarketClosed - waits for the session instead of halting (on).
MarketClosedRetrySeconds - retry spacing while orders are refused (30).
AutoResumeAfterSeconds - a halt clears itself after this many seconds (300; 0 waits for you).
NoPartialRetryMinutes - partial closes tried again this many minutes after a broker refusal (15; 0 never).
AbortIfBookChanged - drops a plan if a leg changed (on).
UseFullCommission - counts commission on both sides (on).
CommissionPerLot - fallback figure (0 reads history).
CloseOrderComment - text on closing deals.
Hedge cycle
EnableHedgeCycle - main switch (off).
HedgeSymbols - comma list; repeat a symbol for more turns (XAGUSD).
HedgeSymbolRotation - how the next symbol is picked (per cycle).
HedgeMaxSymbolsInTester - rotation cap in the tester only (2; 0 none).
HedgeCycleLots - lots on each side of the pair (0.01).
HedgeSliceLots - lots retired per side each slice (0.01).
HedgeFragmentBonus - bonus over the slice cost (100).
HedgeBonusIsPercent - bonus is a percent; false means money (on).
HedgeMaxSurcharge - money cap per closure (0 none).
HedgeMaxSurchargePercent - largest rise of any closure target, percent (50).
HedgeMagicNumber - number on hedge legs, must differ from the grid (9754421).
HedgeReopenOnFinish - opens a new cycle when one ends (on).
HedgeStartRequiresTrade - first cycle waits for a grid order (on).
HedgeIntegritySeconds - leg balance check interval (5).
HedgeAutoRepair - repairs a lone leg automatically (on).
HedgeNakedAction - what to do with a lone leg; re-hedge by default.
HedgeMaxSpreadPoints - hedge spread limit (0 off).
HedgeSlippagePoints - hedge slippage allowance (30).
HedgeAttemptsPerLeg - attempts per hedge leg (3).
HedgeVerifyTimeout - follow time for a stuck hedge leg (90).
HedgeCommissionPerLot - fallback hedge commission (0 reads history).
HedgeOrderComment - text on hedge deals.
Weekly cash day
WeeklyCashDay - pauses new cycles and slices around withdrawals (off).
CashDayOfWeek - 0 Sunday, 1 Monday and so on (1).
CashCutoffHour - server hour after which no new slice fires (21).
Panel and chart
ShowPanel - panel on or off.
PanelX and PanelY - distance from the chart edge (12, 15).
PanelFontSize - base text size (9).
ShowArabic - second language line (on).
ShowChartMarks - plans and levels drawn on the chart (on).
MaxTableRows - order rows per grid (13).
PanelCorner - corner the panel is anchored to.
Entry trigger
EntryTriggerMode - the DPO strategy by default.
SignalBarShift - 1 is the last finished bar.
SignalBarsDelay - bars between accepted signals (30; 0 every).
SignalValidBars - bars a signal stays usable (3).
SignalAllowBuy and SignalAllowSell - switch each side.
SignalReverse - turns the direction around (off).
Detrended Price Oscillator
InpDPOPeriod - length of the average removed from price (20).
InpDPOSignal - length of the signal line EMA (9).
InpDPOClimbMin - Climb Guard: least gain of DPO in ATR (0.2; 0 off).
InpDPOClimbBars - Climb Guard: bars the gain is measured over (3).
InpDPOGapMin - Gap Guard: least distance from the signal line in ATR (0.05; 0 off).
InpDPOStretchMax - Stretch Guard: furthest DPO may already be on the signal side, in ATR (2.5; 0 off).
InpDPOSettleBars - Settle Guard: bars DPO must have stayed on the other side before the crossing (0 off; try 3).
InpDPORangeMinATR - Range Guard: least window width in ATR (5; 0 off).
InpDPORangeBars - Range Guard: window length in bars (20).
InpDPOATRPeriod - ATR length for the guards and the DPO scale (14).
InpDPOTrendFilter - 1 with the EMA side, 2 against it, 0 off (1).
InpDPOTrendMAPeriod - trend EMA length (200).
InpShowSignalArrows - arrow where a cycle armed (on).
InpShowDPOOnChart - past crossings on the live chart (on).
Debug
DebugMode - extra journal detail (off).
Margin timeframe safety
UseMarginTFSafety - main switch (off).
Level1MarginPct and Level1TF - at 6000 percent the work moves to M15.
Level2MarginPct and Level2TF - at 5000 percent the work moves to H1.
MarginTFHysteresisPct - recovery needed before stepping back (500).
----------
Plain risk words
Grid trading is risky. It adds to losing positions, there is no stop loss, and a long trend can keep the book open for a long time or, with lots too large for the balance, end in a stop-out and a heavy loss. DPO is built on an average and cannot know the next bar. No profit is promised. Use lots that survive a bad run, test on your own broker, and risk only money you can afford to lose. No DLLs or extra files are needed.
If you use it, an honest review of how it behaved for you, good or bad, helps the next trader choose well.
