/*********************************************************************************************** Title: Multi-Timeframe Regression Line Script for eSignal By: Divergence Software, Inc. Web: http://www.sr-analyst.com ================================================================================================ Project Description: The MTF-Regression indicator allows you to create regression trend channels based on any bar interval and not just the bar interval you are using in your chart. So, for example, you can load a 5-min chart and accurately plot a regression channel calculated using 65 Daily bars (or Weekly bars or Monthly bars, or 63-min bars or whatever interval you wish to use). This is something that cannot be accomplished with standard regression utilities. Multiple copies of the indicator can be loaded into any chart so you can track regressions based on several different intervals with ease. Extrapolation: Another important feature of the MTF-Regression indicator is its ability to extrapolate the correct line slope when not enough bars are present in your viewing timeframe to draw the actual regression line. For example: Let's say that you are viewing a 5-min chart with a 5-Day Time Template. This means that you have 5-days worth of 5-min data loaded into your eSignal Chart. Now, if you load the MTF-Regression indicator and configure it to plot a 15-bar regression using Daily bars, it is fairly obvious that the indicator will not be able to plot the actual regression line from startpoint to endpoint because you do not have enough data available in your chart (e.g., the start point of this regression is 15 days back and you only have 5 days worth of 5-min data loaded in your chart). In this situation the MTF-Regression indicator will use an algorithm to estimate the number of bars back in your viewing bar interval to the start point of the regression line (taking into account holidays, weekends, etc.) and with that information it can determine the correct line slope to apply when it draws what amounts to a partial regression line (See the Extrapolate Bars menu parameter below). The only limitation associated with the extrapolation logic is the number of Daily bars available at any given time as defined by your Time Template. The extrapolation routines use Daily bars as proxy to determine what segments of time should be skipped due to weekends and holidays. So the number of Daily bars available as per your Time Template definition will be the upper limit as to the length of any regression that you can plot. If you plan on plotting very large regressions (e.g., like a 50-bar regression using Monthly bars plotted on a 5-min chart) then just be sure to set your eSignal Time Template to pre-load a very large number of Daily bars whenever they are requested. Note that whenever the MTF-Regression indicator is forced to use the extrapolation logic, it will print the letter "E" just to the right of the study title so that you are aware that extrapolation was used. Script Parameters: Interval: The bar interval to use for the regression analysis. If you leave this field blank, the script will use the bar interval of the current chart. Note that the interval specified in this field should always be larger than the interval in your chart (e.g., if you are viewing a 1-min chart, you would want to set the regression interval to a 1-min or higher interval. Lin Reg Period: The period to use for calculating the regression (e.g., the regression length). The default value is 20 and the minimum acceptable value is 3. Note that the period is used in conjunction with the Interval you select for the regression calculation. So if you set the Interval to 60 and the Period to 15, a regression will be calculated using 15 60-min bars regardless of the interval you are plotting in your chart. Lin Reg Source: The price source to use in the regression calculation. The default value is "H-L Flip" and you can choose from Close, Open, High, Low, HL/2, HLC/3 and OHLC/4. The "H-L Flip" option will force the regression to be calculated using the Lows when the trend is up and the Highs when the trend is down. Lin Reg Calc Type: Select from Standard Deviation or Standard Error. The eSignal regression line tool uses Standard Error. Lin Reg Offset: The offset to use when calculating the regression. The default value is 0 and you an input any positive integer. Note that the offset is used in conjunction with the Interval you select for the regression calculation. So if you set the Interval to 60, the Period to 15, and the Offset to 2, the regression will be calculated using 15 60-min bars but will shift the calculation back by 2 60-min bars. The key point here is that the Offset is applied to the regression Interval rather than the interval you are plotting in your chart. Std. Deviations: The number of standard deviations/standard errors to use for the upper and lower channel lines. The default value is 1. Set this option to 0 if you only want the regression line and no channels. Remember that the standard deviation is calculated using the regression Interval rather than the interval you are charting. Lin Reg Color: The color to use when drawing the actual regression line. StdDev Band Color: The color to use when drawing the regression channels. Line Thickness: The line thickness to use when drawing the regression line and channels. Line Type: Line type to use when drawing the regression line and channels. Select from Solid, Dot, Dash, DashDot and DashDotDot. Lin Reg Extension: How many bars past the regression endpoint to extend the lines. The default value is 15. This menu option can be set to any positive integer value or zero. Extrapolate Bars: This is the drawing line length to use when the indicator is in extrapolation mode. See the discussion above on Extrapolation for more information. The default value is 400 and it can be set to any positive integer value. Draw Upper Band: True or False. If True then the upper regression line will be drawn. If False, then the upper regression line will not be drawn. Draw Basis: True or False. If True then the regression basis line will be drawn. If False, then the regression basis line will not be drawn. Draw Lower Band: True or False. If True then the lower regression line will be drawn. If False, then the lower regression line will not be drawn. Draw Intervals: True or False. If True then the interval used to calculate the regression will be printed just to the right of the lines. This makes it easier to identify the various regressions when multiple copies of the script (using different intervals) are loaded into the same chart. Font Size: The size of the font to use when printing the intervals. Disclaimer: For educational purposes only! Obviously, no guarantees whatsoever and use at your own risk. *******************************************************************************************************/