Hi, just to clarify, by "volume size" do you mean "position size"?
What do you mean non linear? It's strictly linear.
double perLotPerPoint = PointValuePerLot(), at.risk.balance = 0; for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == Magic.Number // my magic number && OrderSymbol() == Symbol() ){ // and symbol if (OrderType() == OP_BUY) double DIR=+1.; else DIR=-1.; double size = OrderLots(), eRisk = DIR* (OrderOpenPrice() - OrderStopLoss()); at.risk.balance += eRisk*size*perLotPerPoint; } ... } 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. }
-yep position size...
by non linear i meant -->
-The relationship between the position size and my accountbalance is not linear
as the account balance increases the position size grows less rapidly - thus the precentage of risk per trade decreases as the account balance grows
M = MathRound ( MathLog (AccountBalance()/(367.88/M+1) ) / MathLog (2.72) );
But nevermind... i think i got the point
thanks everybody !
sergeyrar:
by non linear i meant -->
thus the precentage of risk per trade decreases as the account balance grows
I'd suggest
by non linear i meant -->
thus the precentage of risk per trade decreases as the account balance grows
extern int MM.F0M1G2 = 2; // Money Management Mode #define MMMODE_FIXED 0 // $ #define MMMODE_MODERATE 1 // SQRT(MMM*AB) #define MMMODE_GEOMETRICAL 2 // MMM*AB #define MMMODE.MAX 2 extern double MM.PerTrade = 0.03; extern double MM.MaxRisk = 0.03; double LotSize(double risk){ /* 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 **************************************************************************/ /*++++ Compute lot size based on account balance and MM mode*/{ double ab = AccountEquity() - at.risk.equity; switch(MM.F0M1G2){ case MMMODE_FIXED: double maxRisk = MM.MaxRisk; break; case MMMODE_MODERATE: // See https://www.mql5.com/en/articles/1526 Fallacies, Part 1: Money // Management is Secondary and Not Very Important. maxRisk = MathSqrt(MM.MaxRisk * ab); break; case MMMODE_GEOMETRICAL: maxRisk = MM.MaxRisk * ab; break; } double minLot = MarketInfo(Symbol(), MODE_MINLOT), lotStep = MarketInfo(Symbol(), MODE_LOTSTEP), perLotPerPoint = PointValuePerLot(), maxLossPerLot = (risk+Slippage.Pips*pips2dbl) * perLotPerPoint, size = minRisk / maxLossPerLot; // Must still round to lotStep. /*---- Compute lot size based on account balance and MM mode*/} /* 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. Using the lesser of size vs * AccountFreeMargin / MODE_MARGINREQUIRED should have been 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://www.mql5.com/en/forum/128506 * * Second problem, after opening the new order, if free margin then drops to * zero we get a margin call. In the tester, the test stops with: "EA: * 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. */ EA.status = "SL>AE"; // Assume size < minLot while (true){ // Adjust for broker, test for margin size = MathFloor(MathMax(0.,size)/lotStep)*lotStep; at.risk.new = size * maxLossPerLot; // Export for Comment if (size < minLot){ /*at.risk.new=0;*/ return(0); } if (at.risk.new+at.risk.balance > maxRisk){ size = (maxRisk-at.risk.balance)/maxLossPerLot; EA.status = "MaxRisk"; continue; } // Multiple open trades double AFMC = AccountFreeMarginCheck(Symbol(), op.code, size), eRisk = at.risk.equity + risk*size*perLotPerPoint; /* at.risk.equity += Direction( OrderType() ) * * (OrderClosePrice()-OrderStopLoss())*perPoint; * Summed for all open orders. */ if (AFMC*0.99 <= eRisk){ size *= 0.95; EA.status = "Free Margin"; continue; } // Prevent margin call if new trade goes against us. break; } return(size); // We're good to go. } // LotSize
WHRoeder:
I'd suggest
I'd suggest
hi WHRoeder ...
I'm quite new a this..
can you please explain what do I do with this program ? Do i just copy it ??

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I use the following formula to set the volume size
M = MathRound ( MathLog (AccountBalance()/(367.88/M+1) ) / MathLog (2.72) );
-------------------------------------------------V
OrderSend(Symbol(), OP_SELL, 0.01*M, Bid, 2, Ask+stoploss*Point*K, Ask-takeprofit*Point*K)
here is the formula for fixed fractional position size : R=e^((-2*a/d)/(ln(1-z)/ln(1-d)))