# Smart Risk Limitation of Martingale by Logistic Growth

• updated
• Completed

One of the main issues with the martingale is its inherent exponential growth. After only a few Iterations, the lot size explodes and with it the risk.

This is bad but must of the time the profits are generated in the first few iterations when the exponential growth leads to a fast exit again.

So, how to have the best of both worlds?

The answer is a function which has at first an exponential growth (like Martingale) but then transitions to a constant lot size (like grid).

Such a function exists and is well-known in nature for limited growth, the logistic function:

Naturally, L is our maxLot and k is related to the Martingale coefficient alpha by

k = ln alpha

Further, we need to define a minLot (starting Lot) and x0. x0 is just the point from which the growth will transition strongly to a constant value.

Here is an example of Martingale coefficient alpha = 1.52 compared to the logistic growth capped at a maxLot of 1.0, x0 = 11, minLot = 0.01:

It is clearly visible how the Martingale (red line) explodes at low Iterations / cycles and with it the trade risk. The logistic function shows a linear risk increase, since the lot is constant.

I think that the logistic function gives us much more possibilities to survice strongly trending markets in which the initial trade has been in the wrong direction.

In python, the implementation of the logistic function looks as follows:

`def logistic(minLot, maxLot, x0, x):    k = 1/x0*numpy.log(maxLot/minLot -1)    return maxLot/(1+numpy.exp(-k*(x-x0)))`

numpy.log is the natural logarithm, in C it is

`double log(double x);`

Note that only x0 is a parameter that needs to be implemented in addition. minLot and maxLot are already implemented in CP, k is automatically calculated.

It would be great to have this mathematical approach implemented.

Replies 13
1
Andrey Khatimlianskyi
• Completed

Robert, sorry for a such long delay with reply...

I've finally added this mode to the EA (will be available in v2.30).
x0 is defined by "Lot coefficient / adding / x0" parameter (never mind that it is real number, just use an integer to define x0).
Max lot must be specified for this mode, of course. And now I understand why did you ask for "Max lot per 1000 USD".

1
RickMos

Nice idea to backtest! thanks Robert for the idea, and many thanks Andrey for implementing it!!!

0
Quote from Andrey Khatimlianskyi

Robert, sorry for a such long delay with reply...

I've finally added this mode to the EA (will be available in v2.30).
x0 is defined by "Lot coefficient / adding / x0" parameter (never mind that it is real number, just use an integer to define x0).
Max lot must be specified for this mode, of course. And now I understand why did you ask for "Max lot per 1000 USD".

Andrey, could you tell me in English? :)

I'm trying to understand basic of this lot increasing mode

What i understand is:

Open 0.26 lot for 1st trade with maximum 1 lot. But in order to suppress the lot exponential, then comes x0 as factor for it

Then what I still confuse are:

1. What next lot would open on 2nd trades and others and based on what

2. With x0 = 7 and x0 = 15 I just see main difference is only 0.5 lot open on trade #7 and trade #15. Lot sizing of course difference, hence that's my 1st question above

3. At what level that 1 lot would be open?

Well, the point is I try to do some paper calculation for understanding it first before tweaking that parameters, but it seems I'm not good enough to do that calculation :D

0
Andrey Khatimlianskyi

Andrey, could you tell me in English? :)

I'm trying to understand basic of this lot increasing mode

What i understand is:

Open 0.26 lot for 1st trade with maximum 1 lot. But in order to suppress the lot exponential, then comes x0 as factor for it

Then what I still confuse are:

1. What next lot would open on 2nd trades and others and based on what

2. With x0 = 7 and x0 = 15 I just see main difference is only 0.5 lot open on trade #7 and trade #15. Lot sizing of course difference, hence that's my 1st question above

3. At what level that 1 lot would be open?

Well, the point is I try to do some paper calculation for understanding it first before tweaking that parameters, but it seems I'm not good enough to do that calculation :D

Did you read the initial message? )

Look at the chart. Lot in the series will change as blue line.

Lot will change between Start lot and Max lot, with average at order # x0.

0
RickMos
Quote from Andrey Khatimlianskyi

Did you read the initial message? )

Look at the chart. Lot in the series will change as blue line.

Lot will change between Start lot and Max lot, with average at order # x0.

Hi Andrey, the average you are refering #x0 is maxlot/2?  not (maxlot-minlot)/2? first is half the max lot.

1
Andrey Khatimlianskyi
Quote from RickMos

Hi Andrey, the average you are refering #x0 is maxlot/2?  not (maxlot-minlot)/2? first is half the max lot.

Seems you're right. I just applied formula from article from the 1st post.

2
RickMos

Im running live this feature,  looks promising, below are 2 pics, one for individual lots grow, in this case maxlots=4 , x0=16 (results in an alfa=1.39), orange curve has a martigale alfa=1.3, green alfa=1.25

The other pic is for total lots placed as iteration number grows.

Im using a tight step in eurusd (2.3 atr based in m1 12periods),  deliberately put alfa=1.39 to account for currency pullbacks on 20 pips or so, to make the most out. I have a telegram ea to signaling in some number of orders openings, (12), and based on currency power and retail volume, i stop the grid (or let it go), trying not to blow the account!

2
RickMos

Here is the setfile im running, only thing i wasnt sure was min step size that actually is 2.1 points(or pips), take a look at the spread, my setting is at 1.3pips (1.1 to 1.2 typical on my shitty fbs cent account)

2021.04.28.cp.mt4.5050.ATR.logistic.eurusd.....set

0
Andrey Khatimlianskyi
Quote from RickMos

Here is the setfile im running, only thing i wasnt sure was min step size that actually is 2.1 points(or pips), take a look at the spread, my setting is at 1.3pips (1.1 to 1.2 typical on my shitty fbs cent account)

2021.04.28.cp.mt4.5050.ATR.logistic.eurusd.....set

Thank you, Rick!

0
Quote from Andrey Khatimlianskyi

Did you read the initial message? )

Look at the chart. Lot in the series will change as blue line.

Lot will change between Start lot and Max lot, with average at order # x0.

I did and saw the chart

What I understand is:

start lot 0.1 with multiplier 1.2 and start averaging at order #8 with 0.05 and max lot 2, so would like this:

So for my understanding, need to determine lot multiplier and lot for averaging

For example above, I know that multiplier is 1.2 and averaging 0.05

But for your pics, I'm still trying to know, in order to use it properly and without blindly )

﻿