Hello
I uses below function for calculate lot size in MQL5 for use simple OrderSend (symbol EURUSD_i and Alpari broker).
my balance is 1000$.
When I input the function with certain stoppless and 1% risk, I exepted margin be 10$.
But margin become fixed value: 2.16$
Why? can anyone help me?
There are so many solution to calculate the lot size: https://www.mql5.com/en/search#!keyword=calculation%20lot%20size.
Learn to search before you start programming. There is practically nothing that has not already been programmed for MT4/MT5!
Hi
Margin and risk per trade are interconnected in trading, but they represent different aspects of risk management. Margin determines the size of the position a trader can take based on available capital and leverage,
double volume = PositionGetDouble(POSITION_VOLUME); double margin_required = SymbolInfoDouble(symbol, SYMBOL_MARGIN_INITIAL) * volume
while risk per trade determines the percentage of capital a trader is willing to risk on each individual trade.
double riskOfTrade = volume*dbLossOrder,
So when you calculate the lot from risk – you don’t calculate margin. Required margin s not the risk directly.
Have a nice weekend
Hi
Margin and risk per trade are interconnected in trading, but they represent different aspects of risk management. Margin determines the size of the position a trader can take based on available capital and leverage,
while risk per trade determines the percentage of capital a trader is willing to risk on each individual trade.
So when you calculate the lot from risk – you don’t calculate margin. Required margin s not the risk directly.
Have a nice weekend
Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin or leverage. No SL means you have infinite risk (on leveraged symbols). Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% account total.
-
You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce, the stop goes below the support. Then you compute your lot size.
-
AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/PIP, but it takes account of the exchange rates of the pair vs. your account currency.)
-
Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum (2017)
Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum (2018)
Lot value calculation off by a factor of 100 - MQL5 programming forum (2019) -
You must normalize lots properly and check against min and max.
-
You must also check Free Margin to avoid stop out
-
For MT5, see 'Money Fixed Risk' - MQL5 Code Base (2017)
Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.
Thank you for the answer. I understood the logic. In order for the margin to be a fixed number like $10 for all symbols, how should I calculate the lot/volume?
Hi
I suppose if you want to set the lot size based on margin only and set the lot size to manage the chosen part of your margin – you need to get this value of required margin per 1 lot:
SymbolInfoDouble(symbol, SYMBOL_MARGIN_INITIAL)
And calculate the chosen value using simple proportion. For example - if you need 1000$ margin to open 1 lot – and you want to use only 10$ margin –you need to open 1/100 part of 1000$ - and that means that you can open 1/100 part from 1 lot = 0.01.
You can try if this is working for you.
Best Regards
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
I uses below function for calculate lot size in MQL5 for use simple OrderSend (symbol EURUSD_i and Alpari broker).
my balance is 1000$.
When I input the function with certain stoppless and 1% risk, I exepted margin be 10$.
But margin become fixed value: 2.16$
Why? can anyone help me?