How get trendline properties by y=k*x+q equation

 

I found some link that explain about y=k*x+q

https://www.mql5.com/en/forum/306293

"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

let consider in a uptrend,

there are two low points

1st point value is 100 at bar 10 ( index 9 )

2nd point value is 105 at bar 5 ( index 4 )


k value get from 105-100 = 5/5 = 1 ( 5 get from 10 bar and 5 bar distance )

So k=1

q =  1st low point value 100

x = 9


y = 1* 9 + 100 = 109 ( current candle value in trend  )


is it correct?


when try in real condition , x value is time axis , so value is not stable ,

cannot get current trend value as example .


How can calculate in real condition

example here is trend

 int CandleonChart = WindowFirstVisibleBar();
    
    int lowestCandle = iLowest(Symbol(),0,MODE_LOW,CandleonChart,0);
    
    ObjectDelete("LT");
    ObjectCreate(0,"LT",OBJ_TREND,0,Time[lowestCandle],Low[lowestCandle],Time[5],Low[5]);
    ObjectSetInteger(0,"LT",OBJPROP_COLOR,clrRed);
    ObjectSetInteger(0,"LT",OBJPROP_STYLE,STYLE_SOLID);
    ObjectSetInteger(0,"LT",OBJPROP_RAY,true);

how calculate by this equation

How to calculate Trend Line values without creat the object?
How to calculate Trend Line values without creat the object?
  • 2019.03.11
  • www.mql5.com
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...