Error: calculating opposite slope direction for Linear Regression | Using vectors with MQL functions
Hi Happy Weekend to everyone
I am trying to calculate Slope of Linear Regression line with vectors. It is calculated but with a opposite direction signal i.e. positive slope is returned as negative slope.
I checked the code and it seems vector.CorrCoef() is causing the issue. e.g if prices are making 'Lower Highs' on recent bars, there is positive correlation between bar number and prices. But the actual slope is negative.
Can you please help me how to rectify this anomaly. Simplest one is, I can put opposite sign before slope, but that is not the correct way of doing it. As it may cause problem if I use the same method for calculating LR between two symbols where bars are not involved.
Thanks in advance.
Thanks for reply Ndawana
I definitely wish to go for AI & ML in future, as I keep improving my MQL skills. I am from a non mathematical background, so these things taken longer than average time a mathematician will take to understand :)
The problem I am trying to resolve now is a simpler one. I have three High prices on ascending or descending bars. I want line of best fit (LR) on these three highs and their slope. This slope I want to use for calculating triangles. e.g. with condition if(MathAbs(slope) <= N) than I conclude it is almost flat upper slope and slope of three lows >= M than, I have ascending tringle.
I have gone through your article LDA, are you referring to the same? In not please share the link. I have read another articles by @Omega J Msigwa on linear regression. They all are good, but I was trying to experiment with vectors + MQL functions instead of using mathematical calculations.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Happy Weekend to everyone
I am trying to calculate Slope of Linear Regression line with vectors. It is calculated but with a opposite direction signal i.e. positive slope is returned as negative slope.
I checked the code and it seems vector.CorrCoef() is causing the issue. e.g if prices are making 'Lower Highs' on recent bars, there is positive correlation between bar number and prices. But the actual slope is negative.
Can you please help me how to rectify this anomaly. Simplest one is, I can put opposite sign before slope, but that is not the correct way of doing it. As it may cause problem if I use the same method for calculating LR between two symbols where bars are not involved.
Thanks in advance.