paulan,
Below is the code for a fixed fractional money management model. The number returned
in the case of forex is whole lots so you would divide by the lot size to get to
whole lots i.e. 25 = 2.5 whole lots trading a 10,000 mini.
This formula requires 1 times delta cummulative profit from each position before
moving your trading size up by 1. I use a delta of twice my largest expected drawdown
which means that if I have 3 positions the strategy has to produce profts of 3
times the delta before trading 4 positions. This guarantees that your largest drawdown
will move you at most 2 levels back in position size.
I translated code from one of my production systems written in C to MQL4 so it
was easiest to do that as a script. In the long run you can make this a function
and add it to an expert advisor with the variables as inputs. I hope this helps.
Scott
int start()
{
double initialBalance = 0;
double currentBalance = 0;
double delta = 0;
double minimumBalance = 0;
double positions = 0;
double increase;
double d;
d = 8 * (increase / delta);
if (currentBalance >= minimumBalance)
{
// You don't calculate positions until your current account balance is greater
than the initial account balance
if (d >= 0)
positions = MathCeil((-1 + MathSqrt(d + 1)) / 2);
else
positions = 1;
if (positions == 0)
positions = 1;
}
else
positions = 0;
Alert("positions: ", positions);
return(positions);
}
paulan,
Below is the code for a fixed fractional money management model. The number returned
in the case of forex is whole lots so you would divide by the lot size to get to
whole lots i.e. 25 = 2.5 whole lots trading a 10,000 mini.
This formula requires 1 times delta cummulative profit from each position before
moving your trading size up by 1. I use a delta of twice my largest expected drawdown
which means that if I have 3 positions the strategy has to produce profts of 3
times the delta before trading 4 positions. This guarantees that your largest drawdown
will move you at most 2 levels back in position size.
I translated code from one of my production systems written in C to MQL4 so it
was easiest to do that as a script. In the long run you can make this a function
and add it to an expert advisor with the variables as inputs. I hope this helps.
Scott
int start()
{
double initialBalance = 0;
double currentBalance = 0;
double delta = 0;
double minimumBalance = 0;
double positions = 0;
double increase;
double d;
d = 8 * (increase / delta);
if (currentBalance >= minimumBalance)
{
// You don't calculate positions until your current account balance is greater
than the initial account balance
if (d >= 0)
positions = MathCeil((-1 + MathSqrt(d + 1)) / 2);
else
positions = 1;
if (positions == 0)
positions = 1;
}
else
positions = 0;
Alert("positions: ", positions);
return(positions);
}
I'm sorry, but I don't know what to do now...
I don't think you know what I want,
I want something like: Every 30 (or whatever) trades the EA calculates what's 0. 001% of the account balance and uses that number as amount of lots for the next 30 trades...
I am not familiar with programming..
thank you for your effort,
Paulan
PS: I won't have more than 1 position.
Hello Scott,
I'm sorry, but I don't know what to do now...
I don't think you know what I want,
I want something like: Every 30 (or whatever) trades the EA calculates what's 0. 001% of the account balance and uses that number as amount of lots for the next 30 trades...
I am not familiar with programming..
thank you for your effort,
Paulan
PS: I won't have more than 1 position.
Paulan,
The code I posted is meant to calculate a position based on a fixed fractional money management model. You would run it as a script with the parameters:
initialBalance = the starting balance of when you turned the system on for the first time
currentBalance = the balance prior to entering this position
delta = how much money each position has to make prior to taking a larger position
minimumBalance = how much margin does it take to have even one position (one full 100,000 lot would take $1,000 usd to have a full position)
You run the code as a script (attach to chart) and the alert statement would pop up telling you the answer to the number of positions.
I am sorry that I wasn't more clear in my earlier post.
Scott
Paulan,
The code I posted is meant to calculate a position based on a fixed fractional money management model. You would run it as a script with the parameters:
initialBalance = the starting balance of when you turned the system on for the first time
currentBalance = the balance prior to entering this position
delta = how much money each position has to make prior to taking a larger position
minimumBalance = how much margin does it take to have even one position (one full 100,000 lot would take $1,000 usd to have a full position)
You run the code as a script (attach to chart) and the alert statement would pop up telling you the answer to the number of positions.
I am sorry that I wasn't more clear in my earlier post.
Scott
I don't think I can use your code to test when it's the best time to compound, can I? (well, maybe, but not faster than without it)
thank you for your explanation though,
Paulan
I don't think I can use your code to test when it's the best time to compound, can I? (well, maybe, but not faster than without it)
thank you for your explanation though,
Paulan
Paulan,
With this formula, reaching the delta value (profit value) per position will result in the number of positions going up. What you may be asking is how to best set the delta value. It is normally set at some ratio of your largest expected drawdown.
If my system has a maximum expected drawdown of 200 pips, I would set the delta at 300 pips. So for the EURUSD trading every time the system made 300 pips PER EXISTING POSITION, therefore if trading 3 positions the system would have to produce 900 pips before adding another position.
It is very important to realize that the profit is per position, not per trade. This will mathematically guarantee that your largest loss will result in only moving back 1-2 levels in your position size. The mistake that is often made is overleaveraging to the point where a large loss leaves you unable to trade anywhere near the same number of positions as before the loss. This puts you in the situation of taking much longer to regain the amount you lost because you are now trading a lot smaller number of positions.
Hope this helps
Scott
Paulan,
With this formula, reaching the delta value (profit value) per position will result in the number of positions going up. What you may be asking is how to best set the delta value. It is normally set at some ratio of your largest expected drawdown.
If my system has a maximum expected drawdown of 200 pips, I would set the delta at 300 pips. So for the EURUSD trading every time the system made 300 pips PER EXISTING POSITION, therefore if trading 3 positions the system would have to produce 900 pips before adding another position.
It is very important to realize that the profit is per position, not per trade. This will mathematically guarantee that your largest loss will result in only moving back 1-2 levels in your position size. The mistake that is often made is overleaveraging to the point where a large loss leaves you unable to trade anywhere near the same number of positions as before the loss. This puts you in the situation of taking much longer to regain the amount you lost because you are now trading a lot smaller number of positions.
Hope this helps
Scott
I may be doing that but I first want to test how good my system works with what I explained earlier...
I know how the (your) script works, and maybe that is better. I have a system that wins aproximately 50% but the wins are 1.3 times as good

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Does someone knows the code/script for compounding?
I'd like to test when it's the best time to compound (per how many trades or days).
Manually testing it is going to cost a lot of time I think (when you consider that I have some experts which make around a thousand trades per year)..
And I thought the code shouldn't be too difficult...
Thanks in advance,
Paulan van Nes
PS: Sorry for my English