Looking for help calculating Lin Reg for Indicator

TradeChaser

Active Trader
May 12, 2020
161
6
34
32
I am trying to call properties of a Linear Regression channel. I have tried created an indicator that creates a LinearRegression object, and then reads from it, such as below:

MQL4:
Iterates through code:
{
    Create OBJ_Regression;
    price1 = ObjectGet(name of obj, OBPROP_PRICE1);
    price2 = ObjectGet(name of obj, OBPROP_PRICE2);
    ObjectDelete(regression)
}

I am doing this because I want to know the absolute difference between the end point of the linear regression line and the start point. When I draw and object via script, I am able to call those properties above. However, when I try to create an indicator that makes an oscillator of this information, nothing seems to work.

My proposed work around is to simply calculate the actual linear regression line myself (was trying to bypass this by creating the Lin Reg channel and reading data from it) and then read the two data points I am looking for.

The only problem is I just don't understand how to create/calculate the said Linear Regression line.

If there is any assistance that can be lent here, that would be awesome. I suppose my direct ask is:

What would be the formula for the LinReg, and how then would I extract the price levels of the terminal points of this information so I can create an oscillator of the difference.
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
18,622
1,367
144
Odesa
www.earnforex.com
I am doing this because I want to know the absolute difference between the end point of the linear regression line and the start point. When I draw and object via script, I am able to call those properties above. However, when I try to create an indicator that makes an oscillator of this information, nothing seems to work.
There shouldn't be a problem for the indicator to access the chart objects info. If you are creating the object from within the same indicator, you just have to make sure that the object is created before you let the indicator read the properties. So, it's best to have some timer even, which will check if the indicator is there, and let the indicator process it on the next tick.
What would be the formula for the LinReg, and how then would I extract the price levels of the terminal points of this information so I can create an oscillator of the difference.
Please see the attached indicator.
 

Attachments

  • Linear Regression.mq4
    6.7 KB · Views: 3