Thanks, @nonetheless so helpful, as the other position managements are based on position size which would not necessarily work unless the underlying value of the contract remained the same. It would only work at that one time, eg. if index 20,000 vs 10,ooo, the value of that one contract is very different.
However i have one question, on line 16 why have you multiplied factor by margin? :
positionsize = startpositionsize + Strategyprofit/(factor*margin)
If factor is say 20, and leverage is 1/20, then would that not just make the denominator = the entire value of the underlying product then (without any leverage)? So if say the starting position of 1 contract that is a margin cost is $700 for 1 DAX contract currently, at a 20:1 leverage available, and a factor of 20 (as increases by 5%), and you have 100% profit = $700. Then your calculator is:
positionsize = 1 + 700/(20)x(14000*.05)
positionsize = 1.05
Instead of the positionsize = 2, which it should be.
Would this not work better?
IF Not OnMarket THEN
positionsize = startpositionsize + Strategyprofit/(margin)
ENDIF
roundedpositionsize = ROUND(positionsize, 1) // need to round to one decimal place if IG, or whole numbers only depending on contracts minimums.
IF BUYCONDITIONS THEN
BUY roundedpositionsize CONTRACT AT MARKET
Also i added in ROUND(a, digits), as depending on the contract, IG would only accept position sizes to one decimal place, or a whole number; so need round it to the nearest. Otherwise might not be able place the trade.