# Calculate lotsize from money (USD) - page 2

28

WHRoeder:
 question: What is DIR? +1 for a buy -1 for a sell
Never mind, the formula I tried to figure out doesn't seems to work too.
379

If I am not wrong , the code in link you posted solves when you want to get lotsize from % of balance.

The code I linked to does illustrate position sizing using percentage of balance.  But the main formula (lotsize = risk amount / stoploss value) is true for both percentage of balance and fixed risk amounts.

My question is, how can I improve the formula and make it finally usable? Should I multiply stoploss with PointValue like you do? Would that be a solution?

I can't answer your questions definitively because you haven't posted any of your code in which you attempt to "improve" the formula and "make it finally usable".  This is partially why I gave you just the main formula (lotsize = risk amount / stoploss value).  How you calculate both risk amount and stoploss value is up to you in your code (although, I caution you that calculating the stoploss value can be a bit tricky...and the subject of much debate on this site.).  If you attempt to code it and encounter problems, post your attempted code here and several of us can try to help.

28

"although, I caution you that calculating the stoploss value can be a bit tricky...and the subject of much debate on this site."

Yes, plenty of opinions, topics and codes... That's why I asked for the solution, because I can't figure it out by myself. There's just too much of that everywhere and no solution. I didn't want to anyone to write an EA for me, I just wanted one function. What's wrong with that? If that's such a problem, sorry for bothering you.

I tried that:

```      double PointValue = MarketInfo(Symbol(), MODE_TICKVALUE) / (MarketInfo(Symbol(), MODE_TICKSIZE) / Point);
double Lotsize = Risk_USD/SLoss*PointValue;```
379

Yes, plenty of opinions, topics and codes... That's why I asked for the solution, because I can't figure it out by myself. There's just too much of that everywhere and no solution.

I understand.  There is allot of topics, conversations, and opinions regarding how to calculate lot size.  There is no easy answer...there are times where you have to wade through the minutiae just to find the right answer.

I tried that:

```double PointValue = MarketInfo(Symbol(), MODE_TICKVALUE) / (MarketInfo(Symbol(), MODE_TICKSIZE) / Point);
double Lotsize = Risk_USD/SLoss*PointValue;```

Is your SLoss denominated in points or pips?  To use PointValue, as I've used in my equation, stoploss must be distance denominated in points.

So, let's say that PointValue is 1.0 (standard account with USD deposit currency on a EUR/USD chart) and your stoploss is 1000 points (100 pips) and your fixed risk amount is \$80.

The equation is: lotsize = 80 / (1000 * 1.0)

Therefore, lotsize = 0.08 (that is 8 microlots on a standard account).

That is why, using the code that I used in my equation, SLoss must be denominated in points, not pips.  (If you used pips, rather than points, the equation would be: lotsize = 80 / (100 * 1.0), which is 0.80 (8 minilots) and a 10 times larger position then you wanted. However, you can change the equation to use pips...I just found it easier to use points.)

There is also a question of minimum and maximum lotsize and the lotstep.  The minimum and maximum lotsize are self-explanatory...your lotsize must be equal to or greater than the minimum and must be less than or equal to the maximum.  Lotstep determines the least significant digit for lotsize between the minimum and maximum.  For example, if the minimum lotsize is 0.10 and lotstep is 0.01, then you can use lotsizes 0.10, 0.11, 0.12, etc, but not 0.09.

Review the code that I linked to to get an idea about minimum and maximum lotsize and lotstep.

16096

1. question:

"although, I caution you that calculating the stoploss value can be a bit tricky...and the subject of much debate on this site."

`PointValue = MarketInfo(Symbol(), MODE_TICKVALUE) / (MarketInfo(Symbol(), MODE_TICKSIZE) / Point);`
Had you bothered to look at my DeltaPerLot link you wouldn't have seen any /Point and you would have known why. Drop the /Point. On currencies Ticksize == point but on metals they don't.
2. `  double Lotsize = Risk_USD/SLoss*PointValue;`
We have no idea what SLoss is but it had better be a change in price, not pips or points.
Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
Look at the equation and your derivation again. Don't you want Risk_USD/ ( SLoss * PointValue ) or Risk_USD/SLoss / PointValue?
379

On currencies Ticksize == point but on metals they don't.

I trade in the US, so unfortunately, I am restricted by law and CFTC rule from trading precious metals in my forex account.  Since I can't trade metals in my forex account, I generally don't code for them; and my code and functions reflect that fact!

Had you bothered to look at my DeltaPerLot link you wouldn't have seen any /Point and you would have known why. Drop the /Point.

Maybe you didn't bother to read my explanation to you the last time you said this.  I respect you and all the knowledge you bring to discussions here, but why is your function (including your DeltaPerlot) the only and exclusive way to calculate lotsizes?  I have looked long and hard at your DeltaValuePerLot function.  As I explained to you in a previous post (which I had hoped you had at least read), I wanted the value per point.  And your DeltaValuePerLot did not give me value per point in deposit currency; that is why I don't use your DeltaValuePerLot.  TickSize is a multiple of Point; this is why I must use Point to achieve a the appropriate divisor of TickValue.  Sure, most (if not all) of the time, TickSize == Point and TickSize / Point == 1.0.  But the rule is: TickSize is a multiple of Point.  That is the reason I use Point the way I do in this instance.  I wanted value per point in deposit currency; my PointValue calculation gives me that value.  Now, hopefully, you know why I use Point!

We have no idea what SLoss is but it had better be a change in price, not pips or points.

We don't have much of an idea what SLoss is, but in my code (which the OP has modeled after), it sure better be distance in points!  The general formula is: lotsize = risk amount / stoploss value.  Since PointValue (as the self-describing name insists) is value per point in deposit currency, SLoss must in distance in points.  The product of those two values create the stoploss value.

Look at the equation and your derivation again. Don't you want Risk_USD/ ( SLoss * PointValue ) or Risk_USD/SLoss / PointValue?

Risk_USD / (SLoss * PointValue).  This was explicit in my code and inferred from my examples.  Why would you divide by PointValue???

16096

1. Risk = change in price * DeltaValuePerLot * lots. So If you want the change per point multiply by point. If you want the change in pips, multiply by pips like my link showed
2.  "Why would you divide by PointValue???" RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot Do your algebra. divide by price change RISK / (OrderOpenPrice - OrderStopLoss)*DIR  =  OrderLots * DeltaPerlot Do your algebra. divide by delta RISK / (OrderOpenPrice - OrderStopLoss)*DIR  / DeltaPerlot  = OrderLots Do your algebra.check your units Risk / ( delta / deltaPerlot) = Risk/perlot = lots Does it make sense? The bigger the value per lot, the smaller the lots for the same risk.
3.  Risk_USD / (SLoss * PointValue). This was explicit in my code and inferred from my examples. Why would you divide by PointValue??? Risk_USD / (SLoss * PointValue) is dividing by PointValue Of course you MUST divide by PointValue. Your original post did NOT `double Lotsize = Risk_USD/SLoss*PointValue;`

4. Thirteen: I trade in the US, so unfortunately, I am restricted by law and CFTC rule from trading precious metals in my forex account.  Since I can't trade metals in my forex account, I generally don't code for them; and my code and functions reflect that fact!
FXCM is a US broker and allows metals Did you market watch -> right click -> show all?
5. and just because you can't (with your current broker) means you may not in the future (same or difference,) code it correctly and be done. Do you really want to have a known, waiting bug in your code?