Appearance
Are you an LLM? You can read better optimized documentation at /safety-and-reliability/position-protection.md for this page in Markdown format
Position Protection
Once a trade is open, the work is far from done. Markets reverse, brokers disconnect, and positions need continuous management. TTMT monitors every open position in real time and applies multiple layers of protection to preserve capital and lock in profits.
This page covers every system that guards your positions after execution.
Auto-Breakeven
When a take-profit target is hit, TTMT can automatically move the stop loss to the entry price (plus a buffer), effectively locking in a risk-free trade. This is one of the most impactful safety features in the system.
How It Works
Parameters
| Parameter | Value | Configurable? |
|---|---|---|
| Default trigger | TP1 hit | Yes -- can be set to any TP level |
| Buffer | 2 pips above/below entry | Yes -- adjustable in pips |
| Retry profile | Breakeven (fastest) | No -- always uses fastest retries |
| Initial retry delay | 200ms | No |
| Max retry delay | 2s | No |
| Max retries | 5 | No |
| Verification timeout | 15 seconds | No |
The 2-Pip Buffer
The buffer is not optional for safety reasons. Setting breakeven exactly at entry price is dangerous because:
- Spread fluctuation can trigger the stop even when price has not truly reversed.
- Slippage on the stop execution could turn a breakeven into a small loss.
- Overnight swaps can shift the effective position value slightly.
The 2-pip buffer (default) accounts for all three. You can adjust it, but setting it to 0 is not recommended.
4 Breakeven Paths
Breakeven can be triggered through four independent code paths, ensuring redundancy:
| Path | Trigger | When |
|---|---|---|
| Live trade monitoring | TP hit detected via live connection | Primary path -- fastest response |
| Signal modification | Signal provider sends breakeven instruction | Channel-driven modification |
| Background safety check | TTMT detects missed TP during periodic check | Safety net for disconnections |
| Unified breakeven handler | All paths converge here | Ensures consistent execution |
INFO
The breakeven status is historical audit data. Once marked as active, it is never cleared -- even after the trade closes. This provides a permanent record of whether breakeven was applied, useful for performance analysis.
Trailing Stop
A trailing stop follows the price as it moves in your favor, automatically tightening the stop loss. Unlike breakeven (which moves the SL once), trailing continuously adjusts the SL to maintain a fixed distance behind the current price.
Server-Side Execution
TTMT's trailing stops run server-side, not inside the TTMT process itself. This is a critical design decision:
| Approach | If TTMT Disconnects | Reliability |
|---|---|---|
| Client-side trailing | Trailing stops working | High (TTMT-dependent) |
| Server-side trailing (TTMT) | Trailing continues independently | Very high (broker-side) |
Because trailing is managed server-side, it continues to protect your positions even if your TTMT service restarts, loses internet, or encounters an error.
Save-First Pattern
Before activating a trailing stop on the broker, TTMT saves the configuration to your records first. This ensures that if the broker activation fails, the intent is preserved and can be retried. The sequence is:
- Save trailing stop config to records.
- Activate on broker.
- Verify activation succeeded.
If step 2 fails, the saved record triggers a retry on the next sync cycle.
Preservation During Modifications
When TTMT modifies a position's stop loss (e.g., for breakeven), it explicitly preserves any existing trailing stop. TTMT reads the current trailing stop parameters and re-applies them during the modification.
Without this, a breakeven modification would silently remove the trailing stop -- defeating the purpose of both features.
TP Redistribution V2
When price retraces and deeper entry layers fill, TP Redistribution V2 dynamically compresses take-profit targets to reduce risk on the increased exposure. This system is covered in detail in the Order Management System reference; this section focuses on the safety mechanisms.
Layer 1 Lock
The most important redistribution rule: when any deeper layer fills, all Layer 1 positions lock to TP1.
Layer 1 positions entered at the worst price (market price when the signal fired). If the market retraces enough to fill deeper layers, these Layer 1 positions are the most at risk. Locking them to TP1 ensures they close at the earliest opportunity, securing whatever profit the initial move provided.
Failure Handling
Redistribution involves modifying multiple positions on the broker. If some modifications fail:
| Failure Rate | Response |
|---|---|
| < 25% of modifications fail | Record partial success, continue. The failed positions keep their previous TPs. |
| >= 25% of modifications fail | Mark the trade for automatic retry. The retry service picks it up within 60 seconds. |
Position-Count-Aware Skip
The system tracks how many positions were open during the last redistribution. If a redistribution is triggered but the position count has not changed since the last run, the redistribution is skipped -- it would produce the same result.
This prevents wasted broker operations and avoids unnecessary modifications that could fail and trigger the failure threshold.
TP-Match Skip
Before modifying a position, the system checks whether the position's current TP already matches the target TP. If it does, the modification is skipped. This is a simple but important optimization that reduces broker operations and prevents unnecessary modification events.
Reliability Enhancements
For the deepest layers (Layer 4), which are the most valuable (best entry price, original TP targets), the system uses enhanced reliability:
| Layer | Retry Strategy |
|---|---|
| Layer 4 | Retry failed modifications + 8-second verification to confirm state |
| Layers 2-3 | 2 retries, then stop (self-healing via next layer fill event) |
| Layer 1 | Locked to TP1 -- simplest modification, highest success rate |
Conflict Prevention
When multiple events affect the same position simultaneously (e.g., a TP hit and a signal modification arrive at the same time), conflicting modifications could corrupt state. TTMT's conflict prevention system handles this.
How It Works
TTMT processes one modification at a time for each position. When any operation needs to close or significantly modify a position, it ensures no other operation is working on the same position. If another operation is already in progress, the new operation waits briefly.
Primary / Fallback Pattern
The system uses a primary/fallback pattern to ensure cleanup even if the primary operation fails:
The fallback ensures that even if the primary closure method fails (e.g., a broker call times out), an alternative approach is tried before giving up.
WARNING
If an operation takes too long (likely a broker timeout), the system releases it and allows subsequent operations to proceed.
P&L Recovery
Positions can close outside of TTMT's direct awareness. A trailing stop might fire during a brief disconnection. A broker might execute a margin call. A manual close from the MetaTrader terminal would not generate a TTMT event. The background P&L recovery system catches all of these.
What It Does
- Compares TTMT's list of "open" positions against the broker's actual open positions.
- Identifies positions that TTMT thinks are open but the broker says are closed.
- Queries the broker's deal history to find the closing deal and extract the actual P&L.
- Updates TTMT's trade record with the correct close price, close time, and P&L.
- Triggers any downstream actions (trade status update, performance recalculation).
TTMT periodically checks for these discrepancies. If the closing deal is not immediately available in the broker's history, TTMT retries automatically with increasing wait times until the information is found.
Order Fill Recovery
When a limit order fills, TTMT needs to know about it to update the trade state, trigger redistribution, and manage the new position. If a fill happens during a disconnection, the 3-layer recovery defense ensures it is not missed.
3-Layer Defense
| Layer | Method | Latency | Reliability |
|---|---|---|---|
| 1. Live reconnect | Broker resynchronization delivers missed events | Seconds | Catches ~99% of cases |
| 2. Direct query fallback | Direct query to broker order/deal history | Brief delay + retries | Catches edge cases |
| 3. Admin alert | Notification for manual review | Manual | Last resort for exceptional failures |
Layer 1 is the normal path. When TTMT reconnects after a disconnection, the synchronization process replays events that occurred during the gap.
Layer 2 activates if the live resync does not include the expected fill event. TTMT directly queries the broker's history with a small delay (to give the broker time to populate history) and retries to confirm the fill.
Layer 3 is the absolute last resort. If both automated recovery methods fail, an alert is generated for administrative review. In practice, this is extremely rare.
Safe Position Modification
All position modifications in TTMT go through a single safe modification process. This exists because modifying a position on the broker has important side effects that must be carefully managed.
What It Preserves
| State | How It Is Preserved |
|---|---|
| Trailing stop | Current trailing parameters are read before modification and re-applied in the same call |
| Breakeven state | The breakeven status in your records is not affected by modification |
| Open TP | Positions with "open TP" (runner mode) retain their open TP status |
Why This Matters
Without this safe modification process, a breakeven modification would silently remove an active trailing stop. The broker's modification call replaces all parameters -- it does not merge them. If you set a new SL without specifying the trailing stop, the trailing stop is removed.
TTMT's safe modification reads the current position state, merges the intended change with all existing parameters, and submits the complete state in a single update.
DANGER
Every part of TTMT that modifies positions uses this safe modification process. Direct broker modification calls are prohibited. This ensures your trailing stops and breakeven settings are never accidentally removed.
Summary
| System | What It Protects | When It Acts |
|---|---|---|
| Auto-Breakeven | Locks in profit after TP hit | TP1 hit (or configured TP) |
| Trailing Stop | Follows price action server-side | Continuously while active |
| TP Redistribution V2 | Compresses targets on increased exposure | When deeper layers fill |
| Conflict Prevention | Prevents conflicting modifications | Concurrent position events |
| P&L Recovery | Reconciles externally closed positions | Periodically |
| Order Fill Recovery | Catches fills missed during disconnection | After reconnection |
| Safe Position Modification | Preserves trailing/breakeven during modifications | Every position modification |
TIP
All position protection systems work together automatically. Auto-breakeven uses safe modification to preserve trailing stops. TP redistribution respects the conflict prevention system. P&L recovery feeds accurate data back to the performance dashboard. You do not need to manage the interactions between these systems -- they are designed to complement each other.
Related Pages
- Safety & Reliability Overview -- The five layers of defense
- Execution Safety -- Automatic safety pauses and error handling
- Connection Resilience -- Reconnection and state synchronization
- Emergency Controls -- Manual intervention options
- Breakeven Management -- Detailed breakeven concepts
- TP Redistribution -- Redistribution algorithm details
- Order Management System -- Full 12-order system reference

