Chapter 5【Middle】: Many Ripples — The Womb of Independent Multi-Layer Logic
IV. The Cannibalistic Positions and the Midnight Sweat
2023, early summer.
I built a multi-layer defense engine by combining several independent approaches and ran a backtest with high hopes.
But what was happening on the chart's candlesticks was a “destructive cannibalization of positions” far from my ideal.
When the market moved in a slight range and the technical indicators aligned, multiple logics simultaneously triggered “buy” or “sell.”
In a very narrow price band of only a few pips, four or five positions were clustered like lumps and entered.
“If this goes on, no matter how many logics I diversify, it’s meaningless…!”
Staring at the screen, I wiped the cold sweat.
If positions pile up in the same place and the market moves against them, all positions would snowball into losses, quickly eroding the account's margin.
This wasn’t multi-layer defense at all; it was structurally the same as the past me’s impulsive, pointer-firing “destructive martingale.”
“Independent engines order without knowing about each other, so this happens.
We must embed a ‘commander code’ that monitors the whole fleet and ensures positions never come too close to each other.”
V. The 20-pip Barrier — Birth of CanOpenNewLine —
Even while waiting at a service car’s signal or facing the MetaEditor’s dark screen at night, my mind was filled with the algorithm for that safety device.
“When opening a new position, if it is not at least a certain distance away from existing positions, create a system that absolutely rejects the order regardless of the entry signal.”
I began typing and delved into programming a new decision function.
//+------------------------------------------------------------------+
//| New line opening decision: check minimum distance from existing positions |
//+------------------------------------------------------------------+
bool CanOpenNewLine(int cmd, double minDistancePips)
{
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == InpMagicNumber)
{
if(OrderType() == cmd)
{
// Calculate distance from the first existing position (in pips)
double distance = MathAbs(OrderOpenPrice() - (cmd == OP_BUY ? Ask : Bid)) / Point / 10;
if(distance < minDistancePips)
{
return false; // Reject entry if distance is below minimum (avoid overlap)
}
}
}
}
}
return true; // Allow opening only when sufficient distance is guaranteed
}
I set the minimum distance to 20.0 pips for trial.
If the market hasn’t moved at least 20.0 pips away from existing positions, no matter how attractive an entry signal lights up, the program will coldly cancel the entry.
It’s an absolute barrier code to physically prevent clusterings in a narrow area and keep the market at a wide, safe distance.
In a narrow room, soldiers get overwhelmed; that’s why we lay a “socially distanced defense network” placing the next soldier only at least 20 steps away.
“This is it…! With this, cannibalism between positions will be completely prevented!”
I pressed the compile button, checked the error-free log, and with trembling hands launched backtesting again.
六. The Chart That Restored Order — The Scattering Defense Net —
On the tester screen, the candlesticks began to ripple violently again.
There would no longer be clumped positions in a narrow price range as before.
Even if the market stretched in one direction, CanOpenNewLine controlled it so that each position would be arranged at neat, evenly spaced intervals of at least 20.0 pips.
【Behavior after introducing the anti-duplication mechanism (CanOpenNewLine)】
・Position 1: 0.9000 (1st layer enters)
・Position 2: 0.9025 (second layer enters 25 pips away)
・Position 3: 0.9050 (further 25 pips away)
⇒ Positions are neatly dispersed, and even during sharp retracements, the average entry price is naturally lifted to a very favorable position.
Because positions aren’t crowded, even large market reversals keep margin maintenance from plunging.
And the moment the market slightly reverses, the dispersed position groups generate a perfect leverage effect and slide into a profitable exit at once.
“Beautiful….”
Staring at the orderly trade history on the monitor, I whispered.
The combination of multi-layer wave capture and physical duplication prevention through CanOpenNewLine.
When these two gears, perfectly complementing each other, clicked into place, my self-made system evolved from a mere “collection of programs” into a true “unsinkable hull” capable of withstanding the market’s raging waves.