Top Menu

Feedburner

Right-Side Top Menu

MetaTrader Script to Add Parallel Channels

February 24, 2013 (Last updated on June 5, 2014)

Sometimes, I post a sort of chart pattern analysis that often consists of channel patterns — descending, ascending or horizontal. They all share some common traits:

  • Each one has a main pattern — a channel. On my charts, it is marked with yellow lines.
  • Each has two entry lines for channel breakouts. The upper one is located at upper border + 10% of channel’s height. The lower one is located at lower border — 10% of channel’s height. They are depicted using cyan (or more precisely, turquoise) lines on my charts.
  • Each has two target lines. Similarly to the entry lines, they are placed at 100% of the channel’s height from the border lines. Their color is green (actually, lime green).

Recently I have been asked by one of the blog readers about how do I draw the entry/target channels at 10%/100% distance of the channel’s height accurately. Until yesterday, I did it this way:

  1. I used the standard Equidistant Channel object to draw the channel borders.
  2. I placed the control dot of the Equidistant Channel’s auxiliary line directly above or below the first or last control dot of the Equidistant Channel’s main line:
    Auxiliary Border Placement
  3. Then, right-clicking the channel and choosing “Channel properties…”, and then “Parameters” tab would show me exact price levels for those control dots:
    Channel Parameters
  4. Subtracting the price levels with the same time coordinates would yield the exact channel height value.
  5. Then, it could be used to place both Entry and TP channels. Two new channels would be placed with their control dots aligned in time to the control dots of the Border channel.
  6. Adding and subtracting 10% and 100% of height from the Border’s channel price levels would position Entry and TP channels exactly where needed.

Yesterday, I have decided to code a MetaTrader 4 script that would do all this automatically. Now, all I need to do is only to place the initial Border channel, name it “Border” and run the script. It will do all the calculations and place the 10%/100% channels completely by itself. Unfortunately, MetaTrader does not support input parameters for scripts, but the percentage levels and some other properties can be easily modified via the script’s source code: Thanks to Medhat Ramses, you can now easily modify all the parameters of the script via MetaTrader native Inputs tab.

You can download the .mq4 file of the script or the same source code in .zip. Please do not forget that scripts should be placed in your MetaTrader’s /experts/scripts/ folder.

Update 2013-02-27: The script was updated to work normally when Entry and TP objects are already on the chart. For example, when you have just repositioned the Border channel, running the script will also reposition Entry/TP channels properly.

Update 2013-02-28: The script is now also available for MetaTrader 5: .mq5 and .zip.

Update 2013-04-13: Fixed the error in MT4 version of the script that caused division by zero on horizontal channel processing.

Update 2013-10-01: Input parameters are now working in both MT4 and MT5 versions. Also fixed the type of the style input parameters.

Update 2014-06-05: New version allows drawing one-sided entry/TP lines and fixes a serious bug in MT5.

If you have any comments or questions about this channel markup script, please post them using the form below.

10 Responses to “MetaTrader Script to Add Parallel Channels”

  1. Armin

    Wow – you rock! Thanks for that!

    Reply

    Armin Reply:

    Errr, sorry, but I can’t get it to work. I use the Equidistant Channel tool to craw the channel. Then I run the script. Nada.

    Reply

    admin Reply:

    The name of the channel you draw should be “Border”, or you can change it to something else if you modify that in script.

    Reply

    Armin Reply:

    Aha! Perfect, thank you!

    Reply

  2. Andrej

    Hello everyone. The script does not start :-(. Giving up on schedule and there was no reaction.

    Reply

    admin Reply:

    Is there any output in the Experts tab? Have you added the initial Border channel and named it “Border”?

    Reply

    Andrej Reply:

    I just put the file in the script. When I want to throw on a graph, then nothing happens. And what that something else must be done?

    Thanks

    Reply

    admin Reply:

    I still need to know the output from the Experts tab of your MT4 when you do that.

    And, of course, you first have to add a channel and rename it to “Border” in order for the script to work at all.

    Reply

  3. Medhat Ramses

    Quote “Unfortunately, MetaTrader does not support input parameters for scripts, but the percentage levels and some other properties can be easily modified via the script’s source code:”

    Thank you very much for the script. MT4 does support input parameters for scripts. Just add the line:
    #property show_inputs

    above the section where the variables are declared and make the variables external by the word “extern” before declaring them.

    Reply

    admin Reply:

    As they say it: Live and learn! Thanks for letting me know. I have updated the scripts accordingly.

    Reply

Leave a Reply

required
required (will not be published)
optional

Follow EarnForex Blog on Facebook