I needed for a strategy to get the geometric distance between 2 points. The platform does not provide the api of the ruler tool. So I implemented the function as an indicator and here is the code I share with you. This is not really an indicator but rather a utility function for developers. See below:
// name : GeomDistance
// author : patmaba
// date : 2017/12/10
//
// Description
// -----------
// return the distance between two points
//
// parameters :
// -----------
// (pt1X, pt1Y) coordinate of first point
// (pt2X, pt2Y) coordinate of second point
//
// return :
// --------
// distValue return the distance
distValue = SQRT((pt2X-pt1X)*(pt2X-pt1X)+(pt2Y-pt1Y)*(pt2Y-pt1Y))
return distValue as "distance"
Thank you for this nice useful function. So what is the unit distance returned? Could we consider it as “time based”?
When you take the tool ruler, the result of the tool displays a grey box with a distance value expressed in decimal number followed by a percentage which represents the difference between 2 points.
The “GeomDistance” function calculates the decimal value that depends on the configuration of your user interface.
Hmm, so it depends only of price? Why not a simple division between 2 prices? as the X coordinates isn’t needed in this case. Anyway, this is useful function, thank you 🙂
I use GeomDistanct on lines that are oblique and whose extreme points do not directly touch the candle.
oh ok! Got a better idea now to know how to use it.