Nonlinear regression forex

Nonlinear regression forex

Posted: AffMaster On: 25.06.2017

Do you like the article? Share it with others - post a link to it! Use new possibilities of MetaTrader 5. An acquaintance of mine when attending a Forex trading course, once received an assignment to develop a trading system. After having trouble with it for about a week, he said, that this task was probably more difficult than writing a thesis. It was then that I suggested using the multiple regression analysis. As a result, a trading system developed from scratch overnight was successfully approved by the examiner.

The success of using the multiple regression is in the ability to quickly find relationships between indicators and price.

The relationships detected allow to predict the price value based on the indicator values with a certain degree of probability. Modern statistical software allows to simultaneously filter thousands of parameters in trying to find these relationships.

This can be compared to industrial sifting gold from gravel. A ready to use strategy as well as a strategy generator will be developed by loading the indicator data into the multiple regression analysis and applying data manipulation, respectively.

This article will demonstrate the process of creating a trading strategy using the multiple regression analysis. The backbone of the trading system developed overnight as mentioned earlier was one sole equation:. The equation was an outcome of the multiple regression analysis that used the data sample from standard indicators. An EA was developed on the basis of the equation. The piece of code in charge of trading decisions virtually consisted of 15 lines only.

The data sample for the regression analysis was collected on EURUSD H1 over two months from July 1, to August 31, It is peculiar that superprofit, which is often the case in the Tester, was not observed on the training data.

It must be a sign of lack of reoptimization. EA performance over the training period. It appears that the two-month data was sufficient for the EA to remain profitable for another two months. That said, the profit made by the EA over the testing period was the same as over the training period.

EA performance over the testing period. Thus, based on the multiple regression analysis a fairly simple EA was developed yielding profit beyond the training data.

The regression analysis can therefore be successfully applied when building trading systems. However, resources of the regression analysis should not be overestimated. Its advantages and disadvantages will be set forth further below. The general purpose of the multiple regression is the analysis of the relationship between several independent variables and one dependent variable.

In our case, it is the analysis of the relationship between values of indicators and the price movement. A regression equation can only be generated if there is a correlation between independent variables and a dependent variable. Since values of indicators are as a rule interrelated, the contribution made by indicators to the forecast may appreciably vary if an indicator is added or removed from the analysis.

Please note that a regression equation is a mere demonstration of the numerical dependence and not a description of causal relationships. Coefficients a, b indicate the contribution made by every independent variable to its relationship with a dependent variable.

A regression equation represents an ideal dependence between the variables. This is however impossible in Forex and the forecast will always differ from the reality. Difference between the predicted and observed value is called the residual.

Analysis of residuals allows to identify inter alia a nonlinear dependence between the indicator and price. In our case, we assume that there is only nonlinear dependence between indicators and price.

Fortunately, the regression analysis is not affected by minor deviations from linearity. It can only be used to analyze quantitative parameters. Qualitative parameters that do not have transitional values are not suitable for the analysis.

The fact that the regression analysis can process any number of parameters may lead to the temptation to include into analysis as many of them as possible. But if the number of independent parameters is bigger than the number of observations of their interaction with a dependent parameter, there is a great chance of getting equations producing good forecasts which are however based on random fluctuations.

The number of observations shall be times bigger than the number of independent parameters. In our case, the number of indicators contained in the data sample shall be times bigger than the number of trades in our sample. The equation generated will then be considered reliable. The sample based on which the Robotrader as described in section 1 was developed, contained 33 parameters and observations. As a result, the number of parameters was 25 times bigger than the number of observations.

This requirement is a general rule in statistics. It is also applicable to the MetaTrader 5 Strategy Tester optimizer. Furthermore, every given value of the indicator in the optimizer is in fact a separate parameter. In other words, when testing 10 indicator values, we are dealing with 10 independent parameters which shall be taken into consideration in order to avoid reoptimization.

A report of the optimizer should probably include another parameter: If the indicator value is less than ten, chances are that reoptimization will be required. Another thing to be considered is outliers. Rare yet powerful events in our case price spikes may add false dependencies to the equation.

For example, following the unexpected news, the market responded with substantial movements lasting for a few hours. The values of technical indicators would in this case be of little importance in the forecast yet they would be considered highly significant in the regression analysis as there was a marked price change.

It is therefore advisable to filter the sample data or check it for possible outliers. We have approached the key part where we will see how to generate a regression equation based on your own data.

Implementation of the regression analysis is similar to that of the discriminant analysis set forth earlier on.

Multiple regression analysis is a part of numerous advanced software products intended for statistical data analysis. The most popular are Statistica by StatSoft Inc. We will further consider the application of the regression analysis using Statistica 8.

We are to generate a regression equation where the price behavior on the next bar can be predicted based on the indicator values on the current bar. The same EA that was used for the discriminant analysis data preparation will be used for collecting data. We will expand its functionality by adding a function for saving indicator values with other periods.

An extended set of parameters will be used for strategy optimization based on the analysis of the same indicators but with different periods.

To load data in Statistica, you should have a CSV file with a following structure. Variables shall be arranged in columns where every column corresponds to a certain indicator. The rows shall contain consecutive measurements cases , i. In other words, the horizontal table headers contain indicators, the vertical table headers contain consecutive bars. Thus, we will generate an equation describing the future price behavior based on the known indicator values.

Apart from the absolute indicator value, we need to save the difference between the absolute and the preceding values in order to see the direction of the change in indicators. The names of such variables in the example provided will have prefix 'd'. For signal line indicators, it is necessary to save the difference between the main and signal line as well as its dynamics. In order to demonstrate the optimization, only one period was added, being twice the length of the standard period of the indicator.

In addition, save the time of the new bar and the relevant hour value. Save the difference between Open and Close for the bar where the indicators are calculated. This will be required to filter outliers. As a result, 33 parameters will be analyzed to generate a multiple regression equation. The file as obtained can be used in Statistica. An example of such file can be found in MasterDataR.

The data was collected for EURUSD H1 from January 3, to November 11, using the Strategy Tester. Only the August and September data was used in the analysis.

The remaining data was saved in a file for you to practice. Click OK to get the table containing our data which is ready for the multiple regression analysis.

nonlinear regression forex

An example of the obtained file to be used Statistica can be found in MasterDataR. Running the regression analysis. In the opened window, go to the Advanced tab and enable the marked items. Click the Variables button. Select the Dependent variable in the first field and Independent variables based on which the equation will be generated - in the second field. In our case, select the Price parameter in the first field and Price 2 to dWPR - in the second field. Preparation to selection of parameters.

A window will open for selection of cases data rows which will be used in the analysis. Enable items as shown in Fig.

Specify the data pertaining to July and August that will be used in the analysis. These are cases from to The numbers of cases are set via the variable V0. In order to avoid the effect of outliers and price spikes, add data filtering by price. Include in the analysis only those indicator values for which the difference between Open and Close on the last bar is not more than points.

By specifying here the rules for selecting cases for the analysis, we have set a data sample for regression equation generation. Click OK here and in the window for preparation to selection of parameters Fig.

A window with options of the automatic data selection methods will open. Select the Forward Stepwise method Fig. And a window will open informing you that the regression analysis was successfully completed.

Window of results of the regression analysis. Automatic selection of parameters concerns only those that contribute materially to the multiple correlation between the parameters independent variables and the dependent variable. In our case, a set of indicators will be selected, best determining price. In effect, the automatic selection acts as a strategy generator.

The generated equation will only consist of the indicators that are reliable and best describe the price behavior. The upper part of the window of results Fig. Please pay attention to the underlined characteristics. Multiple R is the value of multiple correlation between the price and indicators included in the equation. A level of less than 0.

The indicators whose contribution is statistically significant are displayed in red. Ideally, all indicators shall be marked in red. The rules used in Statistica for including parameters in the analysis are not always optimal. For example, a great number of insignificant parameters may get included in a regression equation. We should therefore use our creativity and assist the program in selecting parameters.

If the list contains insignificant parameters, click Summary: Report on the parameters included in the regression equation. Find an insignificant parameter with the highest p-level and remember its name. Go back to the step where the parameters were being included in the analysis Fig. To return, click Cancel in the window of the analysis results and repeat the analysis.

Try to exclude all insignificant parameters in this manner. In so doing, look out for the obtained multiple correlation value Multiple R as it should not be considerably lower than the initial value. Insignificant parameters can be removed from the analysis one by one or all at once, the first option being more advisable.

As a result, the table now only contains the significant parameters Fig. An infinitely long numerical series is known to have an infinite number of random coincidences.

Since data samples we process are quite large, random coincidences and random relationships are often the case. It is therefore important to use statistically significant parameters in your strategies. The equation includes the significant parameters only.

If following the selection of the parameters, a group of several indicators significantly correlating with the price cannot be formed, the price is likely to contain little information on the past events. Trades based on any technical analysis should in cases like this be very prudent or even suspended altogether. In our case, only five out of 33 parameters have proven to be effective in developing a strategy on the basis of the regression equation.

This quality of the regression analysis is of great benefit when selecting indicators for your own strategies. So we ran the regression analysis and obtained the list of the 'right' indicators. Let us now transform it all into a regression equation. The equation coefficients for every indicator are shown in column B of the regression analysis results Fig.

The Intercept parameter in the same table is an independent member of the equation and is included in it as an independent coefficient. This equation was set forth earlier in section 1 as an MQL5 code along with the performance results obtained from the Tester for the EA developed on the basis of this equation. As can be seen, the regression analysis was adequate when used as a strategy tester. The analysis brought forward a certain strategy and selected relevant indicators from the proposed list.

These checks can be carried out using the residual analysis. To proceed to the analysis, click OK in the window of results Fig. After carrying out the above checks with regard to the generated equation, you will see that the equation does not appear to be sensitive to a small number of outliers, small deviation from the normal distribution of data and a certain nonlinearity of the parameters. If there is a significant nonlinearity of relationship, a parameter can be linearized.

For this purpose, Statistica offers a fixed nonlinear regression analysis. To start the analysis, go to the menu: In general, the performed checks have proven that the multiple regression analysis is not sensitive to a moderate amount of noise in the analyzed data.

^X_NonLinearRegression - indicator for MetaTrader 5 | Forex MT4 Indicators

Since the regression analysis is capable of processing thousands of parameters, it can be used to optimize strategies. Thus, if 50 periods for an indicator need to be processed, they can be saved as 50 individual parameters and sent to the regression analysis, all at once. A table in Statistica can fit parameters.

When processing 50 periods for every indicator, around indicators can be analyzed! It is far beyond the capabilities of the MetaTrader 5 Standard Tester. Let us optimize the data used in our example in the same way. As mentioned in section 4. Our sample now contains 60 parameters including the standard period indicators. Following the steps as set forth in section 3. Results of the analysis of the indicators with different periods. The regression equation has comprised 11 parameters: The correlation of the parameters with the price increased by a quarter.

Parameters of the MACD indicator for both periods appeared to be included in the equation. Since values of the same indicator for different periods are treated as different parameters in the regression analysis, the equation may comprise and combine values of the indicators for different periods.

The analysis by the Standard Tester is never so detailed. The regression equation generated on the basis of the extended analysis Fig. Let us see the results this equation will yield in the EA.

The chart has got smoother and the EA has yielded more profit. Let us test the EA over the testing period from September 1 to November 1, The profit chart has become worse than it was in case with the EA with standard period indicators only.

The equation as generated might need to be checked for normality and nonlinearity of internal indicators. Since nonlinearity was observed in standard period indicators, it could become critical over the extended period.

In this case, the equation performance can be improved by linearizing the parameters. Either way, the EA was not a total meltdown over the testing period, it simply did not profit. This qualifies the developed strategy as quite stable. It should be noted that MQL5 supports the output of only 64 parameters in one line of a file. A large-scale analysis of indicators over various periods will require merging the data tables which can be done in Statistica or MS Excel.

A small study presented in the article has shown that the regression analysis provides an opportunity to select from a variety of indicators the most significant ones in terms of price prediction.

It has also demonstrated that the regression analysis can be used to search for indicator periods that are optimal within a given sample. It should be noted that regression equations are easily transformed into MQL5 language and their application does not require high proficiency in programming. Thus, the multiple regression analysis can be employed in trading strategy development. That said, a regression equation can serve as a backbone for a trading strategy.

Translated from Russian by MetaQuotes Software Corp. I was wondering how much your method differs from the built in MT5 optimizer take som indicators, play them on past data, this give them some weight and apply the result to the "futur". The EA parameters were calculated from 6. So, it was test on the data it was trained. In this article, you said "removed the insignificant parameter with the highest p-level".

I removed I run analyzed again, but all of p-level was changed and the parameter which p-level significant turn to insignificant. Are you run analyzed only on 5 params or more? Some parameters be hiddend. Do I need to erase all of the info from that section and make my sections look like yours?

Where is the Statistica program on MQL 5? How do I open it? Maybe it would be better for me to ask you if you would help me with what I am trying to do or if you know someone that can?

I will share the wealth on the idea, but do not want it pubplished nor marketed. Please contact me via email dennie yahoo. Actually they don't even appear in my MT5. Does anyone knows what the rwason could be.

I will be really greatful! Thank you in advance! Best regards, Nikolay Hristov. This article seeks to upgrade the indicator created earlier on and briefly deals with a method for estimating forecast confidence intervals using bootstrapping and quantiles.

As a result, we will get the forecast indicator and scripts to be used for estimation of the forecast accuracy. In the article "Dr. Moreover, we decided to create an Expert Advisor that can not only optimize parameters of one trading system underlying the EA, but also select the best one of several trading systems.

Let's see what can come of it If we thoroughly examine any complex trading system, we will see that it is based on a set of simple trading signals. Therefore, there is no need for novice developers to start writing complex algorithms immediately.

This article provides an example of a trading system that uses semaphore indicators to perform deals. The article is intended to get its readers acquainted with the Box-Cox transformation.

The issues concerning its usage are addressed and some examples are given allowing to evaluate the transformation efficiency with random sequences and real quotes.

How Regression Channels Can Enhance Your Trend Trading

MetaTrader 5 Examples Indicators Experts Tester Trading Trading Systems Integration Indicators Expert Advisors Statistics and analysis Interviews MetaTrader 4 Examples Indicators Experts Tester Trading Trading Systems Integration Indicators Expert Advisors Statistics and analysis.

MetaTrader 5 — Trading Systems. Introduction An acquaintance of mine when attending a Forex trading course, once received an assignment to develop a trading system. Developing a Robotrader - Piece of Cake! The backbone of the trading system developed overnight as mentioned earlier was one sole equation: Importing the file into Statistica. Attached files Download ZIP. All rights to these materials are reserved by MQL5 Ltd.

Copying or reprinting of these materials in whole or in part is prohibited. Last comments Go to discussion 4. First of all thank you for your article which I read with great attention.

Any comment from you on this question would be appreciated. Hi ArtemGaleev Thank you for your awsome article, I have read it many times. And I have some questions: Maybe I wrong in some steps. Anyway, thank you very much for this article. Time Series Forecasting Using Exponential Smoothing continued This article seeks to upgrade the indicator created earlier on and briefly deals with a method for estimating forecast confidence intervals using bootstrapping and quantiles. Rise of the Trading Machines In the article "Dr.

Simple Trading Systems Using Semaphore Indicators If we thoroughly examine any complex trading system, we will see that it is based on a set of simple trading signals. The Box-Cox Transformation The article is intended to get its readers acquainted with the Box-Cox transformation.

Rating 4,3 stars - 331 reviews
inserted by FC2 system