**LONNV: **I optimize EA , no result show , later I know** ObjectFind() and ObjectGet() functions don't work at optimizing!** but in this articles https://www.mql5.com/en/articles/1512. Special Features of Optimization Process. Draw objects are not really set. The objects are **disabled** in order to accelerate the testing.I not know how to disable this objects. My EA entry depend on object get values. How can do that?

Graphical objects are not used during optimisations, so instead use the equivalent math to calculate the value. This will also be much faster than using *ObjectGetValueByShift()*.

For example, instead of using a trend-line object, just use the math for a line "y = m * x + c" to calculate the values.

**Fernando Carreiro #:**

Graphical objects are not used during optimisations, so instead use the equivalent math to calculate the value. This will also be much faster than using *ObjectGetValueByShift()*.

For example, instead of using a trend-line object, just use the math for a line "y = m * x + c" to calculate the values.

how calculate trendline value by math , any formula?

**LONNV #:**how calculate trendline value by math , any formula?

I just gave you the formula for a line in my post: **y = m * x + c**

**Fernando Carreiro #:**

I just gave you the formula for a line in my post: **y = m * x + c**

if I have two coordinate trend points, how replace this points in this equation.

example a point = 1.2345

b point = 1.4566

how replace this values in equation.

in trend object , need Time,Price,Time,Price for coordinate points.

I not understand how replace it.

Y is time axis , X is price axis.

how replace

can you explain ?

thanks

**LONNV #:**if I have two coordinate trend points, how replace this points in this equation. example a point = 1.234, b point = 1.456. how replace this values in equation. in trend object , need Time,Price,Time,Price for coordinate points. I not understand how replace it. Y is time axis , X is price axis.. how replace. can you explain ?

I gave you a link to study how to use the line equation: Equation of a Straight Line

It is all explained there. Did you read it?

**Fernando Carreiro #:**

I gave you a link to study how to use the line equation: Equation of a Straight Line

It is all explained there. Did you read it?

I understand the equation but I not know what values replace in

m is slope value

b is y value when x is zero

x is ? how far along

1st find m

**m** = *Change in Y* **/ Change in X**

m = *2* **/ 1** = 2

b = 1

and then y = 2x + 1

so where is x ?

as graph , x can be see as 1 ,

if x = 1 , y = 2×**1** + 1 = 3

y is current trend value.

So how replace in mql4 code values. Do you have example?

example , i have uptrend two swing points ,

they are two low points .the 1st low is at 10th candle ( 9 index) 2nd low is at 5th candle ( 4 index) .

if x is distance , 9 index and 4th index different is 5 ,

here we get x value.

y = mx + b ;

m value is change in y / change in x .

b is y value when x value at 0 ,

let 10th candle value is 100 , 5th candle value is 105 ,

m = change in y / change in x

change in y = 105-100 = 5

change in x is distance between 10th candle and 5th candle ( index 9 - 4 ) = 5 ;

So , m = 5/5 =1

b is y value when x is zero , So b = 100

y = 1 * x + 100 ;

here x may be distance from 10th candle to 1st candle , 10th candle to current candle , 9th candle distance .

y = 1* 9 + 100 ;

y = 109 = current trend value.

So how can replace this equation in ,

ObjectCreate("mFXNODE.HighLine", OBJ_TREND, 0, Time[mZigHCandel[mSecund_High_Candel]],mZigZagHigh[mSecund_High_Candel],Time[mZigHCandel[mFirst_High_Candel]],mZigZagHigh[mFirst_High_Candel]);

Let

mZigZagHigh[mSecund_High_Candel]

is 10th candle value

mZigZagHigh[mFirst_High_Candel]

is 5th candle value

So change in y = 5th - 10th = Let it be 1.1563-1.1520 = 0.0043

change in x = 5

So m = 0.0043/5 = 0.9259 .

b = 1.1520

y = 0.9259 * x + 1.1520;

y = 0.9259*9 + 1.1520 = ???

it make sense?

can you show correct way .

Please help me.

This piqued my interest so I decided to code up an example for myself.

There was another thread on the subject where a user explained it well.

For example, if you want to have a trend line which connects two lows on a graph with just ten candles.

The first low is on the tenth candle from the right (from the newest) then the first low candle has the index 9 (in MQL4 the current candle has the index 0) and the second low is on the fifth candle (index 4).

The first low price is 100 and second low is 105.

IfThen k=(the second low-the first low)/number of candles between the lows=(105-100)/5=1 and q=the first low=100 . Now you can compute the price on the trend line on the current candle => y=k.x+q=1*9+100=109

It's the same formula that Fernando shared, but the one thing you need to know is that x is equal to the candle index of OBJPROP_TIME1 of the trendline and b is equal to OBJPROP_PRICE1.

What I did was create a trendline and an HLine.

Then, I would get the values of the trendline, plug the values into the formula, then set the resulting value to the HLine chart object to confirm if it was correct.

- 2019.03.11
- www.mql5.com

**Alexander Martinez #:**

This piqued my interest so I decided to code up an example for myself.

There was another thread on the subject where a user explained it well.

It's the same formula that Fernando shared, but the one thing you need to know is that x is equal to the candle index of OBJPROP_TIME1 of the trendline and b is equal to OBJPROP_PRICE1.

What I did was create a trendline and an HLine.

Then, I would get the values of the trendline, plug the values into the formula, then set the resulting value to the HLine chart object to confirm if it was correct.

when you finish your codes , please share me,

here my attempt on trendline of zigzag , but something still wrong.

ObjectCreate("FXNODE.LowLine", OBJ_TREND, 0, Time[ZigLCandel[Secund_Low_Candel]],ZigZagLow[Secund_Low_Candel],Time[ZigLCandel[First_Low_Candel]],ZigZagLow[First_Low_Candel]);

```
double m = ZigZagLow[First_Low_Candel] - ZigZagLow[Secund_Low_Candel]/Lbar-LLastBar ;
double b = ZigZagLow[Secund_Low_Candel];
gl_LineValLow = m*Lbar + b ;
Print("low line value"+gl_LineValLow+"");
```

low line value is 2.42995941252 ,

this is not correct answer of trendline .

Still wrong in some codes.

**LONNV #:**

when you finish your codes , please share me,

here my attempt on trendline of zigzag , but something still wrong.

low line value is 2.42995941252 ,

this is not correct answer of trendline .

Still wrong in some codes.

Organize your code so you can see the formula better:

double mNumerator = ZigZagLow[First_Low_Candel] - ZigZagLow[Secund_Low_Candel]; double mDenominator = Lbar-LLastBar; // Why not use First_Low_Candel and Secund_Low_Candel? They should be the same as Lbar and LLastBar. double m = mNumerator / mDenominator; double b = ZigZagLow[Secund_Low_Candel]; // In a trendline, this would be the value of OBJPROP_PRICE1 int x = ZigZagLow[Secund_Low_Candel]; // This value should be a candle index. In a trendline, it would be the candle index of OBJPROP_TIME1. double y = (m * x) + b; Print("Trendline value at index 0 is " + DoubleToString(y, Digits));

EDIT: this assumes you're only looking for the value of the trendline at index 0.

If you want to check another index, then subtract x by the candle index.

**Alexander Martinez #:**

Organize your code so you can see the formula better:

EDIT: this assumes you're only looking for the value of the trendline at index 0.

If you want to check another index, then subtract x by the candle index.

thanks bro,

if for downtrend , there will be two high points,

1st high point is greater than 2nd higher point ,

So need to substractas follow ,

`double mNumerator = ZigZagHigh[Secund_High_Candel] - ZigZagHigh[First_High_Candel];`

right?

or need to be negative sign infront of mNumerator ?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets

You agree to website policy and terms of use

I optimize EA , no result show , later I know

ObjectFind() and ObjectGet() functions don't work at optimizing!but in this articles

https://www.mql5.com/en/articles/1512

## Special Features of Optimization Process

The objects are

disabledin order to accelerate the testing.I not know how to disable this objects .

My EA entry depend on object get values

How can do that