This is a carry over from the 'Need lines indicator' thread. I thought that Spaced Lines merited its own thread, especially as I can edit post #1 each time I upgrade the indicator.
Latest update: version 3.03, uploaded May 19, 2019
Latest changes to this post in red typeface
All of the required files are in the attached zip. Install them into the same MT4 folders as they are located in the zip.
ParameterFile - if blank, the parameter file Presets---Spaced Lines.TXT will be used. Settings in this file will override those entered in the dialog window when the indicator is attached/edited. If you enter a value (e.g. XXX), then the parameter file Presets---Spaced Lines.XXX will be used instead. This makes it easy to switch between a number of different settings. If you leave the parameter set as NONE, then (assuming a file Presets---Spaced Lines.NONE doesn't exist), the settings you enter in MT4's dialog window will be used. All parameter files must reside in the ....../experts/files folder. See 'PARAMETER FILE' section below for more info
StartPrice - simply entering a number (e.g. 1.3165, 85.389) will mean that the price entered will be used as the 'zero point' from which the lines are plotted. Otherwise you can make an entry like:
Cx,y - this means that the close x bars ago (0 is the currently forming bar), rounded to the nearest y pips, will be used as the zero point, e.g., to draw round numbers starting at XX50, enter C0,50 or simply C,50
work the same, using the open, high, low prices instead.
You can omit the ,y part, if you don't require rounding, e.g. C0 (or simply C) will use the close of bar #0 as the zero point
PriceLevels - up to 100 levels may be entered, separated by commas
-- a zero value (0) will plot a line at the zero point
-- positive values (X) will plot a line X pips above the zero point
-- negative values (-X) will plot a line X pips below the zero point
If you set AbsolutePrices to TRUE, the StartPrice and zero value does not apply. Simply enter absolute price values, separated by commas.
AbsolutePrices - if TRUE, PriceLevels represent absolute price values, and StartPrice (zero point) does not apply. If FALSE, PriceLevels are calculated relative to the zero point.
LineColors - up to 100 values may be entered, separated by commas. These determine the color that will be used to plot the line at the corresponding entry in PriceLevels. If only one value is entered, all lines will be plotted in that color
LineStyles - up to 100 values may be entered, separated by commas. These determine the width/style that will be used to plot the line at the corresponding entry in PriceLevels. If only one value is entered, all lines will be plotted using that width/style. Valid values for style are: 10 = solid line of width 1; 11 = dashed line; 12 = dotted line; 13 = dash-dot; 14 = dash-dot-dot; 20, 30, 40, 50 = solid line of width 2, 3, 4, 5 respectively.
TimeFrames - determine which timeframes on which the lines will be visible. Valid entries are M1, M5, M15, M30, H1, H4, D1, W1, MN. Can be upper or lowercase, use commas to separate entries.
UniqueID - allows you to add multiple instances of the indicator to the same MT4 chart, by giving each one a different UniqueID. (This prevents MT4 from becoming confused as to which objects belong to which instance of the indicator).
CounterLookback - if 0, this has no effect.
If a positive number, a count is made of how many of the last CounterLookback candles have reached or intersected this price level line.
If a negative number, a count is made of how many of the candles showing in the price window have reached or intersected this price level line.
The count is displayed at the left of the chart, as the object description. You must have 'Show object descriptions' checked ON (press F8, and select the Common tab) in order to view the descriptions.
Example #1: to plot lines at round number levels 50 pips apart, with XX00 values as solid lines, and XX50 values as dotted lines:
StartPrice = "C0,100"; PriceLevels = "-500,-450,-400,-350,-300,-250,-200,-150,-100,-50,0,50,100,150,200,250,300,350,400,450,500"; LineColors = "DimGray"; LineStyles = "10,12,10,12,10,12,10,12,10,12,10,12,10,12,10,12,10,12,10,12,10"; UniqueID = "0" CounterLookback = 0;
Example #2: to plot dashed lines at XX20 and XX80 levels:
StartPrice = "C0,100"; PriceLevels = "-480,-420,-380,-320,-280,-220,-180,-120,-80,-20,20,80,120,180,220,280,320,380,420,480"; LineColors = "DimGray"; LineStyles = "11"; UniqueID = "0" CounterLookback = 0;
To display price labels just above the lines, press F8 to get the chart options, then on the 'Common' tab, check 'Show object descriptions' ON.
To remove the nuisance of having to retype the same parameter settings every time you attach the indicator to a chart, you have two options:
1. Use MT4 templates (but these overwrite any other indicators, objects, etc that you also have on the chart). In this case, the indicator settings are defined when you attach or edit the indicator, using MT4's built-in dialog.
2. Use parameter file(s), as follows:
- If you enter nothing or TXT into the ParameterFile setting, then the indicator looks for a parameter file called Presets---Spaced Lines.TXT in the ...../experts/files folder.
- If you enter any other text (e.g. XXX, 001, etc) into the ParameterFile setting, then the indicator looks for a parameter file called Presets---Spaced Lines.XXX, Presets---Spaced Lines.001, etc in the ...../experts/files folder. (This allows you to set up a different definition in each file, then simply enter the file suffix when you attach the indicator).
If the file can't be found, then the settings in MT4's dialog will be used. If the file is found, then the settings in the file will be used instead. Hence if you want to force the use of the MT4 dialog settings, simply enter the name of a non-existent file.
Use a text editor like Notepad to view and/or edit the parameter presets files.
To disable an entry in the file, start the line with two slashes (//). (This means that the setting specified in the MT4 dialog will be used.) To re-enable it, remove the slashes. If you have multiple 'unslashed' entries in the file, the last will be used.
You may use any number of embedded spaces or underscores, and/or any combo of upper or lower case, to aid readability, however you wish.
Every line in the file (including blank lines, and lines beginning with two slashes) MUST end with a semi-colon (; ). Failure to do this will cause unpredictable results.
To save typing and improve accuracy, copy/paste the sample lines in the file. To disable the entire file, rename it, or delete its content.
To have any changes take immediate effect, either (1) re-attach the indicator to your chart; (2) edit the indicator (press Ctrl-I); or (3) toggle between timeframes.
v 3.00: Initial release.
v 3.01: Added CounterLookback parameter.
v 3.02: Added AbsolutePrices parameter.
v 3.03: Addressed requests in posts #36, #37. The latest attached zip file (above) also includes the parameter files from this post.
Terms and conditions
All code is supplied FREE of charge. It may NOT be sold or distributed commercially.
Software is offered on an 'as is' basis. I'm not offering a programming or troubleshooting service. Source code is not currently available.
There is no guarantee that the software is fit for purpose, or free of errors. Download and use the indicator(s) at your own risk; I accept no liability for computer damage or financial losses.