Job finished
Specification
I need an EA that trades when the price difference between 2 brokers is large.
Summary:
On the same computer, I will use 2 MT4 terminals - Primary MT4 and Secondary MT4. There will also be 2 EAs - Primary EA and Secondary EA. The Primary EA will be installed in Primary MT4. Secondary EA will be installed in Secondary MT4. The Secondary EA is like a monitor to send ask and bid prices to the Primary EA. The Primary EA will analyze the data every second, and trade if conditions are met.
I will trade multiple symbols on the primary MT4, with different magic numbers. For each symbol, there will be a Primary EA and a Secondary EA. They will work independent from one another.
Details:
There are 7 parameters that are used for calculation.
AskPrimary: Current Ask price in primary MT4
BidPrimary: Current Bid price in primary MT4
AskSecondary: Current Ask price in secondary MT4
BidSecondary: Current Bid price in secondary MT4
D: This is a manual parameter that I will input in the settings. This is a multiplier to convert the price to points. In general, JPY pairs have D=1000. Non-JPY pairs have D=100000.
S: This is a manual parameter that I will input in the settings. This is a number such as -1, 1, 2.5 or 0.
P: This is a manual parameter that I will imput in the settings. This is a positive number such as 2, 2.5 or 3.
Just follow the formula below to code the EA. You do not need to understand what the formula means.
Condition to Sell:
D*(-0.5*AskPrimary + 1.5*BidPrimary- 0.5*AskSecondary - 0.5*BidSecondary) ≥ S + P
Condition to close Sell:
D*(0.5*AskPrimary + 0.5*BidPrimary - 0.5*AskSecondary - 0.5*BidSecondary) ≤ S + 1
Condition to Buy:
D*(1.5*AskPrimary - 0.5*BidPrimary - 0.5*AskSecondary - 0.5*BidSecondary) ≤ S - P
Condition to close Buy:
D*(0.5*AskPrimary + 0.5*BidPrimary - 0.5*AskSecondary - 0.5*BidSecondary) ≥ S - 1
(Please show the calculation in the Experts log when Primary EA opens or closes a trade. This is so that I can check if calculation is correct)
-Primary EA Settings-
D: Parameter used for calculation.
S: Parameter used for calculation.
P: Parameter used for calculation.
SuffixPrimary: Suffix of the symbol in Primary MT4
TimeRange: This is the time range for the Primary EA to trade in broker time. For example, 9:00-20:00 means Primary EA will trade from 9am to 8pm broker time. (You can use a different format for this setting if you want)
EquityPerLot: Equity required for each lot to trade. For example, if EquityPerLot=1000, and equity is 5000, EA opens 5 lot for each trade.
TakeProfit: Profit target in points. You can use the parameter D to calculate the take profit price.
StopLoss: Stop loss in points. You can use the parameter D to calculate the stop loss price.
MinutesToClose: Primary EA will close trades that are open for too long. For example, if MinutesToClose=20, EA will close trades that are open for 20 minutes.
MagicNumber: Magic number. I will trade multiple symbols, so there will be multiple Primary EAs in the primary MT4 for multiple symbols.
-Secondary EA Settings-
SuffixSecondary: Suffix of the symbol in Secondary MT4
Note 1: Primary MT4 and Secondary MT4 are in same time zone.
Note 2: Each Primary EA with same magic number can open max 1 trade at a time.
====== Method to send AskSecondary and BidSecondary data to Primary EA =======
This is an important part of the EA. The secondary data has to be sent quickly to the primary EA every second, without error or lag. The Primary EA will then compare the secondary data every second and use the formula (see above) to calculate whether to open or close trades. If there is lag, AskPrimary and BidPrimary will have increased/decreased by the time it reads AskSecondary and BidSecondary. This will create a calculation slippage, and some correct trades could be missed, or some wrong trades could open.
One method to send the secondary data to Primary EA is via an exchange file. The secondary EA can send AskSecondary and BidSecondary to an exchange file in C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\Common\Files every second. Then, the primary EA can read this file every second, and then do the calculation. (With multiple symbols, there will be multiple exchange files.)
LET ME KNOW IF YOU HAVE A BETTER METHOD. THE SYNCHRONIZATION SHOULD BE AS FAST AS POSSIBLE, LESS THAN 1 SECOND IF POSSIBLE.