Equation of a Trend Line In Code... Help Pls

 

Hey - i have a scanner I've written that scans a lot of symbols for various things and there is something I need to add to the logic but am stumped.

I have two points - I need the equation of the line that goes through those two points.

I then need to be alerted next time price reaches that line. Essentially what I need is a trend line but without actually drawing it as I'm scanning A LOT of pairs across different time frames.

Can anyone help with this?

I'm looking at using y=mx+c to create the equation then testing current price within a threshold against that. However am a little stuck on where to start.

Appreciate any and all help!

Cheers!

 

Hi

search on Codebase or freelancer

 
Trinh Dat:

Hi

search on Codebase or freelancer

Hm... Is it very complex? I am fairly apt in coding with an example to work with or some hints, I feel I can get it working. How complicated would you say this task is?

 
Trinh Dat:

Hi

search on Codebase or freelancer

I think i've managed to solve it by counting pips and number of bars of the swings and using ratios. thanks anyway

 
vish4al:

Hey - i have a scanner I've written that scans a lot of symbols for various things and there is something I need to add to the logic but am stumped.

I have two points - I need the equation of the line that goes through those two points.

I then need to be alerted next time price reaches that line. Essentially what I need is a trend line but without actually drawing it as I'm scanning A LOT of pairs across different time frames.

Can anyone help with this?

I'm looking at using y=mx+c to create the equation then testing current price within a threshold against that. However am a little stuck on where to start.

Appreciate any and all help!

Cheers!

Hi,

very simple

use vector not that, cause if your slope (x=0)you will loose your point. not so nice

you have 2 point-> A(x,y)  and B(x,y)  so  vectorAB= (x(B)-x(A),y(B)-y(A)) it will give you a vector

so to draw it ,do that your start A+t*vectorAB     -->> t must be from 0 to 1    .to get the full length A+vectorAB  if your line is not in the right direction A-vectorAB  or B-vectorAB or B+vectorAB

to get knowledge about that use geogebra in 2D.

If you need help ask again

but you have an already trend line from point to point , give the time1, price1, time2, price2 . you check the price and time from candle each minute or more and compare new price with the old price. check in you time frame H1 often the start time is about the same if there is a reversal trend.

to get more informations : y=mx+c if the equation about line so :  m= rise/run -> rise=y  run =x

y/x=slope of your line that you multiply by x  (for any value of x you will get your y )

c is to move the all line in y 

I think it is not so usefull to use that cause you have to check if x = 0.   if you don't you will get an error divide by ZERO !!!

bye

Laurent

Files: