Menu
Brokers
MT4 Forex Brokers
MT5 Forex brokers
PayPal Brokers
Skrill Brokers
Oil Trading Brokers
Gold Trading Brokers
Web Browser Platform
Brokers with CFD Trading
ECN Brokers
Bitcoin FX Brokers
PAMM Forex Brokers
With Cent Accounts
With High Leverage
Cryptocurrency Brokers
Forums
All threads
New threads
New posts
Trending
Search forums
What's new
New threads
New posts
Latest activity
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Reply to thread
Forums
Trading Platforms
MetaTrader Expert Advisors
Mql5 function to calculate position size
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
[QUOTE="Poker_player, post: 189431, member: 50152"] Have tried searching and implementing but cannot find correct example. Its weird because it should be needed for lot of people and should exist somewhere. Can you give a link or code for that? So far I have done by examples this [CODE=mql5] double calculateLotSizeForPips(double slPips, double maxRiskPerTradePercent){ //Calculate the size of the position size double LotSize=0; //We get the value of a tick //double nTickValue=MarketInfo(Symbol(),MODE_TICKVALUE); // not used double nTickValue = SYMBOL_TRADE_TICK_VALUE; //If the digits are 3 or 5 we normalize multiplying by 10 /*if(_Digits==3 || _Digits==5){ nTickValue=nTickValue*10; }*/ float balance = AccountInfoDouble(ACCOUNT_BALANCE); //We apply the formula to calculate the position size and assign the value to the variable LotSize=(balance*maxRiskPerTradePercent/100)/(slPips*nTickValue); //LotSize=MathRound(LotSize/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP); // not used double volumeStep = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP); LotSize=MathRound(LotSize/volumeStep)*volumeStep; return LotSize; }[/CODE] But it works bad. Testing on USDJPY pair, usd account. I do not know why in the example was when digits are 3 or 5 - multiply by ten , but it make my position 10 times smaller. So for 10k account, when I put to formula it is: Risk 2 percent, pips 4, tick value 26 10000*0.02/(4*26) = 1.92 Code with volume step is not changing the result. But it is wrong. [ATTACH type="full"]17521[/ATTACH] It loses about 80 usd. 2 % from 10k is 200. Backtest shows it has lost about 75 [ATTACH type="full"]17522[/ATTACH] its more or less what the function calculated. But it is not 200. It is weird I cannot find a thing which should be used by tons of developers :) [/QUOTE]
Insert quotes…
Verification
Post reply
Top
Bottom
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…