Hi everyone,
I’m trying to adjust my strategy so that it trades a percentage of my account equity instead of using a fixed number of contracts.
Ideally, I’d like the strategy to automatically calculate position size based on my current equity — for example, allocate 2% of the account equity per trade. That way, the position size scales up as the account grows, and decreases after losses.
Has anyone implemented this before in ProBuilder code?
I’d really appreciate an example or some guidance on how to calculate and set the position size dynamically.
Thanks a lot in advance!
/Osca
Hi Osca,
It is not possible to obtain your portfolio amount by means of ProBuilder.
It *is* of course possible to enter that amount yourself as a parameter to the program code. But you would need change the parameter in/to the code and restart that strategy code in ProOrder to let the latest value come through.
In other words : what you functionally want is not possible.
What
PeterSt said is correct.
But, since when you start a strategy you for sure KNOW how much of your balance is assigned to that strategy, simply code that value in your code and add to it the STRATEGYPROFIT, then you have to calculate thge risk for the trade and divide the result by the price to determine the number of contracts:
ONCE myCapital = 20000
ONCE myRisk = 2 //2%
myEquity = myCapital + StrategyProfit
tempRisk = myEquity * myRisk / 100
LotSize = tempRisk * 100 / close
myLongConditions = Not OnMarket AND close CROSSES OVER average[20,0](close)
myShortConditions = Not OnMarket AND close CROSSES UNDER average[20,0](close)
IF myLongConditions THEN
BUY LotSize Contracts at Market
ELSIF myLongConditions THEN
BUY LotSize Contracts at Market
ENDIF
SET STOP %LOSS 0.5 //0.5%
SET TARGET %PROFIT 1 //1%
graph myEquity
graph tempRisk