Using spline(s)

 

This thread will be dedicated to spline(s) usage in technical analysis

________________________

Direct cause for considering splines is the request by simba to create a manual nonlinear trend line, and how ever I thought of it, it seemed that the most logical way of doing it was to use some of the spline methods for solving the problem of connecting a set of random points in an acceptable way.

For starters here is a link with a basic explanation of splines : Spline (mathematics) - Wikipedia, the free encyclopedia

The one used in this particular solution is a cubic spline (more info about cubci spline itself can be found here : Spline interpolation - Wikipedia, the free encyclopedia ). Some other solutions will be added with time as they are finished and tested. Also, the idea of using splines as a way to interpolate is rather appealing in some other implementations (mtf-ing for example), so it seems that we do not need to limit ourselves to just one indicator and just one way of using those, hence this thread is created to keep all eventual developments using spline in this thread.________________________

Now, of the indicator :

It is a strictly manual indicator (in the manner that user has to define the control points) "Defining" control points is easy : in the parameters choose the number of control points (PointsNumberparameter), control points prefix (PointsPrefixparameter) and control points initial spacing (PointsIntialBarsSpacingparameter) you wish to use. Once the initial set of points is created (initially it uses a close as a price when creating new points), you can drag the points at locations you wish, add or remove control points (by changing PointsNumber parameter). Control points are not limited to present and past but can be dragged to "future" too (here is an example of a manual cubic spline trend line with a couple of control points defined in future)
Minimal number of points used is 2, and in the case when you use 2 points you are getting a special case of cubic spline : a linear interpolation (since there are only 2 points, all it can draw is a straight line between the 2 points and that straight line is, in effect, a linear interpolated line. So, in a implicit manner, this indicator covers a "simple" linear trend line too (here is an example of a simple linear interpolation done when points number is set to 2)
________________________

Of one feature specific for this indicator only : clearly a basic problem of this indicator is the way how control points are managed. Most of the problem comes from a manner how metatrader treats objects and what is needed to be done in any code in order to make it "tidy". So, in order to "know" what to do with points, this indicator is using one more option : SaveAndRestorePoints. If that option is set to true, then the indicator will save and restore points positions in a file named symbol+PointsPrefix.csv. It has to be done so in order to be able to keep the points visible between time frames, consecutive runs of metatrader, and ultimately, when done this way, indicator can clear the points from the screen when removed from the chart (that is the basic need that had to be done and this is the only acceptable way to do this). It does not distinguish time frames (since that would mean that changing time frame would force you to create a new indicator settings) nor the control points (since changing control points would also imply the same)

But exactly this way of saving and restoring points gives us some nice features of the indicator. Here is an example of what I mean : upper is a 30 minute chart and lower is the 1 hour chart - as you can see it behaves as a multi time frame indicator already without even using any multi time frame parameter and it will do so across all time frames

Also, since it has a saved set of points, if indicator is removed and that placed back (with the same number of points) it will draw exactly what was the last state of the indicator without the need of remembering what was it. If you wish to prevent this "behavior", turn the SaveAndRestorePoints parameter to false

________________________

So much for now

Since already there had been some suggestions as of what else could it do, will see what can be done regarding that and also will see some new (automatic) implementations - frankly, ideas are flooding now and will see what of those are going to be usable for all of us

________________________

PS: "mnt" in name comes from "manual non-linear trend line" (it has nothing to do with my name )

PPS: the distance of points from a line comes from a fact that those are actually objects that are characters *chr(159) to be exact) and not graphical points (check the prices of those objects and you will see that they are the same as the value of the line, it is only the way how metatrader treats "arrows") , but I rather like it this way, since the points are clearly visible this way. Also, the new spline will be updated on a first tick if any of the points has been moved. In times when there are no ticks (weekends) you have to change time frames to force drawing of the changed curve

Files:
cubic_1.gif  20 kb
cubic_2.gif  19 kb
cubic_3.gif  22 kb
cubic_4.gif  19 kb
 

mladen

What i haveto set to see in the futures in this indicators ...mnt - cubic spline...

 

bebeshel

As I said in the original post : you have to drag a point to the place where you want it. It (the dragged point) can be in the future too, so simply drag the rightmost point to the right )into the "future").

And remember : this is a manualnonlinear trend line - it does not update by values but buy user manually placing / draging points and curve to desired value

regards

Mladen

bebeshel:
What i haveto set to see in the futures in this indicators ...mnt - cubic spline...
 

Well

Here is a first variation

A good thing about well defined interpolations (and cubic spline is a well defined interpolation) is that it is very easy to turn them "upside down" - to make them extrapolate instead to interpolate. And this version has both : interpolation based on user defined points, and then, as a sort of "prediction", an extrapolation to the future of the last defined point by required bars

Additional parameter added for that purpose is ExtrapolateBars: as it is saying it is the number of bars that the indicator will extrapolate to the right of the last (rightmost) defined point, and in that case it looks like this (the dotted line on the right is a cubic spline extrapolation) :
It works equally in linear mode too (when you define only 2 control points and when it turns to linear interpolation - in that case it is doing a linear extrapolation)

_________________________

To conclude : this is still a manual nonlinear trend line (user has to define and manage control points) Some "automatic" versions will follow soon I guess as soon as an acceptable manner of automatic finding control points emerges

 

Thanks

Mladen,

Thanks a lot for the time you took to do this indicator.

This is perfect for manually creating nonlinear trendlines,please see pic.

I think that there is few or no literature regarding nonlinear trendlines,but what is clear is that the market is nonlinear,so,using linear trendlines to analyze a nonlinear market was not enough,IMO

Thanks again and Regards

S

Files:
nltl2_1.gif  76 kb
 

Mladen ,

Thanks for this advanced indicator.Can you use the cubic spline as centre of gravity and measure the deviations from it as a seperate indicator?Just curious are the points keep changing I mean, would that make the deviations keep recalculating like hodrick prescott filter?Thanks.

 

Results

SIMBA:
Mladen,

Thanks a lot for the time you took to do this indicator.

This is perfect for manually creating nonlinear trendlines,please see pic.

I think that there is few or no literature regarding nonlinear trendlines,but what is clear is that the market is nonlinear,so,using linear trendlines to analyze a nonlinear market was not enough,IMO

Thanks again and Regards

S

Mladen...See pic...continuation of my previous post,looks like the breakdown of the nonlinear trendline worked fantastically well.

S

Files:
nltl1_1.gif  81 kb
 

How does it differ from the moving average?

 

Janusz

There are some links at the first post in which you can find an explanation how splines are calculated and what are they. The one used in the posted one is a cubic spline. It has almost nothing in common with moving averages. Splines are mostly used for interpolating (some info about interpolation can be found here : https://en.wikipedia.org/wiki/Interpolation ), but as you can see, they can be used for extrapolation too (some info about extrapolation can be found here : https://en.wikipedia.org/wiki/Extrapolation ).

To remind the original request of simba and what actually the "mnt" indicator is : it is a nonlinear manual trend line which uses cubic spline to calculate curves for manually placed control points (points that are below the line can be moved by mouse - click once on it (till you see a little square around it) and drag it wherever you wish and see what is going to be drawn)

regards

Mladen

Janusz123:
How does it differ from the moving average?
 
mladen:
Well

Here is a first variation

A good thing about well defined interpolations (and cubic spline is a well defined interpolation) is that it is very easy to turn them "upside down" - to make them extrapolate instead to interpolate. And this version has both : interpolation based on user defined points, and then, as a sort of "prediction", an extrapolation to the future of the last defined point by required bars

Additional parameter added for that purpose is ExtrapolateBars: as it is saying it is the number of bars that the indicator will extrapolate to the right of the last (rightmost) defined point, and in that case it looks like this (the dotted line on the right is a cubic spline extrapolation) :
It works equally in linear mode too (when you define only 2 control points and when it turns to linear interpolation - in that case it is doing a linear extrapolation)

_________________________

To conclude : this is still a manual nonlinear trend line (user has to define and manage control points) Some "automatic" versions will follow soon I guess as soon as an acceptable manner of automatic finding control points emerges

Hi mladen.

I'm studying this indicator and i found it very useful.

HAve you found the way for automated the dot point where connect indicator?

Thank you very much

 

...

dasio

Frankly I did not work on that. At first I thought to make it a multi time frame interpolation (which is already done in one version of "averages" where quadratic spline is used for interpolation) but from cubic on, the changed bars back would extend too much in my opinion.

Probably some other mode of finding points than equidistant (multi time frame is equidistant in it's nature) that would then be connected by splines should be used. since it largely depends on those points, it seems to be the crucial point that would determine the whole result (and usefulness) in the end

dasio:
Hi mladen.

I'm studying this indicator and i found it very useful.

HAve you found the way for automated the dot point where connect indicator?

Thank you very much
Reason: