How to calculate Trend Line values without creat the object?

To add comments, please log in or register
Sharon Aharonov
222
Sharon Aharonov  

Hi all,

Does anyone know if there is a possibility to calculate Trend Line values without the need to create it on the chart?


Thanks,

Petr Nosek
3024
Petr Nosek  
Sharon Aharonov:

Hi all,

Does anyone know if there is a possibility to calculate Trend Line without the need to create it on the chart?


Thanks,

Of course. A trend line is an ordinary line which is described by following formula y=k.x+q where "y" is the price axis and "x" the time axis. You need to determine two points and you can calculate the coefficients "k" and "q". If you get the coefficients you can easily calculate any point on this line. But you should use a bar's number instead of time because of the inconsistent time axis (weekends, missed bars...).

Sharon Aharonov
222
Sharon Aharonov  
Petr Nosek:

Of course. A trend line is an ordinary line which is described by following formula y=k.x+q where "y" is the price axis and "x" the time axis. You need to determine two points and you can calculate the coefficients "k" and "q". If you get the coefficients you can easily calculate any point on this line. But you should use a bar's number instead of time because of the inconsistent time axis (weekends, missed bars...).

Thanks Petr,

But I didn't understand something, what are the "k" and "q" means?

Can you give an example, please?

Petr Nosek
3024
Petr Nosek  
Sharon Aharonov:

Thanks Petr,

But I didn't understand something, what are the "k" and "q" means?

Can you give an example, please?

Linear function graph


"k" for the red line is 1/2 and for the blue line -1

"q" for the red line is 2 and for the blue line 5

In general, "k" is a tangent angle between the line and axis x and "q" is a shift on axis y.

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

Sharon Aharonov
222
Sharon Aharonov  
Petr Nosek:


"k" for the red line is 1/2 and for the blue line -1

"q" for the red line is 2 and for the blue line 5

In general, "k" is a tangent angle between the line and axis x and "q" is a shift on axis y.

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

Got it Petr, very helpful, thank you very much!!

To add comments, please log in or register