Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 5 Libraries | Cosine distance and cosine similarity

function to calculate the cosine distance and the cosine similarity.

The cosine distance between 2 vectors A and B is : 

MetaTrader Experts, Indicators, Scripts and Libraries

So 1-CosineSimilarity

And the cosine similarity is :

MetaTrader Experts, Indicators, Scripts and Libraries

In simple terms :

  • the cosine of the angle between the 2 vectors
  • or , the dot product of the vectors divided by their magnitudes multiplied

Here is the simplest explanation (although his cos(45) is wrong) : 


47793