Specification
I am looking for an EA in MQL5 that trades both sides of a range breakout and places a hedge order. Fairly straightforward!
Here is a specification:
Trading Strategy Specification: Range BreakoutPlatform: Metatrader 5, Forex brokers
Default Chart: EURUSD, 5m chart
Quick overview
The strategy looks for an established range in the morning session and then trades breakouts above or below that range, by opening either a long trade above the range or a short trade below the range. Take-profit and stop-loss targets are immediately set. If one order has been hit, the other order is immediately terminated. If a trade ends in stop-loss, a hedge trade is opened immediately afterwards
Description of Algorithm
Input Parameters
| Name | data type | default value |
| starttime | time | 7:00am UTC+1 |
| endtime | time | 9:00am UTC+1 |
| minimumrange | number | 10 pips |
| maximumrange | number | 150 pips |
| entrybuffer | number | 5% |
| exitbuffer | number | 2% |
| riskrewardratio | number | 2 |
| tradevolume | number | 0.05 lots |
| hedgerangedivider | number | 3 |
| hedgevolumemultiplier | number | 4 |
| endtime | time | 8:00pm UTC+1 |
Step 1: Establish range in the morning session
Record the highest and the lowest encountered price in the time interval between start time and end time in two variables and calculate the resulting range. Also apply a minimum and maximum range.
High = highest price encountered in interal between starttime and endtime
Low = lowest price encountered in interval between starttime and endtime
Range = High - Low
if Range is higher than maximum range, then set Range = maximumrange
if Range is lower than minimum range, then set Range = minimumrange
Step 2: Trade Entries
Calculate the entry prices by using the range, and a buffer. Set the orders immediately after the time interval of step 1 is over. First, calculate price levels:
bufferrangeentry = range * (1+entrybuffer)
bufferrangeexit = range * (1+exitbuffer)
rangedivider = range / riskrewardratio
Place two pending stop orders with the following parameters:
1) Short Order
Direction: short
Entry Price: Low - bufferrangeentry
stop loss: High + bufferrangeexit
take profit: Entry - rangedivider
2) Long Order:
Direction: long
Entry: High + bufferrangeentry
Set stop loss: Low - bufferrangeexit
Set take profit: Entry + rangedivider
If one of the orders is hit, delete the other open order.
Step 3: Hedge Orders
If a stop loss has been hit, on the first opened position, we try to re-coup our losses with a hedge. Therefore a hedge order is placed at the stop-loss of the first opened order. Calculate the range of the hedge:
hedgerange = Range / hedgerangedivider
Place Long Hedge Order if 1st opened position was a short:
Direction: Long
Entry: 1st order stop loss price, immediately after
Stop loss: 1st order entry price
Take Profit: entry + hedgerange
OR
Place Short Hedge Order if 1st opened position was a long:
Direction: Short
Entry: 1st order stop loss price
Set Stop loss: 1st order entry price
set Take Profit: entry - hedgerange
Step 4: Close at market price at a time at the end of the day
Close all orders and positions at the given time in the endtime parameter