Trendlines

We have been asked by users how to draw trendlines in NeuroShell with a particular slope and Y intercept, or between two points.

The regression indicators in the Neuroshell Trader draw imaginary straight lines through a whole window of consecutive data. For example, the regression slope indicator gives you the slope of such a straight line. However, since the window moves across the entire time series, the line you see plotted is not the straight line, but the slope of that straight line as it changes with each window. The plotted line is not straight since it changes as the window moves.

You cannot actually DRAW any such straight lines on the chart with the regression indicators. (You can do it with advanced Indicator set 1 using Polynomial regression with degree=1, but the points still have to be consecutive. See the Addons section of www.neuroshell.com for more information about Advanced Indicator Set 1.) The NeuroShell Trader was not built for that type of visual technical analysis. It was designed so that you can use the values produced by such indicators in formulas, rules, and neural nets, including the slope, the next point on the line, etc.

The indicators in the Regression category draw imaginary lines through the last N data points in the time series. You can then use the indicators to get the future points on that line (so for example you can subtract the daily close from it).

But suppose you want to draw an imaginary straight line through two non-consecutive points, or through one point with a given slope?

Let’s take the latter example first. You can draw imaginary lines where the slope and Y axis are pre-specified, like slope=0.16 and Y intercept (price) = 62 for a given bar. Use the old high school formula y=mx+b. In this case you get y=0.16*x+62. You can assume that at the current bar is x=0 if the current bar is where the price is 62. Then if you plug in x=1 (the next bar), you’ll get y=62.16, and the next bar y=62.32. The last bar is y=61.84. You can make an indicator called “line” if you want to that takes the daily index (-1, 0, 1,2,3, etc), the slope, and the Y intercept, and returns the current value of the line.

In fact we have just made such an indicator which you can download by clicking here. After downloading, run the file and extract the contents to the Template folder of NeuroShell, restart NeuroShell, and the indicator will appear in the Custom Indicators category as the indicator “line”. It requires release 3.2 or better.

The line indicator assumes a line with a certain slope has been drawn through today’s close, and it will give you the point on this line N days from now by feeding N into the parameter called “daily index”. For N days ago, feed in -N. The “slope” parameter defaults to .16 but can be set to any desired slope (or you can let the optimizer do that.)

Now let’s take the case where you have two points that you want to put a line through. The high school formula is (y-y1)/(x-x1) = (y2-y1)/(x2-x1) where the y are the prices and the x are the index values -1, 0, 1, 2, etc. Let’s say y is the price you want on the line at bar x. Then y=y1+(x-x1)(y2-y1)/(x2-x1). You could make an indicator called “line2” to compute y, which we have done for you. We made a DLL to do the work instead of building the formula in the Indicator Wizard (we also included the PowerBasic source code). If you want the price 5 bars from now on the line through the last bar and the one one 10 bars before that, then set x1=-1, x2=-11, and x=5. This indicator finds the y1 and y2 prices from the time series, and then returns y.

Note: You may be tempted to use our trendline indicators in the optimizer. If you do, make sure you don’t allow the optimizer to put lines through bars in the future. If you let that happen, your neural net or trading strategy that is being optimized will be looking into the future, and you’ll get great (but unrealistic) results. To guard against this, set the optimization ranges so that your daily index, or x1, or x2 values are always zero or negative.

Was this article helpful?

Related Articles