//+------------------------------------------------------------------+ //| Lot size computation. | //+------------------------------------------------------------------+ double LotSize(double SL_points, bool modifying = false) { /* This function computes the lot size for a trade. * Explicit inputs are SL relative to bid/ask (E.G. SL=30*points,) and if * returned lot size will be used in a new order or be used to modify an * pending order (trade count-1.) Implicit inputs are the MM mode, the MM * multiplier and currently filled or pending trade count (used to reduce * available balance.) Mode, multiplier, adjusted account balance determined * the maximum dollar risk allowed. StopLoss determines the maximum dollar * risk possible per lot. Lots=maxRisk/maxRiskPerLot **************************************************************************/ double ab = AccountBalance(); switch(MMMode_F0M1G2) { case MMMODE_FIXED: atRisk = MMMultplier; break; case MMMODE_MODERATE: // See https://www.mql5.com/en/articles/1526 Fallacies, Part 1: Money // Management is Secondary and Not Very Important. atRisk = MathSqrt(MMMultplier * ab)/ab; // % used/trade ~const. atRisk = MathSqrt(MMMultplier * ab * MathPow( 1 - atRisk, OrdersTotal()-modifying )); break; case MMMODE_GEOMETRICAL: atRisk = MMMultplier * ab * MathPow(1 - MMMultplier, OrdersTotal()-modifying); break; } double maxLossPerLot = SL_points/Point * MarketInfo( Symbol(), MODE_TICKVALUE ); // IBFX demo/mini EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000 // 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/standard EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000 // $1.00/point or $10.00/pip. double LotStep = MarketInfo( Symbol(), MODE_LOTSTEP ), // atRisk / maxLossPerLot = number of lots wanted. Must be rounded/truncated // to nearest lotStep size. // // However, the broker doesn't care about the atRisk/account balance. They // care about margin. margin used=lots used*marginPerLot and that must be // less than free margin available. marginFree = AccountFreeMargin(), // Free Margin marginPerLot = MarketInfo( Symbol(), MODE_MARGINREQUIRED ), // So I use, the lesser of either. // I don't use MODE_MAXLOT as OpenNow handles that. size = MathFloor( MathMin ( marginFree / marginPerLot , atRisk / maxLossPerLot ) / LotStep )*LotStep; // truncate if (size < MarketInfo( Symbol(), MODE_MINLOT )) { // Multiple orders -> no free margin -> LotSize(SL=4.1)=0 // [risk=9.48USD/40.80, margin=10.62/1334.48, MMM=1x1, coat=0] // 0.23 0.007 Print( "LotSize(SL=", DoubleToStr(SL_points/pips2dbl, Digits.pips), ")=", size, " [risk=", atRisk, AccountCurrency(), "/", maxLossPerLot, ", margin=", marginFree, "/", marginPerLot, ", MMM=", MMMode_F0M1G2, "x", MMMultplier, ", coat=", OrdersTotal(), // Count Of active trades "]" ); return(0.0); // Risk limit. } atRisk = size * maxLossPerLot; // Export for Comment return(size); } // LotSize
Hi,
What is pips2dbl ?
Digits.pips is MarketInfo(Symbol(),MODE_DIGITS)*MarketInfo(Symbol(),MODE_POINT); right ?
tx
//++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
Any idea for calculating TSSF value ?
The article states:
Which is ambiguous. Rereading the original article I get: safe "avg.Win/Ave.loss" = ((110% - %Win) / (%Win-10%) + 1) and TSSF is defined as the ratio of (actual avg.win/ave.loss) / (safe "avg.Win/Ave.loss")
Therefor TSSF = Avg.Win / Avg.Loss / ((110% - %Win) / (%Win-10%) + 1)
or TSSF = Avg.Win /( Avg.Loss * ((110% - %Win) / (%Win-10%) +
1) )
In the article Fig 3 is labeled Moving value of %Win (correct) The
graph itself is incorrectly labeled TSSF. Estimating %win (Fig 3) and WinLossRatio (Fig 4) my unambiguous equations do calculate corresponding TSSF (Fig 5)
Example of usage was this French post Système de Money Management adapté aux systèmes irréguliers
Example of usage was this French post Système de Money Management adapté aux systèmes irréguliers Translated to English Beware the code listed does not use the above equations. That writer took the article formula as TSSF = Avg.Win / Avg.Loss * ((110% - %Win) / (%Win-10%) + 1)
The question I ask in this forum https://www.mql5.com/en/forum/117857 is also relevant here.
However, one example in this article uses TSSF to set lot sizes...
If ((tssf> 0.5) and (tssf <= 0.75)) lot = 0.2
If ((tssf> 0.75) and (tssf <= 1)) lot = 0.5
If ((tssf> 1) and (tssf <= 1.25)) lot = 1.5
If ((tssf> 1.25) and (tssf <= 1.5)) lot = 2.0
If ((tssf> 1.5)) lot = 2.5
I think a better way to calculate lot size from the TSSF-based Trade Encouragement Factor TEF is given in https://www.mql5.com/en/forum/110048
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everybody :)
I need to complete my Money Management system. Anyone has Trading System Safety Factor aka TSSF (https://championship.mql5.com/2012/en/2008) EA in box ?
Currenlty, i have these 3 cases:
1/ fixe
2/ geometrical
3/ proportionnal
Regards,
S.T