You will probably find some example code in the CodeBase, but the main MQL5 function to consider is OrderCalcProfit.
Essentially, you would iterate over current positions (real exposure) and current pending orders (possible exposure), and apply the function (summing it all up), taking into account the Type (buy/sell), Symbol, Volume, Open price and Stop-Loss price of each position and/or pending order.
You will probably find some example code in the CodeBase, but the main MQL5 function to consider is OrderCalcProfit.
Essentially, you would iterate over current positions (real exposure) and current pending orders (possible exposure), and apply the function (summing it all up), taking into account the Type (buy/sell), Symbol, Volume, Open price and Stop-Loss price of each position and/or pending order.
Oh amazing, I never new the OrderCalcProfit function existed. Thank you very much for pointing me in the right direction!
- www.mql5.com
Thank you. It appears the only issue is you can't call either from within an indicator, they are only available in EA's. https://www.mql5.com/en/docs/runtime/running;
Which is ok... I'll just have to re-think the way I do this slightly.
Cheers!
- www.mql5.com
Then use the following ...
[Money Value] = [Volume] * [Stop Size] * [Tick Value] / [Tick Size]
Forum on trading, automated trading systems and testing trading strategies
How to calculate take profit from currency
Fernando Carreiro, 2022.09.05 17:00
These are all the same equation written in different ways ...
[Volume] = [Money Value] * [Tick Size] / ( [Tick Value] * [Stop Size] ) [Stop Size] = [Money Value] * [Tick Size] / ( [Tick Value] * [Volume] ) [Money Value] = [Volume] * [Stop Size] * [Tick Value] / [Tick Size] [Volume] in lots [Stop Size] in quote price change [Money Value] in account currencyForum on trading, automated trading systems and testing trading strategies
Fernando Carreiro, 2022.05.18 21:05
double dbTickSize = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE ), // Tick size dbTickValue = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_VALUE ), // Tick value dbPointSize = SymbolInfoDouble( _Symbol, SYMBOL_POINT ), // Point size dbPointValue = dbTickValue * dbPointSize / dbTickSize; // Point valueRemember, it's best to use tick size and tick value in your calculations, instead of point size and its value.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I would like to make an indicator that shows the total account exposure - i.e. the amount in account currency that the trader would loose if all open positions and pending orders were filled and all hit stop loss. Once I have this figure I would then show it as a percentage of account size.
I know in MT5 if you hover mouse over SL level it shows the amount for that position you would loose if stop loss is hit. I need a way to find the total for all stop loss amounts for all open orders.
Is there a way to programmatically get this figure for each ticket at sum them together?