Hi there, I'm new to MQL4 coming from a PHP/mySQL background. My question is probably quite simple, but I'm not quite understanding why it won't work. I'm trying to basically get the account's balance, the price of the current currency being traded, and then calculate the lot size that should be traded based on the Risk variable. Here's the code:
double int Lots = (Risk * NormalizeDouble(AccountBalance() * 50) / (MarketInfo(Symbol(),MODE_BID) * 10000),2));
Sorry, I had typed the code wrong, I actually got it working, but there's an error code 4051 (Invalid function parameter value.) which basically means invalid lot amount when I try to run it. Here is what it's supposed to look like:
Lots = NormalizeDouble(Risk * ((AccountBalance() * 50) / (MarketInfo(Symbol(),MODE_BID) * 10000)),2);
Let's assume, Risk is 3%, AccountBalance is 10000, and the MarketInfo Symbol is EUR/USD with a current BiD of 1.33150.
So first I want to get the useable balance given my account's leverage of 50:1, so 10000 * 50 = 50000.
Then I want to divide this number by the current bid price of the currency chart I'm looking at * 10000 for 1 lot (Oanda). This should be the maximum lot size I can trade based on my account balance.
Next, I want to factor in my Risk % * Value in order to get the actual lot size I should trade based on my Risk %.
Lastly, I want to round the final value to just 2 decimal places.
So in this example it would be:
NormalizeDouble(0.3 * ((10000 * 50) / (1.33150 * 10000)),2);
NormalizeDouble(0.3 * (50000 / 13315),2);
NormalizeDouble(0.3 * 3.75***),2);
END VALUE = 1.13;
Any idea what I'm doing wrong?
Well first of all, a percentage is a number out of 100, so 10% == 10/100 so 3% == 3/100 == 0.03 not 0.3
What is the relevance of leverage ? if you want to risk 10% of your Account Balance and your Account Balance is $1000 then you are risking $100 if you have 50:1 or 500:1 Leverage.
Answer this question, assuming your figures are correct, and you place a Sell order at 1.33150 , what will price have to move up to for you to lose your 3% that you wanted to risk ?
Then that is a calculation with a fixed lotsize
It can also be if I loose 100 pips how big can the lotsize be to risk 3% of my account balance
Please enable the necessary setting in your browser, otherwise you will not be able to log in.