[PYTHON] I have problem determining stop loss and take profit if i am not using all my capital
Hello, this is my first post, my following function behaves as expected if i let it determine my position size, but when i choose that position size with another value, it gives me wrong result, for this problem i'm not using tick size yet.
This is an example input/output
Everything is ok, it gives me the desired stop loss to risk the 1% of my account, and the take profit to gain 2x the risked amount, but it fails when i choose different position size
I will appreciate if you help me with my calculations, thanks in advance
Well, i found a solution, i will share in case you find useful.
>>> def sltp_calculator(account, entry, position_size=None, risk_percentage=0.01, reward_multiplier=2): """Stop Loss / Take Profit Calculator RESTRICTION ----------- `position_size * entry` must be greater than `account * (1 - risk_percentage)`, otherwise calculation of stop loss / take profit will fail. """ if position_size is None: position_size = account / entry # position_size * stop_loss = account * (1 - risk_percentage) # position_size * (entry - delta) = account * (1 - risk_percentage) # entry - delta = (account * (1 - risk_percentage)) / position_size delta = entry - ((account * (1 - risk_percentage)) / position_size) stop_loss = entry - delta reward_percentage = risk_percentage * reward_multiplier # position_size * take_profit = account * (1 + reward_percentage) # position_size * (entry + delta) = account * (1 + reward_percentage) # entry + delta = (account * (1 + reward_percentage)) / position_size delta = ((account * (1 + reward_percentage)) / position_size) - entry take_profit = entry + delta return position_size, stop_loss, take_profit
Hello, this is my first post, my following function behaves as expected if i let it determine my position size, but when i choose that position size with another value, it gives me wrong result, for this problem i'm not using tick size yet.
This is an example input/output
Everything is ok, it gives me the desired stop loss to risk the 1% of my account, and the take profit to gain 2x the risked amount, but it fails when i choose different position size
I will appreciate if you help me with my calculations, thanks in advance