Introduction
Chart Pattern Helper EA is not an automated trading robot. It has no trading strategy implemented inside. The only purpose of this expert advisor is to execute trades via pending orders based on some chart objects: trend lines, horizontal lines, or equidistant channels. In addition to straightforward execution of breakout trades, it is also able to execute a pull-back trade with this EA if you have missed the breakout point for some reason.
The main advantage of Chart Pattern Helper is its ability to set and adjust pending orders according to a range of graphical objects placed on the Forex chart, including objects with slope. This allows easy trade execution for such popular patterns as triangles (ascending, descending, and symmetrical), channels, flags and pennants, rectangles, head-and-shoulders, double tops/bottoms, etc.
Breakout of a level is defined as a simple touch. Chart Pattern Helper will not wait for a price to close above/below the given line. It will place pending orders that get executed whenever the price first touches the set levels.
There is a range of input parameters to regulate the work of this expert advisor, but it can start functioning immediately after you attach it to the chart and add the properly named chart objects. The chart objects may be moved freely then. The expert advisor will continue detecting their position and will adjust orders' parameters accordingly. By default, the EA outputs its current status to the chart comment.
Since all the chart objects are drawn at Bid price, the EA adjusts the entry, stop-loss, and take-profit levels by adding the current spread value in cases when Ask price is to be used. This behavior can be disabled via the input parameters, decreasing the number of modification orders sent to trading server.
Chart Pattern Helper is capable of calculating the position size based on a set of input parameters, stop-loss level, and account balance/equity — much like the Position Sizer for MetaTrader. You may turn this feature off by setting a fixed position size to the EA.
Operation process
This expert advisor goes through the following steps after initialization:
- Detect the objects according to names given via input parameters.
- Entry level for Buy order is placed at Entry object + spread (Ask).
- Entry level for Sell order is placed at Entry object (Bid).
- Stop-loss level for Buy order is placed at the Low of the latest bar with the majority of its length below Border object.
- Stop-loss level for Sell order is placed at the High of the latest bar with the majority of its length above Border object; the spread is then added to that High.
- If UseDistantSL is set to true, the two previous steps are ignored and the farthest point of the opposite line is used. This works only with horizontal and trend lines.
- Take-profit level for Buy order is placed at TP object (Bid).
- Take-profit level for Sell order is placed at TP object + spread (Ask).
- Calculated values are on a constant display via chart comment unless Silent input parameter is set to true.
- Pending orders are positioned according to these calculated values. If either Buy or Sell Entry object is absent, only one order is placed. Orders expire automatically when the current chart bar ends. In MT4, the minimum expiration time is 11 minutes; in MT5, it is 2 minutes.
- If the current price is below the Buy entry and above the Sell entry, pending stop orders are used. If the current price is either below the Sell entry or above the Buy entry, only one pending limit order is used.
- Track current object values and adjust entry, SL and TP levels accordingly.
- If position size calculation is used, order's volume is updated when needed. In this case, the order with old volume is deleted and the order with new volume is created. Warning: Be advised that this may cause significant flow of pending orders, which may be against your broker's terms of service. To prevent such behavior, you need to set UpdatePendingVolume input parameter to false.
- Expired orders are recreated with new volume (if needed) and updated entry/SL/TP levels.
- If one stop order is triggered, the second (opposite) order is deleted (unless OneCancelsOther input parameter is set to false). All objects are renamed by appending EA's Magic number to their initial names. This prevents creation of new pending orders.
- If PostEntrySLAdjustment is set to true, try to update stop-loss when a new candle opens following the breakout.
- Continue updating position's take-profit level according to TP object.
- Cease activity once the position is closed.
- Go to step one once the controlling chart objects are renamed back to their initial names.
Alternatively, the expert advisor can work in a trendline trading mode:
- Detect the upper/lower border chart object.
- Wait till a candle closes above/below the trendline with a minimum distance defined via the ThresholdSpreads input parameter. Enter a trade once such a close occurs.
- Use a given stop-loss object as a stop-loss level.
- Use a corresponding upper/lower TP line as a take-profit level.
Demonstration video
This video shows how the Chart Pattern Helper EA is applied to a channel pattern on the NZD/CAD currency pair:
Input parameters
Objects
- UpperBorderLine (default = "UpperBorder") — the name of the object (horizontal line or trend line) used to define the upper border of a breakout pattern. You can either name the object to the value of this parameter or change the parameter to fit the name you have used when created the chart object.
- UpperEntryLine (default = "UpperEntry") — the name of the object (horizontal line or trend line) used to define the Buy entry level of a breakout pattern. You can either name the object to the value of this parameter or change the parameter to fit the name you have used when created the chart object.
- UpperTPLine (default = "UpperTP") — the name of the object (horizontal line or trend line) used to define take-profit level of a Buy order. You can either name the object to the value of this parameter or change the parameter to fit the name you have used when created the chart object.
- LowerBorderLine (default = "LowerBorder") — the name of the object (horizontal line or trend line) used to define the lower border of a breakout pattern. You can either name the object to the value of this parameter or change the parameter to fit the name you have used when created the chart object.
- LowerEntryLine (default = "LowerEntry") — the name of the object (horizontal line or trend line) used to define the Sell entry level of a breakout pattern. You can either name the object to the value of this parameter or change the parameter to fit the name you have used when created the chart object.
- LowerTPLine (default = "LowerTP") — the name of the object (horizontal line or trend line) used to define take-profit level of a Sell order. You can either name the object to the value of this parameter or change the parameter to fit the name you have used when created the chart object.
- BorderChannel (default = "Border") — the name of the equidistant channel object used to define both upper and lower borders of a breakout pattern. You can either name the object to the value of this parameter or change the parameter to fit the name you have used when created the chart object.
- EntryChannel (default = "Entry") — the name of the equidistant channel object used to define both Buy and Sell entry levels. You can either name the object to the value of this parameter or change the parameter to fit the name you have used when created the chart object.
- TPChannel (default = "TP") — the name of the equidistant channel object used to define both Buy and Sell take-profit levels. You can either name the object to the value of this parameter or change the parameter to fit the name you have used when created the chart object.
Order management
- OneCancelsOther (default = true) — if true, a triggered pending order will cancel the opposite pending order. If false, the opposite order will remain intact and may trigger after the first position hits stop-loss or take-profit.
- UseSpreadAdjustment (default = true) — if true, spread will be added to Buy entry level and Sell SL/TP levels. It compensates the difference when Ask price is used, while all chart objects are drawn at Bid level. Setting it to false will reduce the flow of order modification requests to the broker's trading server.
- UseExpiration (default = true) — if true, pending orders will expire at the end of the current bar or in 11 minutes (MT4) or 2 minutes (MT5) after creation — whatever is further. Setting it to false may be required if a broker does not support order expiration.
- DisableBuyOrders (default = false) — if true, new Buy orders will not be created, existing Buy orders and positions will be ignored.
- DisableSellOrders (default = false) — if true, new Sell orders will not be created, existing Sell orders and positions will be ignored.
- PostEntrySLAdjustment (default = false) — if true, the EA will try to adjust the stop-loss as a new candle opens after the breakout one. It will check whether the High/Low of the breakout candle still qualifies for SL. It may potentially break the position sizing rules but will define stop-loss more precisely according to the trading strategy's exit rules.
- UseDistantSL (default = false) — if true, the EA will set the stop-loss to the farthest point of the opposite line. This feature is intended to be used only with triangles and wedges.
Trendline trading
- OpenOnCloseAboveBelowTrendline (default = false) — if true, a trade will be opened after candle closes above/below the border trendline.
- SLLine (default = "SL") — the name of the stop-loss line object for trendline trading.
- ThresholdSpreads (default = 10) — the number of spreads for a minimum distance above/below the border trendline before opening a trade.
Position sizing
- CalculatePositionSize (default = true) — if true, position size is calculated based on given risk tolerance, account size (balance or equity), account currency and traded currency pair. The calculation process is the same as in Position Sizer. If false, a fixed position size is used.
- UpdatePendingVolume (default = true) — if true, pending order's volume is updated whenever new position size gets calculated. This may cause excessively high number of orders to the trading server because it is not possible to modify order's volume; instead, it has to be deleted and then created with a new volume. If false, order's volume remains constant until expiration and following recreation. This parameter is ignored if CalculatePositionSize = false.
- FixedPositionSize (default = 0.01) — if CalculatePositionSize = false, the expert advisor will use the value of this parameter as a volume of created pending orders.
- Risk (default = 1) — risk tolerance in percentage of account balance/equity. Works only if CalculatePositionSize = true. This input parameter is ignored if UseMoneyInsteadOfPercentage is set to true.
- MoneyRisk (default = 0) — risk tolerance in account currency. Works only if CalculatePositionSize = true. Requires UseMoneyInsteadOfPercentage to be set to true.
- UseMoneyInsteadOfPercentage (default = false) — if true, position size is calculated based on risk amount given in account currency (MoneyRisk) instead of balance/equity percentage risk (Risk). Works only if CalculatePositionSize = true.
- UseEquityInsteadOfBalance (default = false) — if true, position size is calculated based on account equity instead of balance. Works only if CalculatePositionSize = true. Ignored if UseMoneyInsteadOfPercentage = true.
- FixedBalance (default = 0) — if set to non-zero value, it is used instead of account balance/equity for position size calculation. Works only if CalculatePositionSize = true.
Miscellaneous
- Magic (default = 20130116) — number used by the expert advisor to distinguish own orders (MT4 and MT5) and positions (MT4 only). You may need to change it only if you have other EAs running with the same Magic number or if you wish to add two or more instances of Chart Pattern Helper to one currency pair.
- Slippage (default = 30) — maximum tolerable slippage in broker's pips.
- Silent (default = false) — if true, no status information will be output to the chart comment. This comes helpful if you use some indicator or other EA that modify chart comment and want to give them priority.
- ErrorLogging (default = true) — if true, the EA will log all errors and other non-standard situations to a log file. It is named as "CPH-Errors-" and can be found in /experts/files/ subfolder of MetaTrader 4 installation folder or /MQL5/Files/ subfolder of MetaTrader 5 installation folder (or a user application data folder designated for your MetaTrader 5 if you are on Vista or newer Windows version.)
MiniFAQ
Is it safe to turn this EA off once the orders are placed?
Yes, but the orders will expire if not triggered. The running EA is required to recreate and update them.
Does it use any trailing stop?
No, stop-loss is fixed after order gets executed. But you can apply your own trailing stop, even in a form of a separate expert advisor.
Can I modify position's stop-loss or take-profit once pending order is triggered?
Sure! You can start modifying stop-loss immediately and you can modify take-profit once you rename/delete the respective TP object or disable the expert advisor.
I use channels to draw the pattern but want the EA to trade only one side — either long or short. How do I do it?
You can prevent the expert advisor from using long (Buy) or short (Sell) orders by setting DisableBuyOrders or DisableSellOrders input parameters to true.
Can you change something for me, please?
No, sorry. There are hundreds of ways to modify this EA to trade differently and to comply with someone else's trading style. I am not going to implement any of them as it is practically impossible to satisfy everyone. However, the source code is open and well commented — you are free to implement your own changes.
Examples
MT4
The following example chart demonstrates the trading process of the Chart Pattern Helper. This descending channel pattern on the weekly GBP/USD is marked with three channel objects: Border (yellow), Entry (turquoise), and TP (lime green.) The expert advisor has detected all objects and calculated the entry, stop-loss, and take-profit levels accordingly. The calculated values are displayed in the chart comment (the top-left corner.) Pending stop orders have been placed, and their TP and SL levels are visible on the chart too.
MT5
The next chart shows how Chart Pattern Helper places a pending buy limit order to get into a trade missed on breakout of the chart pattern. The AUD/JPY @ M5 chart uses two trendlines to define the Border (goldenrod), Entry (turquoise), and Take-Profit (lime green.) The same as in the previous example, the chart comment in the top-left corner of the screen shows the detected levels. Since the lower objects are absent, only buy-specific levels are calculated. One pending buy limit order has been placed because the current price is above the entry level.
Trendline
This chart example shows how Chart Pattern Helper prepares for an entry upon the candle's close above the bullish pennant's upper border. As seen in the top-left corner of the screen, it doesn't require an upper entry level but it found the TP level.
This EA is ECN-compatible., If you are trading with an ECN broker (with market execution for orders), you cannot set SL/TP on position opening. You have to open a position first without SL/TP and only then modify it, adding stop-loss and/or take-profit level. This EA will do it automatically.
Download (ver. 1.14, 2024-03-06)
Chart Pattern Helper for MT4 Zipped Chart Pattern Helper for MT4 Chart Pattern Helper for MT5 Zipped Chart Pattern Helper for MT5Discussion
Warning! Before you ask basic questions regarding installation of the expert advisors, please, read this MT4 Expert Advisors Tutorial to get the elementary knowledge on handling them.
Do you have your own trading results or any other remarks regarding this expert advisor?
Discuss Chart Pattern Helper with other traders and MQL programmers on the experts forums.
Changelog
1.14 — 2024-03-06
- Fixed a bug that could result in a flood of order modification requests to the trading server without actually modifying anything.
- Fixed all double comparisons to avoid potential issues.
- Fixed a minor bug in the MT5 version of the EA that could lead to a failure while updating a pending order.
1.13 — 2023-05-22
- Fixed another bug with horizontal lines trading.
1.12 — 2023-05-19
- Fixed operation of trendline trading mode with horizontal lines.
1.11 — 2022-07-09
- Minor improvements of position size calculation.
1.10 — 2022-04-25
- Added a "close above/below trendline" entry option.
- Updated input parameters' descriptions.
- Fixed some potential errors in position size calculation.
1.09 — 2020-12-13
- Fixed position size calculation for pending orders when the currency pair's base currency is the same as the account currency.
1.08 — 2020-11-30
- Fixed some stop-loss calculation errors.
1.07 — 2020-11-19
- Position size calculation update.
1.06 — 2020-06-24
- Further improvements for unit cost calculation in MT4.
1.05 — 2020-05-30
- Fixed a bug in MT5 version that caused incorrect pip value calculation in some cases.
1.04 — 2020-05-16
- Fine-tuning the changes introduced in version 1.03.
1.03 — 2020-05-15
- Improved accuracy of position size calculation.
- Fixed potential Error 131 (Invalid trade volume) in MT4 and return code 10014 (TRADE_RETCODE_INVALID_VOLUME) in MT5 due to position size not respecting the trading symbol's volume step parameter.
1.02 — 2020-03-31
- Added adjustment for tick size granularity to prevent OrderSend Error 130 (Invalid stops) in MT4 and Error 4756 in MT5 when the trading instrument's tick size is greater than 1 point. This is particularly useful when trading CFDs.
1.01 — 2019-02-11
- Added an option to set stop-loss to the farthest point of triangle/wedge.
- Fixed a bug that could cause incorrect stop-loss calculation in MT4.
1.00 — 2013-03-07
- Initial release.