Lot size calculation

 

Hi there,

I'm trying to figure something out but ...

I'll try to explain.

I have $50000 account and I prefer to risk on every trade 3% of it. This is $1500. The standard lot normally yields $10 for 1 pip. Right ? So divide 1500 by 10 means I have 150 pips price channel for the market which I can risk. So I can have one lot and 150 pips stop loss or 3 lots and 50 pips stop loss or 5 lots and 30 pips stop loss .... etc. Am I right ? I choose to have 3 lots and 50 pips stop loss. If the trade goes wrong then I lose 3 * 50 = 150 pips which is $1500. All above for EUR/USD.

Now, how I can do all this in my EA ?

I tried the follow but with no success.

=================================

double Lots;

//Formula: Pip = lot size x tick size
//Example for 100,000 GBP/USD contract:
//1 pip = 100,000 (lot size) x .0001 (tick size) = $10.00 USD
double contract = MarketInfo( Symbol(), MODE_LOTSIZE );
double ticksize = MarketInfo( Symbol(), MODE_TICKSIZE );
double onePip = contract * ticksize;

double RiskUSD = AccountBalance() * ( Risk / 100 );

double RiskPip = RiskUSD / onePip ;

StopLoss_Pips = RiskPip / 3;

LOTs = RiskPip / StopLoss_Pips;

==================================

Obviously I'm doing something wrong because the lot size always become very big.


If anyone can help with this I'll be very thankful !


Thank you in advance .

EDIT



COME ON people.

What ? Nobody can help with this math. ???

I have tried all bloody lot size calculation func. on this forum and none of them is doing what I need !


PLEASE HELP !
 
seemore:

Hi there,

I'm trying to figure something out but ...

I'll try to explain.

I have $25000 account and I prefer to risk on every trade 3% of it. This is $1500. The standard lot normally yields $10 for 1 pip. Right ? So divide 1500 by 10 means I have 150 pips price channel for the market which I can risk. So I can have one lot and 150 pips stop loss or 3 lots and 50 pips stop loss or 5 lots and 30 pips stop loss .... etc. Am I right ? I choose to have 3 lots and 50 pips stop loss. If the trade goes wrong then I lose 3 * 50 = 150 pips which is $1500. All above for EUR/USD.

Now, how I can do all this in my EA ?

3% of $25,000 is $750, standard lot only yeilds $10 for xxxUSD pairs (assuming your deposit currency is $)

Rather than using Account Balance you might be better using FreeMargin . . .

But regardless of all this, this subject has been done to death, do a search using google (mql4 lot size) or on this forum's search for lot size

 

Choose the appropriate SL and compute the lot size from that. The $10/pip is only for a USD currency account and xxxUSD pairs.

Look at my code, it deals with margin, multiple open orders and margin calls, slippage etc.

 

Sorry, the 3% are $750 ...

Yes, I deal only with xxxUSD at the moment.

RaptorUK, WHRoeder, THANK YOU for the answers but I really want to figure out only this :

"

I have $25000 account and I prefer to risk on every trade 3% of it. This is $750. The standard lot normally yields $10 for 1 pip. Right ? So divide 1500 by 10 means I have 150 pips price channel for the market which I can risk. So I can have one lot and 150 pips stop loss or 3 lots and 50 pips stop loss or 5 lots and 30 pips stop loss .... etc. Am I right ? I choose to have 3 lots and 50 pips stop loss. If the trade goes wrong then I lose 3 * 50 = 150 pips which is $1500. All above for EUR/USD.

"


Can you help with some exact code how to get this math done ?


Thank you and I really appreciate your answers !

 
And WHRoeder, your code looks really really good but is too complicated for me. I'm trying to keep my EA very very simple and stooopid :) Anyway I'm very happy with the performance of my EA, just this lot calculation is driving me crazy...
 
seemore:
And WHRoeder, your code looks really really good but is too complicated for me. I'm trying to keep my EA very very simple and stooopid :) Anyway I'm very happy with the performance of my EA, just this lot calculation is driving me crazy...
There is only one answer . . . . . LEARN ! ! !
 
RaptorUK:
There is only one answer . . . . . LEARN ! ! !

I'm trying my best ...
 
seemore:

I'm trying my best ...
Glad to hear it, me too, I'm currently working on my TradeSize() function, you can guess what it does . . .
 
RaptorUK:
Glad to hear it, me too, I'm currently working on my TradeSize() function, you can guess what it does . . .

TradeSize() sounds the same as LotSize() :)
 
seemore:

TradeSize() sounds the same as LotSize() :)
Yep, probably very similar. Tell you what, I won't bother, when you have done yours can you send me the code, that way I can go do something else instead . . . :-)
 
RaptorUK:
Yep, probably very similar. Tell you what, I won't bother, when you have done yours can you send me the code, that way I can go do something else instead . . . :-)

No problem ! You can have it of course :)