0

Part 1: Formula to calculate Stop Loss based on account variables

In part 1 I had trouble trying to get the formula correct to set a StopLoss at the right point. after weeks, I finally got it.

$$x = e-(p/L\times 0.01)\times e).$$

Now I have another related issue.

Lets say that I calculated my stoploss to be 9% of my account balance, and that worked, and the stoploss was hit. That means that my account just lost 9% and I am trying to verify that with a Profit/Loss % after the position is closed. This is what I have:

  • Previous Account Balance = Current Account Balance - Loss
  • Difference = Current Account Balance - Previous Account Balance
  • StopLoss Percent = (Difference/Previous Account Balance) * 100

or in mathjax $$-x = {(a - (a-l))\over (a-l)} * 100$$

in this case, if x above equals 9% then x here should equal -9%, unless the position closed in a profit, then x should be something positive.

This isn't working as x comes in anywhere between -1 and -4

1 Answers1

1

Note that your equation is $-x=\frac {-l}{a-l}\cdot 100%$ You should be dividing by $a$, the previous balance, not $a-l$. If you start with $100$ and lose $9\%$, you have $91$ left, but $\frac 9{91}\cdot 100%$ is about $10\%$.

$x$ should be coming out too large because you are dividing by too small a number. I don't know how you get between $1$ and $4$.

Ross Millikan
  • 374,822
  • Thank you for the response. The mathjax was an attempt to rewrite what is in the bulleted list to make it more readable. in the last bullet, i am dividing the difference in price by the previous amount. a-l = previous balance. a = current balance. does that change anything? going back and checking, they are coming out between -1 and --10. (this is all within a python based bot) – Keven Scharaswak Sep 09 '19 at 15:02
  • 1
    The line Previous Account Balance =Current Account Balance - Loss is not correct. It should be Current Account + Loss assuming you take the Loss as a positive number In any case, you should be dividing by the Previous Account Balance, which I thought was $a$, though you didn't say so. – Ross Millikan Sep 09 '19 at 16:40