This is a very simple Expert Advisor for the Metatrader 4 platform. It is designed to place buy and sell orders at certain prices, with fixed profit levels, and loop until the command is given to close all open orders.
The following variables will be used -
SYMBOL = the currency pair to be used e.g. EUR USD
LOTSIZE = order size e.g. [url removed, login to view] lots
SELL PRICE = the pending price at which a sell order is placed
BUYPRICE = the pending price at which a buy order is placed
PROFITPIPSELL = the number of pips profit target before the sell order is closed
PROFITPIPBUY = the number of pips profit target before the buy order is closed
AGGPROFIT = The total profit target in base currency since the EA was launched. If set to 0 this feature is disabled. If it set to, say 50, then when the total aggregate profit of 50 units of base currency is reached, including the cost of closing the current open trade at a profit / loss is reached the EA will disable itself and place no further trades.
If the current price is in between, or outside the buy and sell price range, then it simply waits until it crosses one of the threshold values for buy or sell.
It then places a buy or a sell trade. If the trade closes in profit, it immediately sets up a new trade in the opposite direction as per the buy and sell variables.
It does this in a continuous loop for both buy and sell trades, until any open trades are closed manually or the preset aggregate profit target is met.
Here is an example from the EUR USD - We want to take profit from a tight range so we set it up for a 12 pip profit target as follows :-
SYMBOL = EURUSD
LOTSIZE = 0.1
SELLPRICE = [url removed, login to view]
BUYPRICE = [url removed, login to view]
PROFITPIPSELL = 12
AGGPROFIT = 50
The price is [url removed, login to view] when the EA is loaded, and the EA waits for the price to to touch [url removed, login to view], then opens up a 0.1 lot sell trade. This closes in profit and the EA opens up a buy trade at 1.3420. The price moves back up and the buy trade closes in profit back at [url removed, login to view], when another sell trade is opened. This goes on for several hours and eventually after 5 winning trades the agg profit reaches 60 pips with the current trade losing by 10 pips - so we have met our profit target and can shut down the EA.