Carry Percentage-Based Pairs Trading EA

June 24, 2020 Views: 68,655

    CarryPCT percentage-based pairs trading EA

This Expert Advisor (EA) uses a different strategy from the earlier Carry Price-Difference Pairs Trading EA. They are effectively two separate Expert Advisors.

After I released the earlier EA, several users suggested this approach. They had been trading it manually and shared screenshots of profitable trades. Their feedback encouraged me to automate the strategy.

Once development was complete, I asked those users to test it. Their initial feedback was positive, and my own brief test also looked promising. However, the testing period was short, and favorable market conditions may have contributed to the results. I planned to run it on a dedicated account to evaluate its performance over a longer period.

    Historical price difference chart

When the EA is running, it displays the highest and lowest price differences between the primary and secondary instruments over the previous 400 bars.

The primary instrument is the symbol on the current chart—in this example, EUR/USD. You choose the secondary instrument; this example uses AUD/USD.

    EURUSD and AUDUSD chart comparison

The example compares EUR/USD and AUD/USD. When the price difference falls below a specified percentage of its historical range, buying EUR/USD and selling AUD/USD may create a pairs trading opportunity.

Conversely, when the price difference rises above a specified percentage, the strategy can sell the primary instrument and buy the secondary instrument.


The following sections explain each panel. The values shown are examples used to illustrate the EA’s features. You can change them in the input fields.


Statistics & Settings

    Stats and settings panel

Enter the symbol for the secondary instrument.

Set the trade size, in lots, for the primary and secondary instruments.

When an entry condition is met, the bid–ask spread must be below 50. If the spread does not meet that condition, the EA skips the entry.

Calculate the highest and lowest price differences over the previous 400 bars.

The panel displays the current price difference. The percentage in parentheses shows its position within the historical high-to-low range. Entry, exit, and additional-entry rules use this percentage as a key reference.

The panel also displays the maximum price difference, the minimum price difference, and the average price difference.

Instrument details appear below. Margin is the amount required to trade one lot. Point value is the profit from a one-point upward move on a one-lot long position.


Carry Panel

    Carry entry panel

Open positions when the price-difference percentage is above 88%.

Use the direction buttons to change whether each instrument is bought or sold.


Open positions when the price-difference percentage is below 20%.

Use the direction buttons to change whether each instrument is bought or sold.


    Scheduled exit settings

Scheduled Exits

Close all managed positions when the first position has been open for more than 888 minutes.

Close all managed positions after June 25, 2020, at 7:09 p.m., based on the computer’s local time.


    Trading session settings

Trading Sessions

This setting is especially important for a two-instrument strategy. If the instruments have different trading hours, an entry condition may trigger a trade in only one instrument. The account would then be exposed without the intended offsetting position.

Some platforms provide quotes around the clock even though trading is not available 24 hours a day. In that situation, an entry condition may be met while the broker is not accepting trades in one of the instruments.

For example, suppose a platform allows WTI crude oil trading from 00:00–02:59 and 04:00–23:59, while Brent crude oil trades from 00:00–01:00 and 03:00–23:59. Set two trading windows: 00:00–01:00 and 04:00–23:59. These are the overlapping hours when both instruments are available to trade. Times in this example use the platform’s 24-hour clock.

To check trading hours, right-click an instrument and select Specification. The original example uses a Hong Kong Hang Seng Index instrument with three trading sessions per day.

    HK50 instrument specifications


    Manual entry controls

Use these manual-entry buttons to add a buy or sell position in either the primary or secondary instrument.


Close Positions Panel

    Close positions panel

The buttons at the top let you close positions with a single click.

    Profit and loss exit controls

Close all managed positions when total profit exceeds $10.

Close all managed positions when the combined profit/loss falls below −$3.

These exit rules apply only to positions managed by this EA. It does not manage manual trades or positions opened by other EAs.


When the price-difference percentage exceeds 80%, close long positions in the primary instrument and short positions in the secondary instrument.

The combined profit/loss of those positions must also be greater than −999.


When the price-difference percentage falls below 20%, close short positions in the primary instrument and long positions in the secondary instrument.

The combined profit/loss of those positions must also be greater than −999.


Add Positions Panel

    Add positions panel

Add Positions as the Price Difference Widens

Starting from an 80% baseline, add a short position in the primary instrument and a long position in the secondary instrument for every 10-percentage-point increase.

Use the controls to change the position-sizing multiplier and trade directions.


Add Positions as the Price Difference Narrows

Starting from a 20% baseline, add a long position in each instrument for every 10-percentage-point decrease.


The baseline percentage and trade directions generally match the initial-entry settings in the Carry panel.