Good morning to the PRT community!
Can anyone help me with hard coding the initial capital that is to be allocated to a trading system?
I assume one has to do this if they plan to use a % based profit target or stop loss, other wise a specified % will be based on the total capital. Is this correct?
It would also be interesting to experiment with a trailing % based stop loss, but maybe that is for another topic.
Best regards
J
The percentages of stop loss, take profit and trailing refer to the underlying value, i.e. the index such as DAX, NASDAQ etc.
JSParticipant
Senior
Hi,
Stop loss, take profit and trailing are all calculated from the (average) position price…
Simple example:
Initial capital = 10,000 euros
Risk 1% (of the initial capital) =100 euros
(Index point value=1, number of contracts=1)
SL=100 (1% of initial capital)
Set Stop pLoss SL
Or in percentages:
SL=Risk/PositionPrice*100
Set Stop %Loss SL
If you want to make use of your total equity:
Equity=Capital + StrategyProfit
Risk 1% (of the Equity) = (Capital + StrategyProfit) * 1/100
Etc…
You can’t allocate different slices of your Capital among strategies, as they are unaware of each other.
You need to manage that allocation within your code.
In this example I assume this strategy has an initial Capital allocated of 10K euros (or whatever currency unit it is), no matter if your account has more, and I have set a 10% treshold, so that when my loss reaches that treshold, my strategy is stopped with QUIT:
ONCE myCapital = 10000
ONCE myTreshold = myCapital * 0.9 //Exit when only 10% of my initial Capital is left
IF StrategyProfit <= -myTreshold THEN
QUIT
ENDIF
Sma10 = average[20,0](close)
Xup = close CROSSES OVER Sma10
Xdn = close CROSSES UNDER Sma10
IF Not OnMarket THEN
IF Xup THEN
BUY 1 CONTRACT AT MARKET
ELSIF Xdn THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
SET STOP pLOSS 100
SET TARGET pPROFIT 200
ENDIF
it’s just the first 5 lines that you need to use at the beginning of your code.
As I always say “two is better than none!” 🙂
JSParticipant
Senior
For the sake of clarity:
Roberto, of course, meant 0.1 instead of 0.9
ONCE myThreshold=myCapital*0.1
Before someone is stuck with a DD of 9000 euros 😉
No
JS, I actually meant 0.9, as it will be turned negative in line 3, so after a -9000 losses (thus 1000 left on the account), it will QUIT.