Download MetaTrader 5

Calculate lotsize from money (USD)

To add comments, please log in or register
MQL5 language supports OpenCL. Try it!
Question
28
Question 2015.03.16 23:49 

Hi,

 I need a simple function. 

 I know stop loss and fixed amount of money (let's say in USD). 

I'd like to know, where SL should be placed.

 

Please, don't post some topics, libraries, big parts of code, that doesn't solve the exact problem...

Just something like

double LotsizeFromMoney(StopLoss, Money) {} //returns SL

 

I couldn't find it anywhere and I am looking for it for about 3 months, it really drives me mad. 

Baby Blue
20
Baby Blue 2015.03.17 00:18  
question:

Hi,

 I need a simple function. 

 I know stop loss and fixed amount of money (let's say in USD). 

I'd like to know, where SL should be placed.

 

Please, don't post some topics, libraries, big parts of code, that doesn't solve the exact problem...

Just something like

double LotsizeFromMoney(StopLoss, Money) {} //returns SL

 

I couldn't find it anywhere and I am looking for it for about 3 months, it really drives me mad. 

Wtf are u talking about? You said the sl is known, which form is it stored? Be precise
whroeder1
14518
whroeder1 2015.03.17 01:28  
question: I'd like to know, where SL should be placed.
  1. You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  2. Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
  3. Do NOT use TickValue by itself - DeltaPerlot
  4. You must normalize lots properly and check against min and max.
  5. You must also check FreeMargin to avoid stop out
Question
28
Question 2015.03.17 08:06  

Sorry, I explained wrong.

 

I know SL and amount of money that I want to loose when SL is hit.

 I want to calculate lotsize from that. Just one goddamn function. 

 

WHRoeder - sadly that's not the exact solution of the problem 

 

Example - I know my SL is 40 pips and I want to loose $80 when SL is hit.  I need to calculate lotsize.

 

PLAESE DON'T POST ANY OTHER THINGS. TRY TO POST ONE, WORKING FUNCTION. THANKS 

Question
28
Question 2015.03.17 12:45  
It makes me mad, that there's no answer for that...
whroeder1
14518
whroeder1 2015.03.17 12:48  
question: . TRY TO POST ONE, WORKING FUNCTION.
Example - I know my SL is 40 pips and I want to loose $80 when SL is hit.  I need to calculate lotsize.
  1. DON'T SHOUT AT US
  2. TRY to learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  3. I gave you the formula, solve for lotsize and code it.
Question
28
Question 2015.03.17 12:55  

Sorry, I didn't want to. 

 

I just wanted to find the solution. I've already read those topics, but it has never worked for me.

Is that really that complicated?  I just can't figure out the solution...

Question
28
Question 2015.03.17 14:08  

Ok, you posted this formula:

Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)

So for Lotsize it should be:  Lotsize = Account Balance/(DIR*OrderOpenPrice*DeltaPerlot - DIR*OrderStopLoss*DeltaPerlot)

Is that correct? What is DIR?

Thanks 

GreenMoney
379
GreenMoney 2015.03.17 14:09  
question:

Sorry, I didn't want to. 

I just wanted to find the solution. I've already read those topics, but it has never worked for me.

Is that really that complicated?  I just can't figure out the solution...

Stop being petulant and at least attempt to understand what others are trying to tell you.

The formula is: lotsize = risk amount / stoploss value (i.e., lotsize equals risk amount divided by stoploss value)

Be careful about calculating stoploss value...you must calculate stoploss value correctly.

This site is replete with discussions and examples of how to calculate lotsize (here is my lotsize code).  If you haven't been able to find anything for 3 months, you haven't been looking very hard.  I suggest you search again and try to understand some of discussions you uncover regarding lotsize calculation.

whroeder1
14518
whroeder1 2015.03.17 20:58  
question: What is DIR?
+1 for a buy -1 for a sell
Question
28
Question 2015.03.17 20:58  
Thirteen:

Stop being petulant and at least attempt to understand what others are trying to tell you.

The formula is: lotsize = risk amount / stoploss value (i.e., lotsize equals risk amount divided by stoploss value)

Be careful about calculating stoploss value...you must calculate stoploss value correctly.

This site is replete with discussions and examples of how to calculate lotsize (here is my lotsize code).  If you haven't been able to find anything for 3 months, you haven't been looking very hard.  I suggest you search again and try to understand some of discussions you uncover regarding lotsize calculation.

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

Those things can be found easily, that's not the problem.

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?

 

EDIT: Actually isn't, I am wrong again. 

12
To add comments, please log in or register