Vol = any volatility indicator reading of your choosing such as ATR
SLmultiplier = an input variable controlling SL size as a multiplier.
TPmultiplier = an input variable controlling TP size as a multiplier.
Risk = an input variable that is the percentage risk of account balance per trade.
I hope the rest are self-explanatory.
TPsize = Vol * TPmultiplier SLsize = Vol * SLmultiplier SLticks = SLsize / TickSize AmtToRisk = Risk * 0.01 * AccountBalance Lotsize = AmtToRisk/SLticks/TickValue