| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Help with MQL4 Equation https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1422 |
Page 1 of 2 |
| Author: | remix919 [ Thu Jan 24, 2013 3:09 pm ] |
| Post subject: | Help with MQL4 Equation |
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. There's an error code 4051 (Invalid function parameter value.) which basically means invalid lot amount when I try to run it. Here's the code: Code: Select all 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: Code: Select all |
|
| Author: | phil_trade [ Thu Jan 24, 2013 3:17 pm ] |
| Post subject: | Re: Help with MQL4 Equation |
Code: Select all No problem at home with this code. It should be another line returning your error code |
|
| Author: | fxdaytrader [ Thu Jan 24, 2013 3:22 pm ] |
| Post subject: | Re: Help with MQL4 Equation |
by the way: NormalizeDouble is the wrong way to round the lotsize. You have to use lotstep Further instead of using the balance you should use the free margin if you like have a look to the script here: http://www.stevehopwoodforex.com/phpBB3 ... =23&t=1332 |
|
| Author: | remix919 [ Thu Jan 24, 2013 3:31 pm ] |
| Post subject: | Re: Help with MQL4 Equation |
I'm using this code with the strategy tester, could it be a problem with the strategy tester? Here's the exact errors I'm getting from the journal: Code: Select all |
|
| Author: | phil_trade [ Thu Jan 24, 2013 3:36 pm ] |
| Post subject: | Re: Help with MQL4 Equation |
May be the result is under MinLot authorized for this pairs with this broker. try manually to trade this lot to check |
|
| Author: | remix919 [ Thu Jan 24, 2013 3:37 pm ] |
| Post subject: | Re: Help with MQL4 Equation |
Thanks for the tips and I've downloaded and am looking over your buy script, but it's quite a handful for a beginner in MQL4 |
|
| Author: | remix919 [ Thu Jan 24, 2013 3:38 pm ] |
| Post subject: | Re: Help with MQL4 Equation |
I use Oanda and they allow pretty much any lot size. |
|
| Author: | remix919 [ Thu Jan 24, 2013 9:56 pm ] |
| Post subject: | Re: Help with MQL4 Equation |
Just noticed something interesting, why is it that the following works: Code: Select all Code: Select all |
|
| Author: | remix919 [ Fri Jan 25, 2013 2:43 am ] |
| Post subject: | Re: Help with MQL4 Equation |
Problem solved, I had to put the code after the initialization, not before :\ |
|
| Author: | icon [ Mon Feb 04, 2013 6:43 am ] |
| Post subject: | Re: Help with MQL4 Equation |
I saw some functions with & in the input what does that mean ? for example void DoSOmething( double& a[]) What is the job of the & before the a ? I saw some examples on FF http://www.forexfactory.com/showthread.php?t=374836 and some others in Empty4 codebase and I am curious what they use the & for ? |
|
| All times are UTC | Page 1 of 2 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|