afaik the leverage has only influence on the margin you require to open one lot. if you want use 2% of your possible trading balance (Balance*Leverage) you have to include that into your calculation.
//z
Hello,
When I use the OrderSend command to my broker, does the Lot value get multiplied by my leverage when they receive it, or am I supposed to use the AccountLeverage() function in my lot size calculation?
Say I send a value of 1 for lot, when I send the order, does my broker multiply it by 50 if I use a 50:1 ratio.
Or
Say I want to trade 2% of my account, do I mutliply 2% of account X AccountLeverage(), then divide the lot cost by that?
Thanks!
Leverage is not used that way in the lot size aspects of your position. Leverage is used to determine margin requirements and not much else.
What do you mean by "trade 2% of my account"? Do you mean you want to open a position which is sized (lotsize) such that when it is stopped out for loss then those losses will be equal to 2% of your account's value at the time the position was opened?
Don't feel bad, it took me a year to realize I had been calculating my margin requirements wrong. But thankfully it didn't make a material difference in my results. But if I had to do it again I'd invest more time in understanding how the numbers work before I started trading.
//+------------------------------------------------------------------+ //| Lot size computation. | //+------------------------------------------------------------------+ double oo.count; // Import from ModifyStops double LotSize(double risk){ /*double TEF.value, // Import from ComputeTEF //double at.risk; // Export to init/start //bool need2refresh; // Import from RelTradeContext //int op.code; // -1/OP_BUY/OP_SELL // Import from setDIR */ /* This function computes the lot size for a trade. * Explicit inputs are SL relative to bid/ask (E.G. SL=30*points,) * Implicit inputs are the MM mode, the MM multiplier, count currently * filled orders by all EA's vs this EA/pair/period count and history. * Implicit inputs are all used to reduce available balance the maximum * dollar risk allowed. StopLoss determines the maximum dollar risk possible * per lot. Lots=maxRisk/maxRiskPerLot **************************************************************************/ if (need2refresh) Refresh(); /*++++ Compute lot size based on account balance and MM mode*/{ double ab = AccountBalance(); switch(Money.Management.F0M1G2){ case MMMODE_FIXED: at.risk = Money.Management.Multiplier; break; case MMMODE_MODERATE: // See https://www.mql5.com/en/articles/1526 Fallacies, Part 1: Money // Management is Secondary and Not Very Important. // %used/trade= at.risk = MathSqrt(Money.Management.Multiplier * ab)/ab; // ~const rate. at.risk = MathSqrt(Money.Management.Multiplier * ab * MathPow( 1 - at.risk, OrdersTotal() )); break; case MMMODE_GEOMETRICAL: at.risk = Money.Management.Multiplier * ab * MathPow(1 - Money.Management.Multiplier, OrdersTotal()); break; } double maxLossPerLot = risk * PointValuePerLot(), /* Number of lots wanted = at.risk / maxLossPerLot rounded/truncated to * nearest lotStep size. * * However, the broker doesn't care about the at.risk/account balance. They * care about margin. Margin used=lots used*marginPerLot and that must be * less than free margin available. */ marginFree = AccountFreeMargin(), marginPerLot = MarketInfo( Symbol(), MODE_MARGINREQUIRED ), // So I use, the lesser of either. size = MathMin(marginFree / marginPerLot, at.risk / maxLossPerLot); /*---- Compute lot size based on account balance and MM mode*/} double adjFact = IfD(MathMin(1, TEF.value), 1, TEF.Enable01), minLot = MarketInfo(Symbol(), MODE_MINLOT), LotStep = MarketInfo(Symbol(), MODE_LOTSTEP), perLotPerPoint = PointValuePerLot(); while (true){ // Adjust for broker, test for margin, combine with TEF size = MathFloor(size/LotStep)*LotStep; double eRisk = risk*(oo.lots+size)*perLotPerPoint; if (size < minLot){ // Insufficient margin. Print( "LotSize(SL=", DoubleToStr(risk/pips2dbl, Digits.pips), ")=", size, " [risk=", at.risk, AccountCurrency(), "/", maxLossPerLot, ", margin=", marginFree, "/", marginPerLot, ", MMM=", Money.Management.F0M1G2,"@",Money.Management.Multiplier, ", OO=", oo.count, ", Lots=", oo.lots, ", EquRisk=", eRisk, "]" ); size=0; break; } /* size<minLot should be sufficient, but the tester was generating error * 134 even when marginFree should have been OK. So I also use * AccountFreeMarginCheck < 0 which agrees with the tester. * Reported at https://forum.mql4.com/35056 * * Second problem, after opening the new order, if free margin drops to * zero we get a margin call. In the tester, the test stops: "WHRea14: * stopped because of Stop Out" So I make sure that the free margin * after is larger then the equity risk so I never get a margin call. */ double AFMC = AccountFreeMarginCheck(Symbol(), op.code, size); /**/ if (AFMC <= eRisk) size *= 0.95; else if (adjFact < 1){ size = MathMax(minLot,size*adjFact);adjFact=1;} else break; // We're good to go. } at.risk = size * maxLossPerLot; // Export for Comment return(size); } // LotSize double PointValuePerLot() { // Value in account currency of a Point of Symbol. /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147) * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip. * IBFX demo/mini EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000 * IBFX demo/standard EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000 * $1.00/point or $10.00/pip. * * https://forum.mql4.com/33975 CB: MODE_TICKSIZE will usually return the * same value as MODE_POINT (or Point for the current symbol), however, an * example of where to use MODE_TICKSIZE would be as part of a ratio with * MODE_TICKVALUE when performing money management calculations which need * to take account of the pair and the account currency. The reason I use * this ratio is that although TV and TS may constantly be returned as * something like 7.00 and 0.00001 respectively, I've seen this * (intermittently) change to 14.00 and 0.00002 respectively (just example * tick values to illustrate). */ return( MarketInfo(Symbol(), MODE_TICKVALUE) / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point. }
- 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,
When I use the OrderSend command to my broker, does the Lot value get multiplied by my leverage when they receive it, or am I supposed to use the AccountLeverage() function in my lot size calculation?
Say I send a value of 1 for lot, when I send the order, does my broker multiply it by 50 if I use a 50:1 ratio.
Or
Say I want to trade 2% of my account, do I mutliply 2% of account X AccountLeverage(), then divide the lot cost by that?
Thanks!