Lot calculation by Vince - page 9

 
Roman.:

When the full Vince lot calculation function is done, I would like to see an example of an EA that, for example, calculates lots every month (or even week) and manages the lots of open trades! :))

And also a variant of work of the Expert Advisor without lot calculation according to Vince, i.e. the permanent lot or lot increase depending on % of the deposit.

The result of this experiment is interesting.

After all, this is what started it all, as I understand! ;)

 
MaxZ:

I was too lazy to paste the code into the EA and check it myself! :)))

I don't have a proper Expert Advisor yet. I have only a few ideas. That's why I took a standard Moving Average without optimizing it and chose a profitable period.

The last code I tried, when I understood that TWR will not reset to "1", was as follows:

No TWR array.

You'll be waiting a long time for an overflow! ;D Although it may not have been there at all...


Thanks, Maxim, I will check it, there's one more thing - the variable D is the maximal loss of a deal in history, therefore this construct will have to be changed

      if (orderIndex == 0 || lastProfit < D)
         D = lastProfit;

i.e. find also its maximal value (the maximal loss on the most loss-making trade within the testing history) in the loop on the history (to avoid troublesome manipulations with external variables) and multiply it by coefficient, say, 1.5, to be ready to make bigger loss during trading, and then consider its value (obtained earlier from the order history loop) in further calculations of TTR

 TWR = 1+f*(-Mas_Outcome_of_transactions[orderIndex]/(D));

D - this is not the past (or the first loss), this is the maximal loss per trade for the entire history under test; then we can do without external variables for calculation of the optimum f in the Expert Advisor to determine the size of lots to be opened later (from the current moment).

 
MaxZ:

When the full Vince lot calculation function is done, I would like to see an example of an EA that, for example, calculates lots every month (or even week) and manages open trades! :))

And also a variant of work of the Expert Advisor without lot calculation according to Vince, i.e. the permanent lot or lot increase depending on % of the deposit.

The result of this experiment is interesting.

After all, this is what started it all, as I understand it! ;)


Yes. There are many variants of MM, for example this one - I wrapped it in a function (volume of positions in %-per-capital depending on the size of the stop-loss. If you are interested, I can post this fiu here.

As soon as everything is done, I will check it, I will post it in a code with some variant of owl (including different variants of MM), we will compare and check it together... :-)))

Examples with test results of one and the same EA with the same settings and with different MM variants, I will give at the end of the week, when I successfully complete calculation of optimum f by R.Vince using geometric mean.

 

Roman.:

Thank you Maxim, I will check, there is one more thing - the D variable is the maximum loss on a trade in history, so this construction will need to be changed

      if (orderIndex == 0 || lastProfit < D)
         D = lastProfit;
i.e. to find its maximal value (maximal loss on the most loss-making trade in the entire history of the test) in the loop (in order not to make any troubles with external variables)

This is how the maximal loss is searched for in this construction. I compare the report and the log. Everything fits.
 
MaxZ:
This is how the maximum loss is sought in this construction. I'm comparing the report and the log. It all fits.

:-))) Right... :-))) my eyes have already been washed out... :-))) It's only Wednesday... work and work and work... :-)))
 

I am showing you the results of testing with different variants of MM, including version 3 by R.Vince's metod for geometric mean - optimal f. You can display the same function of lot calculation in your EA and compare the obtained output balance change values. The task here was not to show the owl operation with MM by optimal f of R.Vince in the best possible way, the aim was to write a f-function correctly calculating the optimal f, and as a consequence, the volume of subsequent orders to be opened. Here are the external variables:

extern string A3 = "Расчет лота по Р.Винсу"; // При количестве сделок на истории от 150 (при наличии репрезентативной выборки)
extern string A4 = "через значение оптимального f"; // метод геометрического среднего 
extern bool optimal_f = true;           // Торговать с расчетом последующих объемов лотов по методу Р.Винса: Да/Нет
extern double Transaction_number = 150; // номер сделки, с которого считаем последующие объемы открываемых позиций через 
                                        // оптимальное f. До этой сделки - минимальный лот.

Here, in this Expert Advisor (in the trailer, on the basis of МА, included in the standard delivery of MT terminal) together with the reports, the following approach to calculation of optimal f is implemented. If the amount of trades in the tester or in the trading account exceeds the amount specified in the Transaction_number variable (the amount of closed positions based on the characteristics (profit/loss) that the volume of subsequent orders being set/opened is considered), we proceed to calculating the lot by R.Vince. I.e. every next order is opened with a new value of f, and consequently, new volume. However, this approach is not quite correct. If you get interested in this method of lot calculation, you should take into consideration the following: I will give an example, this approach of lot calculation is correct but new volumes should be calculated not for each successive trade that is larger than Transaction_number, but as follows (it is just an example where only the approach to calculation of optimal f is significant): we optimize parameters of the EA on H1 from Jan 2008 till Jan 2010 and then calculate the optimal f value and volume of opening positions on the forward section from Then, we repeat this, i.e. January 2008 - June 2010 - calculate the optimal f for this period, which is 30 months, the next period is 15-25% - i.e. up to 7 or 8 months - we trade using the new constant volumes obtained as a result of the new optimal f calculation for this new calculation period (in the calculation period Transaction_number - it should have a numerical value that would correspond to the concept of sample representativeness, i.e. 200 to 500 - already a norm, IMHO) That's it - the cycle is over, we continue using the same approach to volume calculation at 15-25% of the optimization period - during this period of trade volumes are constant in correspondence with the previously calculated optimal value f, they are not recalculated for each next trade.

Variant. Variant №1 - fixed lot - 0,1.

Variation 2 - a percentage of free funds

extern double Lots = 0;
extern string A0 = "Вариант ММ";
extern string A1 = "Процент от своб. ср-тв";
extern string A2 = "с возможностью уменьшения Lots при проигрыше";
extern bool MaximumRisk_DecreaseFactor = true; //считать объем лотов от процента своб ср-тв и также с уменьшающим коэффициентом
                                  //(при его значении больше "0")  при предыщущей убыточной позиции на истории торгового счета
extern double MaximumRisk = 0.02; // процент от своб ср-тв 
extern double DecreaseFactor = 3; // уменьшающий коэфиициент при проигрыше для открытия очередной меньшей предыдущей по объему позиции

Variation№3 - by optimal f:

For a description of the calculations - see chapter "Costs calculation". 31-33 - trailer in archive on 2-nd page - book "Mathematics of capital management".

In this connection, an interesting quote from the book pg. 36:

"

There is a misconception that losses can be completely avoided if you diversify effectively enough. It is true to a certain extent that losses can be mitigated through effective diversification, but they can never be completely avoided. Do not be misled. No matter how good the system applied is, no matter how effectively you diversify, you will still encounter significant losses. The reason for this is not because your market systems are mutually correlated, because there are times when most or all of the portfolio's market systems work against you when you think it shouldn't. Try to find a portfolio with five years of historical data so that all trading systems would work at optimum f and still have a maximum loss of less than 30%! It will not be easy. It doesn't matter how many market systems are used. If you want to do everything mathematically correct, you have to be prepared to lose 30 to 95% of your account balance...:-)) Strict discipline is required, and not everyone can follow it.

As soon as a trader gives up trading a constant number of contracts, he faces the problem of how many to trade. It always happens irrespective of whether the trader admits the problem or not. Trading a constant number of contracts is not a solution, because this way you will never achieve geometric growth. Therefore, whether you like it or not, the question of how many to trade in the next trade will be unavoidable for everyone. Simply choosing a random quantity can lead to serious error. Optimal f is the only mathematically correct solution."

P.S. Spin this f to your experts, look, check, compare results with other MM variants, not forgetting to share interesting reports and conclusions here ...

Files:
 

There is a note on the following code:

lot = NormalizeDouble (( AccountFreeMargin ()/H)*Min_Lot, 1 );

I would change the precision from "1" to "2". After all, you also have Min_Lot = 0.01?

Try the last test now.


There is also one more note on this code. It is not advisable to use all available funds in lot calculation when the percentage of losing trades exceeds the percentage of profitable ones.

Or you need to use a larger lot before the calculation of the lot by Vince begins. Explanations below.


I got the following results (EURUSD currency pair, H1 period, current year, optimization was not carried out, the parameters are yours):

0). Constant lot (Lots = 0.1).

Strategy Test Report
Moving Average_MM
EGlobal-Demo (Build 402)

Symbol EURUSD (Euro vs USD)
Period 1 Hour (H1) 2011.01.03 00:00 - 2011.08.19 22:59 (2011.01.01 - 2011.08.20)
Model By opening prices (only for Expert Advisors with explicit control of bar openings)
Options lots=0.1; A0="MM Variant"; A1="Percentage of free avg"; A2="with the possibility of reducing Lots when losing"; MaximumRisk_DecreaseFactor=false; MaximumRisk=0.02; DecreaseFactor=3; A3="Lot calculation by R.Vince"; A4="through the value of the optimal f"; optimal_f=true; transaction_number=100; A5="Parameters of technical indicators"; MovingPeriod=12; MovingShift=6;

Bars in history 4925 Simulated ticks 8849 Simulation quality n/a
Graph Mismatch Errors 0




Initial deposit 10000.00



Net profit 669.25 Total profit 4458.42 Total loss -3789.17
Profitability 1.18 Expectation of winning 3.80

Absolute Drawdown 157.47 Maximum drawdown 693.81 (6.15%) Relative drawdown 6.15% (693.81)

Total transactions 176 Short positions (% won) 70 (25.71%) Long positions (% won) 106 (34.91%)

Profitable trades (% of all) 55 (31.25%) Losing trades (% of all) 121 (68.75%)
The biggest profitable trade 341.58 losing trade -139.95
Medium profitable trade 81.06 losing trade -31.32
Maximum amount continuous winnings (profit) 3 (153.85) continuous losses (loss) 9 (-252.47)
Maximum continuous profit (number of wins) 341.58 (1) continuous loss (number of losses) -350.42 (6)
Average continuous gain one continuous loss 3

Conclusion:

The result is acceptable: the number of transactions, profitability. I did not optimize the settings.


one). The first attempt to use the Author's code (Transaction_number = 100), we start with a constant lot of 0.01.

Strategy Test Report
Moving Average_MM
EGlobal-Demo (Build 402)

Symbol EURUSD (Euro vs USD)
Period 1 Hour (H1) 2011.01.03 00:00 - 2011.08.19 22:59 (2011.01.01 - 2011.08.20)
Model By opening prices (only for Expert Advisors with explicit control of bar openings)
Options lots=0; A0="MM Variant"; A1="Percentage of free avg"; A2="with the possibility of reducing Lots when losing"; MaximumRisk_DecreaseFactor=false; MaximumRisk=0.02; DecreaseFactor=3; A3="Lot calculation by R.Vince"; A4="through the value of the optimal f"; optimal_f=true; transaction_number=100; A5="Parameters of technical indicators"; MovingPeriod=12; MovingShift=6;

Bars in history 4925 Simulated ticks 8849 Simulation quality n/a
Graph Mismatch Errors 0




Initial deposit 10000.00



Net profit -458.67 Total profit 445.84 Total loss -904.52
Profitability 0.49 Expectation of winning -2.61

Absolute Drawdown 476.69 Maximum drawdown 787.28 (7.64%) Relative drawdown 7.64% (787.28)

Total transactions 176 Short positions (% won) 70 (25.71%) Long positions (% won) 106 (34.91%)

Profitable trades (% of all) 55 (31.25%) Losing trades (% of all) 121 (68.75%)
The biggest profitable trade 34.16 losing trade -528.00
Medium profitable trade 8.11 losing trade -7.48
Maximum amount continuous winnings (profit) 3 (15.39) continuous losses (loss) 9 (-25.25)
Maximum continuous profit (number of wins) 34.16(1) continuous loss (number of losses) -546.34 (6)
Average continuous gain one continuous loss 3


Conclusions :

Until the EA has made 100 trades: the losses are small, the maximum loss is also not large (D). Hence H is small:

H=D/(-f);

And the calculated lot for Vince will be huge:

lot = NormalizeDouble (( AccountFreeMargin ()/H)*Min_Lot, 1 );

since We use all free funds, which are many times greater than the parameter H.

As I wrote earlier, the percentage of losing trades is higher than profitable trades, the probability of getting a loss is higher, which happened in the test.

At the next calculation of the optimal f, the parameter D becomes several times higher than the previous one, and that's it, you've arrived... Positions are opened with a volume of 0.01 lots.


2). The second attempt to use the Author's code (Transaction_number = 100), we start with a constant lot of 0.1 (added the Initial_Lots input parameter).

Changes in the code to the following line:

}     // Выход из  if (Transaction_number<Qnt)
else {
   lot=Initial_Lots; // Min_Lot;
   Print ( "Закрытых позиций = " ,   Qnt, " Transaction_number = " , Transaction_number);
   return (lot);
}
Strategy Test Report
Moving Average_MM
EGlobal-Demo (Build 402)

Symbol EURUSD (Euro vs USD)
Period 1 Hour (H1) 2011.01.03 00:00 - 2011.08.19 22:59 (2011.01.01 - 2011.08.20)
Model By opening prices (only for Expert Advisors with explicit control of bar openings)
Options lots=0; A0="MM Variant"; A1="Percentage of free avg"; A2="with the possibility of reducing Lots when losing"; MaximumRisk_DecreaseFactor=false; MaximumRisk=0.02; DecreaseFactor=3; A3="Lot calculation by R.Vince"; A4="through the value of the optimal f"; optimal_f=true; transaction_number=100; Initial_Lots=0.1; A5="Parameters of technical indicators"; MovingPeriod=12; MovingShift=6;

Bars in history 4925 Simulated ticks 8849 Simulation quality n/a
Graph Mismatch Errors 0




Initial deposit 10000.00



Net profit 578.78 Total profit 4703.48 Total loss -4124.69
Profitability 1.14 Expectation of winning 3.29

Absolute Drawdown 157.47 Maximum drawdown 768.81 (6.82%) Relative drawdown 6.82% (768.81)

Total transactions 176 Short positions (% won) 70 (25.71%) Long positions (% won) 106 (34.91%)

Profitable trades (% of all) 55 (31.25%) Losing trades (% of all) 121 (68.75%)
The biggest profitable trade 474.11 losing trade -154.00
Medium profitable trade 85.52 losing trade -34.09
Maximum amount continuous winnings (profit) 3 (153.85) continuous losses (loss) 9 (-327.47)
Maximum continuous profit (number of wins) 490.11(2) continuous loss (number of losses) -504.89 (6)
Average continuous gain one continuous loss 3


Conclusion :

The chart has become more interesting, but still the profitability is worse...


I was outraged by the sharp jumps in the volume of the position and I got into the code.

3). The third attempt to use the Author's code (Transaction_number = 100), starting with a constant lot of 0.1, corrected the accuracy in the lot calculation.

Changes in the code to the following line:

lot = NormalizeDouble (( AccountFreeMargin ()/H)*Min_Lot, 2 );
Strategy Test Report
Moving Average_MM
EGlobal-Demo (Build 402)

Symbol EURUSD (Euro vs USD)
Period 1 Hour (H1) 2011.01.03 00:00 - 2011.08.19 22:59 (2011.01.01 - 2011.08.20)
Model By opening prices (only for Expert Advisors with explicit control of bar openings)
Options lots=0; A0="MM Variant"; A1="Percentage of free avg"; A2="with the possibility of reducing Lots when losing"; MaximumRisk_DecreaseFactor=false; MaximumRisk=0.02; DecreaseFactor=3; A3="Lot calculation by R.Vince"; A4="through the value of the optimal f"; optimal_f=true; transaction_number=100; Initial_Lots=0.1; A5="Parameters of technical indicators"; MovingPeriod=12; MovingShift=6; k=1;

Bars in history 4925 Simulated ticks 8849 Simulation quality n/a
Graph Mismatch Errors 0




Initial deposit 10000.00



Net profit 386.40 Total profit 4349.80 Total loss -3963.40
Profitability 1.10 Expectation of winning 2.20

Absolute Drawdown 157.47 Maximum drawdown 714.98 (6.46%) Relative drawdown 6.46% (714.98)

Total transactions 176 Short positions (% won) 70 (25.71%) Long positions (% won) 106 (34.91%)

Profitable trades (% of all) 55 (31.25%) Losing trades (% of all) 121 (68.75%)
The biggest profitable trade 379.29 losing trade -169.40
Medium profitable trade 79.09 losing trade -32.76
Maximum amount continuous winnings (profit) 3 (153.85) continuous losses (loss) 9 (-285.97)
Maximum continuous profit (number of wins) 397.69 (2) continuous loss (number of losses) -530.19 (6)
Average continuous gain one continuous loss 3


Conclusion :

The lot began to get out more smoothly, but again, due to the prevailing number of losing trades, the profitability of the adviser decreased.


4). The fourth attempt to use the Author's code (Transaction_number = 100), starting with a constant lot of 0.1, using only a part of the free margin (50%) to calculate the lot according to Vince (added the FreeMarginRisk input parameter):

Changes in the code to the following line:

lot = NormalizeDouble ((FreeMarginRisk* AccountFreeMargin ()/H)*Min_Lot, 2 );
Strategy Test Report
Moving Average_MM
EGlobal-Demo (Build 402)

Symbol EURUSD (Euro vs USD)
Period 1 Hour (H1) 2011.01.03 00:00 - 2011.08.19 22:59 (2011.01.01 - 2011.08.20)
Model By opening prices (only for Expert Advisors with explicit control of bar openings)
Options lots=0; A0="MM Variant"; A1="Percentage of free avg"; A2="with the possibility of reducing Lots when losing"; MaximumRisk_DecreaseFactor=false; MaximumRisk=0.02; DecreaseFactor=3; A3="Lot calculation by R.Vince"; A4="through the value of the optimal f"; optimal_f=true; transaction_number=100; FreeMarginRisk=0.5; Initial_Lots=0.1; A5="Parameters of technical indicators"; MovingPeriod=12; MovingShift=6;

Bars in history 4925 Simulated ticks 8849 Simulation quality n/a
Graph Mismatch Errors 0




Initial deposit 10000.00



Net profit 553.66 Total profit 3960.94 Total loss -3407.28
Profitability 1.16 Expectation of winning 3.15

Absolute Drawdown 157.47 Maximum drawdown 528.66 (4.80%) Relative drawdown 4.80% (528.66)

Total transactions 176 Short positions (% won) 70 (25.71%) Long positions (% won) 106 (34.91%)

Profitable trades (% of all) 55 (31.25%) Losing trades (% of all) 121 (68.75%)
The biggest profitable trade 296.80 losing trade -125.95
Medium profitable trade 72.02 losing trade -28.16
Maximum amount continuous winnings (profit) 3 (153.85) continuous losses (loss) 9 (-222.33)
Maximum continuous profit (number of wins) 330.76 (2) continuous loss (number of losses) -343.22 (6)
Average continuous gain one continuous loss 3


Conclusions :

First, take a look at the maximum drawdown and profitability . Much better than the first try.

The following patterns are also visible on the balance and volume chart:

- when profitable areas are observed, the lot grows;

- but as soon as there is a series of losses (parameter D sharply increases) and the calculated lot sharply decreases accordingly;

- then the profitable sections of the lot are restored, but again, due to the low percentage of profitable trades, this phenomenon is not long.

There is a certain geometric averaging or something! :)))

I'm attaching the latest code...


Conclusion :

How to correctly calculate the lot according to Vince from the resulting formula:

lot = NormalizeDouble ((FreeMarginRisk* AccountFreeMargin ()/H)*Min_Lot, 2 );

I don't know... That is, what parameters should be taken.

Or maybe someone will refute the result.


But I know for sure that you need to somehow deal with the maximum loss (parameter D), so that it does not grow in proportion to the lot (maybe somehow limit the deal with StopLoss)...

But first of all, it is necessary to increase the ratio of profitable and unprofitable trades. The Expert Advisor itself is very simple and I did not expect super-profitable results.

In general, I think that this method of calculating the lot according to Vince has the right to life. But in order to fully master it, additional research will be required, for which I am not ready at the moment. There is no ready-made trading system as such...

I am now on the path of wandering between wave theory, technical analysis, candlestick, Price Action methods, pipsomania, and even sometimes I look at Lavinshchik and Martinshchik! :DD

 
MaxZ:

There is a comment on the following code:

1. I would change the accuracy from "1" to "2". After all, you also have Min_Lot = 0.01?

Try the last test now.


2 There is also one more comment about this code. It is not advisable to use all available funds in the lot calculation when the percentage of losing trades exceeds the percentage of profitable ones.

Or you should use a larger lot before you start calculation of lots by Vince. Explanation below.

...

First, take a look at the maximum drawdown and profitability. Noticeably better than the first attempt.

Also on the balance and volume chart you can see the following patterns:

- when there are profitable areas, the lot grows;

- but as soon as we have a series of losses (parameter D sharply increases) and the calculated lot is sharply decreased;

- Then the lot is restored in profitable areas, but again, due to low percentage of profitable trades, this phenomenon doesn't last long.

Some kind of geometric averaging takes place, or something! :)))

I'm attaching the code for the latest version...


3. Conclusion:

...

But first of all, the ratio of profitable and losing trades should be increased. The Expert Advisor itself is very simple and I didn't expect super profitable results.

In general, I think this method of calculation of lots by Vince has the right to life.

4. There is no ready-made trading system as such...


Thank you Max for interesting and detailed comments and review on this subject.

Regarding answers see points (questions) above...

1. " Do you also have Min_Lot = 0.01?" - no. Min_Lot = 0.1 is a demo classic account, Step parameter = same, so accuracy to one decimal place.

0.01 is micro.

2. absolutely correct.

3. Of course, it already depends directly on the vehicle in operation... :-))) Of course, it has a right to life.

4. The TC is there. Description - from here + next page, from here to the end of the branch..., "basket currency index..." branch - from here, base here (including contents of "Sources" at the end of the article), video here.

Who is interested in the choice of MM variant can connect this variant to his TS and see the results, not forgetting to share interesting points in this branch of the forum.

 
Roman.:

Vary #3 - by the optimum f:

In this picture the calculated lot is just jumping around terribly... That's why I thought that I was trading 0.01 lot first, and then a multiple of 0.1. My mistake! :))

 
MaxZ:
In this picture the calculated lot just jumps terribly... That's why I thought the first is trading with 0.01 lot, and then a multiple of 0.1. My mistake! :))


I see, R.Vince does not write for nothing:

"

Try to find a portfolio with five years of historical data so that all trading systems would work at optimum f and still have a maximum loss of less than 30%! It's not going to be easy. It doesn't matter how many market systems are used. If you want to do everything mathematically correct, you have to be prepared to lose 30 to 95% of your account balance. Strict discipline is required and not everyone can follow it.

As soon as a trader gives up trading a constant number of contracts, he is faced with the problem of how many to trade. It always happens irrespective of whether the trader admits the problem or not. Trading a constant number of contracts is not a solution, because this way you will never achieve geometric growth. Therefore, whether you like it or not, the question of how many to trade in the next trade will be unavoidable for everyone. Simply choosing a random quantity can lead to serious error. Optimal f is the only mathematically correct solution."

:-)))

Maybe some kind of ironer to go with it... I don't know, I didn't bother with this question much, the task was to display everything strictly according to the original source... We did it... Hooray! :-)))

I had the idea of multiplying D by some factor, e.g. 1.5 - something like a buffer (tolerance)... But that won't solve the problem you mentioned: "but as soon as a series of losses occurs (the D parameter increases sharply) and the calculated lot is sharply reduced..." - the D parameter increases not because of a series, but because of the maximal loss of a certain trade, probably the smoothing is not necessary here, you just have to use stops... :-))) Owl is without stops... :-))) That's why these situations arise...

In any case, I think it is necessary to look more closely at this variant of MM with real owls!

Reason: