Help to calculate the lot based on my currency.

 

Hi, I am making an EA where you place the stop loss (for example, 50 EUR), where you want with double click on chart, and it automatically calculates lot size and open a market position. Is there some universal mathematical equation to calculate risk based on my currency, that uses volume of the contract, the precision, the pips and does not depend on whether I am in forex, metals, cfds...?

 

search codebase for: "position size calculator" and you get a lot of what you want.

https://www.mql5.com/en/code/24365

MQL5 Version of Position Size Calculator - Based on VP Money Management rules
MQL5 Version of Position Size Calculator - Based on VP Money Management rules
  • www.mql5.com
MT5 (MQL5) Version of Position Size Calculator - Based on VP Money Management rules This version has been tested and works in both versions; in MT4 (MQL4) as well as in MT5 (MQL5). See the original MT4(MQL4) only version here: https://www.mql5.com/en/code/23886 NOTE: I'm aware there appears to be an issue with the volume calculation and cross currency exchange rates. I'm working on fixing these issues.