# Smart Pair Trading MT5 – Version 1.22 Update
Version **1.22** is now available and includes several improvements to position management, trade handling, and execution behavior.
## New Feature: Close Reference Leg
A new input parameter, **CloseRefLeg**, has been added.
This option allows you to choose whether **Leg A** or **Leg B** is used as the reference when converting **Points** or **Percentage of Instrument Price** close targets into account currency.
This provides additional flexibility when trading instruments with different price scales.
---
## Improved Position Recovery
The EA now automatically checks for existing positions with the same **Magic Number** after:
* EA restart
* Recompilation
* Chart reload
If matching positions are found, the EA rebuilds its internal trading state and continues managing the existing trade instead of creating a new one.
---
## Additional Duplicate Position Protection
Before opening a new trade, the EA now performs an additional verification to determine whether positions with the configured Magic Number already exist.
If existing positions are detected, the EA synchronizes its internal state instead of opening another position.
This change helps prevent duplicate entries after unexpected restarts or interruptions.
---
## Optional Broker-Side Stop Loss and Take Profit
A new input parameter, **UseBrokerSLTP**, has been introduced.
When trading a **single leg only** (the other lot size is set to zero), the EA can convert the configured **CloseProfit** and **CloseLoss** targets into broker-side Stop Loss and Take Profit price levels.
This feature supports all available **CloseUnit** modes:
* Account Currency
* Points
* Percentage of Account Balance
* Percentage of Instrument Price
When both legs are traded simultaneously, the profit and loss targets continue to be managed internally because a combined pair target cannot be represented as a single broker-side price.
---
## Optional OHLC-Style Tick Sampling
A new option, **UseSecondGate**, has been added.
When enabled, signal evaluation, entries, and exits are processed only at selected checkpoints during each M1 candle:
* :00
* :20
* :40
* :59
This execution mode is designed to produce behavior similar to the MT5 **1 Minute OHLC** testing model while reducing unnecessary intrabar signal evaluations.
Background safety functions such as drawdown monitoring, Friday position management, and position synchronization continue to operate continuously.
---
## Summary
Version 1.22 introduces:
* CloseRefLeg for flexible close-target calculations
* Automatic position recovery after EA restart
* Additional duplicate position protection
* Optional broker-side Stop Loss and Take Profit for single-leg trading
* Optional OHLC-style signal evaluation using UseSecondGate
Please update both the Expert Advisor and the latest recommended set files to use the new features available in Version 1.22. https://www.mql5.com/en/market/product/182975
Version **1.22** is now available and includes several improvements to position management, trade handling, and execution behavior.
## New Feature: Close Reference Leg
A new input parameter, **CloseRefLeg**, has been added.
This option allows you to choose whether **Leg A** or **Leg B** is used as the reference when converting **Points** or **Percentage of Instrument Price** close targets into account currency.
This provides additional flexibility when trading instruments with different price scales.
---
## Improved Position Recovery
The EA now automatically checks for existing positions with the same **Magic Number** after:
* EA restart
* Recompilation
* Chart reload
If matching positions are found, the EA rebuilds its internal trading state and continues managing the existing trade instead of creating a new one.
---
## Additional Duplicate Position Protection
Before opening a new trade, the EA now performs an additional verification to determine whether positions with the configured Magic Number already exist.
If existing positions are detected, the EA synchronizes its internal state instead of opening another position.
This change helps prevent duplicate entries after unexpected restarts or interruptions.
---
## Optional Broker-Side Stop Loss and Take Profit
A new input parameter, **UseBrokerSLTP**, has been introduced.
When trading a **single leg only** (the other lot size is set to zero), the EA can convert the configured **CloseProfit** and **CloseLoss** targets into broker-side Stop Loss and Take Profit price levels.
This feature supports all available **CloseUnit** modes:
* Account Currency
* Points
* Percentage of Account Balance
* Percentage of Instrument Price
When both legs are traded simultaneously, the profit and loss targets continue to be managed internally because a combined pair target cannot be represented as a single broker-side price.
---
## Optional OHLC-Style Tick Sampling
A new option, **UseSecondGate**, has been added.
When enabled, signal evaluation, entries, and exits are processed only at selected checkpoints during each M1 candle:
* :00
* :20
* :40
* :59
This execution mode is designed to produce behavior similar to the MT5 **1 Minute OHLC** testing model while reducing unnecessary intrabar signal evaluations.
Background safety functions such as drawdown monitoring, Friday position management, and position synchronization continue to operate continuously.
---
## Summary
Version 1.22 introduces:
* CloseRefLeg for flexible close-target calculations
* Automatic position recovery after EA restart
* Additional duplicate position protection
* Optional broker-side Stop Loss and Take Profit for single-leg trading
* Optional OHLC-style signal evaluation using UseSecondGate
Please update both the Expert Advisor and the latest recommended set files to use the new features available in Version 1.22. https://www.mql5.com/en/market/product/182975