This ProBuilder script is designed to dynamically adjust trading position sizes based on the margin cost and accumulated strategy profits. It is particularly set up for trading the DOW index, considering different margin tiers as provided by a broker like IG. The script includes parameters to control the reinvestment of profits into new positions, which helps in managing risk and capital utilization effectively.
//Money Management DOW
MM = 1 // = 0 for optimization
if MM = 0 then
positionsize=1
ENDIF
if MM = 1 then
ONCE startpositionsize = .4
ONCE factor = f // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
ONCE factor2 = 20 // tier 2 factor
ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE tier1 = 55 // DOW €1 IG first tier margin limit
ONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limit
ONCE minpositionsize = .2 // enter minimum position allowed
IF Not OnMarket THEN
positionsize = startpositionsize + Strategyprofit/(factor*margin)
ENDIF
IF Not OnMarket THEN
IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 //incorporating tier 2 margin
ENDIF
IF startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
positionsize = minpositionsize //keeps positionsize from going below allowed minimum
ENDIF
IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 > maxpositionsize then
positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
ENDIF
ENDIF
ENDIF
The code snippet above manages the position size for trading based on the profit generated by the strategy and the margin requirements for different tiers. Here’s a breakdown of its functionality:
ONCE keyword, ensuring they are assigned only once.This approach helps in optimizing the capital usage based on performance and market conditions, making it a practical tool for managing investments dynamically.
Check out this related content for more information:
https://www.prorealcode.com/topic/reinvesting-full-value-of-portfolio-after-each-trade/#post-122308
Visit Link