This is a semi-automatic Expert Advisor. A user draws a support or a resistance line in the form of a horizontal line or a trendline on a chart. A command in the format of UP|DN_xxxx:yyyy is specified in the line name; the Expert Advisor understands it as a signal to buy or sell setting a stop loss and a take profit.
EA settings include a parameter with a lot size and a value for moving stop loss to breakeven. If stop loss = 0, the EA does not use breakeven. If this parameter is greater than zero, then when a position moves to profit equal to the parameter (in points), stop loss is moved to breakeven. Positions are closed either by SL, TP or manually.
You draw a trendline on a chart. МТ4 calls it Trendline 53503. If you believe that the price should rollback from this line, then add the command UP_xxxx:yyyy in the line name, where:
- UP is a command to buy, DN is a command to sell;
- xxxx is the stop loss value in points;
- yyyy is the take profit value in points.
I.e. in this example, a stop loss should be set at 300 pips from the current price, and a possible profit can be equal to 1200 points, so the name of the trend line is like this: Trendline 53503 UP_0300:1200. The Expert Advisor will be watching the price based on this command. Once the price crosses the trendline upwards, the EA will open a buy deal with the preset stop loss (300 points) and take profit (1,200 points).
A buy deal opens when the following conditions are met:
- There are no open buy deals for this symbol that have been opened by this EA (checked by Magic).
- There is an open buy deal on this symbol, which has been opened by the EA (checked by Magic) and its stop loss is above its opening price, i.e. its stop loss provides a guaranteed profit.
For a reverse situation - to form a sell deal - a command in the line deal should be as follows: Trendline 53503 DN_0300:1200. In this case, the EA will wait until the trendline is crossed downwards. When this situation occurs, a sell deal will be opened.
The deal will be opened under the following conditions:
- There are no open sell deals for this symbol that have been opened by this EA (checked by Magic).
- There is an open sell deal on this symbol, which has been opened by the EA (checked by Magic), and its stop loss is below its opening price, i.e. its stop loss provides a guaranteed profit.
Important: keep the command form UP_xxxx:yyyy and DN_xxxx:yyyy. If the stop loss value is two-digit (e.g. 20 points), then you should add two zeros in the command, like this: UP_0020:0100.