# Strategy & Execution Architecture

**AIMS LOBOT EA** combines mechanical price action filters with systematic capital preservation algorithms. It is designed to capture directional momentum expansions following market compression at the London session open.

***

## 1. Structural Signal Detection & Inside Bar Compression[​](#1-structural-signal-detection--inside-bar-compression "Direct link to 1. Structural Signal Detection & Inside Bar Compression")

The algorithm executes according to clear price-action rules:



### The Inside Bar Filter[​](#the-inside-bar-filter "Direct link to The Inside Bar Filter")

* **Definition:** An Inside Bar occurs when the high of the current closed candle (`Bar 1`) is lower than the high of the preceding candle (`Bar 2`), and its low is higher than the low of the preceding candle.
* **Significance:** Represents volatility compression and order accumulation before directional expansion.

### Session Benchmark Alignment[​](#session-benchmark-alignment "Direct link to Session Benchmark Alignment")

* **Daily Session Line (`InpOpenHour:InpOpenMinute`):** The EA calculates the open price of the designated session hour (typically 09:00 broker time for London open).

* **Directional Constraint:**

  * If the Inside Bar is situated **above** the Session Open price, only bullish **Buy Stop** orders are queued.
  * If situated **below**, only bearish **Sell Stop** orders are queued.

* **Order Placement:** Pending Stop orders are positioned at `High[1] + InpBufferPips` (for Buys) and `Low[1] - InpBufferPips` (for Sells). Initial Stop Loss is placed on the opposite boundary of the Inside Bar.

***

## 2. Risk-Neutral Capital Preservation Model[​](#2-risk-neutral-capital-preservation-model "Direct link to 2. Risk-Neutral Capital Preservation Model")

Standard breakout systems frequently encounter whipsaws when trailing stops are moved prematurely to the entry price (`+0.0`), terminating positions during routine intraday pullbacks.

AIMS LOBOT EA employs a mathematical partial liquidation model to establish a net-neutral risk structure while allowing the position sufficient room to develop:



### Mathematical Framework[​](#mathematical-framework "Direct link to Mathematical Framework")

1. **At Order Entry:** Total risk is sized to the initial distance between entry and Stop Loss (`1.0R`, calibrated to 1% of account equity).
2. **At +1.0R Milestone:** The engine automatically closes **50% of trade volume**:
   
   ```
   Realized Return = +0.5R
   ```
3. **Runner Position Mechanics:** The remaining 50% volume maintains its original structural Stop Loss level.
4. **Adverse Retest Scenario:** Should market price retrace completely and strike the original Stop Loss:
   
   ```
   Runner Result = -0.5R

   Net Trade Outcome = (+0.5R) + (-0.5R) = 0.0R
   ```
5. **Structural Integrity:** Because the Stop Loss is not compressed directly to the entry price, the runner survives normal market retracements and remains positioned for multi-hour trend continuation.

***

## 3. Dynamic ATR Trailing Stop Ratchet[​](#3-dynamic-atr-trailing-stop-ratchet "Direct link to 3. Dynamic ATR Trailing Stop Ratchet")

Following execution of the partial liquidation at `+1.0R`, the dynamic **Average True Range (ATR)** trailing algorithm becomes active:

* **Calculation:** Trails behind price action by `ATR(14) * InpATRMultiplier`.
* **Directional Lock:** The Stop Loss ratchets strictly in the direction of the trade and never widens.
* **Execution Safeguards:** Incorporates broker `MODE_FREEZELEVEL` and `MODE_STOPLEVEL` validation checks to prevent order modification rejections from broker trade servers during fast market conditions.

***

## 4. Pyramiding Architecture[​](#4-pyramiding-architecture "Direct link to 4. Pyramiding Architecture")

When `InpMaxOpenTrades > 1`:

* The EA allows subsequent Inside Bar breakout setups in the same direction **only after all existing active positions have achieved partial liquidation at +1.0R**.
* This structural gate ensures that total open account risk does not compound beyond the baseline risk threshold while scaling into sustained trends.

***

## 5. R-Multiple Telemetry & CSV Logging[​](#5-r-multiple-telemetry--csv-logging "Direct link to 5. R-Multiple Telemetry & CSV Logging")

To support empirical analysis, the EA logs trade metrics directly to the MetaTrader 4 data directory: `MQL4/Files/AIMSLOBOT_R_Analytics.csv`

```
Ticket,Symbol,Direction,OpenTime,CloseTime,EntryPrice,InitialSL,RiskPips,Hit1R,MaxMFE_R,RealizedR,NetProfit,ExitReason
```

* **`Hit1R`**: Flag indicating whether the position reached the `+1.0R` capital preservation milestone (`1`) or stopped out prior (`0`).
* **`MaxMFE_R`**: Maximum Favorable Excursion achieved during the lifecycle of the position, measured in R-multiples.
* **`RealizedR`**: Total net realized R-multiple upon final position closure.
