Everyone sooner or later everyone get in touch with the “holy grail” of trading, the compound interest.
Far from a philosophical discussion, I would like to share and discuss available codes in PRT to develope it in automatic trading.
At the moment I only know this:
n= 1+(ROUND((strategyprofit)/2500)) //every 2500 add a contract
//where
buy n contracts at market
Is it possible to make a percentage version? When equity reaches 3% profit it adds n contracts? Do you know other alternatives?
First you have to set up your initial equity and number of lots, later, when NOT OnMarket check if strategyprofit is > 3% of your equity and act accordingly:
ONCE MyEquity = 10000
ONCE nLots = 1
IF Not OnMarket THEN
IF Strategyprofit >= (MyEquiti * 1.03) THEN
MyEquity = Strategyprofit
nLots = nLots + 1
ENDIF
ENDIF
You must be aware that after increasing 3%, your equity could fall by 5% and you might want to decrease the number of lots you are trading.
There you go
ONCE MyEquity = 10000
ONCE nLots = 1
IF Not OnMarket THEN
IF Strategyprofit >= (MyEquity * 1.03) THEN
MyEquity = Strategyprofit
nLots = nLots + 1
ELSIF Strategyprofit <= (MyEquity * 0.97) THEN
MyEquity = Strategyprofit
nLots = nLots - 1
nLots = max(1, nLots) //do not allow nLots to fall below 1
ENDIF
ENDIF
LeoParticipant
Veteran
I use this
// RISK CONTROL IF THINGS ARE GOING WONDERFULL
n = 1 + (strategyprofit / (17*pipvalue))
n=SQRT(n)
n = round(n * 100)
n = n / 100
n = max(1,n)
When the code wins 17*4=68 pips then it duplicate the size of lot.
Above added to
Snippet Link Library.
I can’t see where the *4 comes from, but maybe I need to think about it more do I? 🙂
I tried to figure out what 4 stands for, as well, since I’m not a fan of maths.
I guess it has to do with the square root. If you are trading 4 contracts and want to double that number, if you take the square root if, which is two, then you’ll have to multiply it by 4 to get the correct number. Maybe GRAPH (or Leo) could help!
LeoParticipant
Veteran
Hi all,
welll actually is not a 4, haha sorry.
Look, the code is based in the strategy profit. Therefore I do not want something linear because when it wins the next trade is quite high. Which I choose and works well is the root fuction. Normally a trade quite small amount and very short period of times.
Lets say, in this example (with strategyprift/17), when the code wins 17 pips then the next trade is 1+17/7=2 then root of 2 is 1.41… the next trade opens 1.41 lots
next trade win another 17 pips, then 1+34/17=3, root of 3 equal 1.73. Next trade will open with 1.73 lots
next trade win another 17 pips, it means that the strategy profit is 3 times 17 so, 1+51/17=4, root of 4 is 2 then
when the strategy is 3 times the 17 then it opens 2 lots.
in summary if the initial n=1 and you want to duplicate the number of lot after certain number of pips winning, then take the number of pips you desire divided by 3 and remplace the 17 in the code. For example. My initial lot is 1, after 100 winning pips I want to duplicate the number of lot by 2 then, the fist line of the code will be
N=1+(strategyprofit/(33*pipvalue))
hope I clarify the code.