Firstly, thank you for taking the time to read this post and hopefully answer, I'm fairly new to building Mql4 and am struggling with some understanding of how much of my balance gets used to place a trade.
So I've a balance of 4,108.95, I'm trading the US30 and looking to risk 205.45 of my total balance (5%). Ignore the risk management strategies etc here i'm just looking to get the system to risk 205.45 of the account balance but cannot get a formula to work it out exactly.
After each trade my program spits out an excel file so I can see what its doing properly. To calculate the lots used I use the following code:
MyAccountBal = AccountBalance(); double ContractSize = MarketInfo(SymbolIn, MODE_LOTSIZE); ValuetoRisk=MyAccountBal*(Risk/100);
double lots; lots=ValuetoRisk/((TradePrice-StopLossIn)*ContractSize);
The output from my excel File is:
I have no idea why it's risking 171 and not 205.44? The 171 is calculated by simply taking the AccountFreeMargin prior to the trade and then comparing it to the AccountFreeMargin directly after the trade has been place.
If one of you genius coders could point me in the right direction I'd be eternally grateful! I'm looking to trade Forex, Equities and Indicies so I believe the formula is different for each... I just cant get it to work on Indicies at all.
P.s. I will purely be spreadbetting using Ig Index and not buying full shares or options etc.
Thank you in advance.
Thank you for this so much, this is very useful indeed. However I'm still very confused as to how to calculate it with what numbers? I think it's mostly because there is very different terminology used and most of which I don't actually understand what values people are actually talking about?
if we take the US30 and use the trade I have made above as a example so we can use real numbers and I can see exactly where it's coming from, can you point me in the direction of what DeltaPerLot means? I would usually pay the commission via the spread on a spreadbet wouldn't I? So would I have to take into account the actual price of the entity minus the bid price? (if buying)
So Account Balance * percent/100 = RISK is simple.. I get that bit completely. But I cannot get numbers to come back to 171.10...
I do believe it has something to do with exchange rates as I'm in UK and the US30 is traded in its base currency of USD.... but I'm still not working back to 171.10. GBP/USD is about1.4 but the calc between 205.4475 and 171.10 is 1.2 approx.
Again I do realise to an experienced person some of these questions sound very stupid but I'm lost in a lost of terminology I cant seem to get my head around here.... (my background is i'm an accountant and a computer programmer - I've studied the markets for over 9 years but now programming in MQL4 some of the terms have thrown me completely)
NashCo, have you trade on the Demo platform for long enough?
If not! do not trade on the live account with that large balance. It is vital to learn and understand the market.
If you have traded on the demo account before, you were probably going to figure out a risk calculation to be used on your balance.
Well if that account balance is on demo keep practicing, till you are satisfyed with your learning result.
Yes don't worry I have no intention of trading at all live until my system is built and tested over a 3-6 month period of time. Until then i'll be running purely on demo account... thank god for demo accounts!!
No problem, Good luck and all the best.
Thank you Whroeder1, after re-reading this several times it's starting to sink in. I've been chasing my tail a little and trying to calculate a stupid value!!
The risk I was asking is exactly what I was doing but I hadn't really understood it in my head properly.
Thank you all again