How to specify the volumn of an order to be 5% of the Account Free Margin?

 

I can use the following function to do so if the symbol is like USD/xxx.

double dblVolumn = AccountFreeMargin()*0.05*AccountLeverage()/100000;

But the function doesn't work for symbols like xxx/USD or xxx/yyy. Apparently I should convert it using their corresponding current price. It's still easy to do so if it is like xxx/USD. What should I do if it is like xxx/yyy? Is there any convenient way to do the conversion?

Thanks.

 

I've posted on this recently. Have a search of the forum and you'll find my formulae.


CB

 
cloudbreaker:

I've posted on this recently. Have a search of the forum and you'll find my formulae.

Personally, I'd appreciate a little further coverage of it here, because I'm not sure I follow how and why you appear to be normalizing tick-sizes versus tick-values in your previous post.


In simple money management there is one constant (the profit/loss for each pip of movement in a symbol) and three variables: the number of lots you trade, the size of your stop loss in pips, and the amount of cash you are prepared to risk. In essence, you choose two out of these three figures depending on the nature of your strategy, and that determines the third one. For example, if you want a stop loss of 100 pips and aren't prepared to risk more than $1,000, then you have to adjust your lot sizing accordingly. Alternatively, if you want to trade 0.25 lots and you're not prepared to risk more than $1,000, then that determines the positioning of your stop loss.


Taking the first example - fixed stop loss and risk, determining the lot sizing - then the calculation would seem to go as follows:


A. The number of pips in your stop loss multiplied by MODE_TICKVALUE gives you the loss you will incur if trading 1.00 lots (e.g. 100 pips times $10 per pip = $1,000)

B. You take your fixed risk (e.g. 5% of free margin) and divide it by A. This gives you the number of lots you can afford to trade (e.g. 5% of $10,000 free margin = $500, which means that you can trade $500 / $1,000 = 0.50 lots).


Taking the second example - fixed lot size and risk, determining the distance to the stop loss - then the calculation would seem to go as follows:


A. MODE_TICKVALUE gives you the value per whole lot of each pip of movement in the symbol (e.g. $10).

B. This multiplied by your fixed lot sizing gives you the value per pip of movement in the trade you're about to place (e.g. $10 * 0.5 lots = $5)

C. You have a fixed sum of money (e.g. 5% of free margin). This divided by the value of each pip from step B gives you the number of pips you can afford for your stop loss. (e.g. 5% of $10,000 free margin = $500, divided by a cost of $5 per pip = 100 pip stop loss).

D. The number of pips for the stop loss multiplied by MODE_TICKSIZE gives you the amount to add/subtract from your entry price to set your stop loss at.


The one particular problem with both these calculations is that they don't take account of the initial margin used in placing the trade.

 
jjc:

Personally, I'd appreciate a little further coverage of it here, because I'm not sure I follow how and why you appear to be normalizing tick-sizes versus tick-values in your previous post.


In simple money management there is one constant (the profit/loss for each pip of movement in a symbol) and three variables: the number of lots you trade, the size of your stop loss in pips, and the amount of cash you are prepared to risk. In essence, you choose two out of these three figures depending on the nature of your strategy, and that determines the third one. For example, if you want a stop loss of 100 pips and aren't prepared to risk more than $1,000, then you have to adjust your lot sizing accordingly. Alternatively, if you want to trade 0.25 lots and you're not prepared to risk more than $1,000, then that determines the positioning of your stop loss.


Taking the first example - fixed stop loss and risk, determining the lot sizing - then the calculation would seem to go as follows:


A. The number of pips in your stop loss multiplied by MODE_TICKVALUE gives you the loss you will incur if trading 1.00 lots (e.g. 100 pips times $10 per pip = $1,000)

B. You take your fixed risk (e.g. 5% of free margin) and divide it by A. This gives you the number of lots you can afford to trade (e.g. 5% of $10,000 free margin = $500, which means that you can trade $500 / $1,000 = 0.50 lots).


Taking the second example - fixed lot size and risk, determining the distance to the stop loss - then the calculation would seem to go as follows:


A. MODE_TICKVALUE gives you the value per whole lot of each pip of movement in the symbol (e.g. $10).

B. This multiplied by your fixed lot sizing gives you the value per pip of movement in the trade you're about to place (e.g. $10 * 0.5 lots = $5)

C. You have a fixed sum of money (e.g. 5% of free margin). This divided by the value of each pip from step B gives you the number of pips you can afford for your stop loss. (e.g. 5% of $10,000 free margin = $500, divided by a cost of $5 per pip = 100 pip stop loss).

D. The number of pips for the stop loss multiplied by MODE_TICKSIZE gives you the amount to add/subtract from your entry price to set your stop loss at.


The one particular problem with both these calculations is that they don't take account of the initial margin used in placing the trade.


Good stuff jjc, and I certainly agree with most of it.

Whether or not MODE_TICKVALUE is a constant depends upon the relationship between the symbol you trade and the deposit currency of the account you are using.

I have found that in most cases MODE_TICKSIZE is equal to Point. However, in some cases it is not. To arrive at a universal "TV per Point" value I always use a ratio of MODE_TICKVALUE and (MODE_TICKSIZE divided by Point).

Hey - I may be wrong for some theoretical reason, however on a practical basis, it works universally in exactly the way I wish it to.


CB

 
cloudbreaker:

Whether or not MODE_TICKVALUE is a constant depends upon [...]

True. Not strictly a constant for all symbols. Basically, it's a constant if the quote currency is the same as your deposit currency.

 
jjc:

True. Not strictly a constant for all symbols. Basically, it's a constant if the quote currency is the same as your deposit currency.


Yep. That's it. :-)

Do you get what I'm saying now about TV and TS?


CB

 
cloudbreaker:

Do you get what I'm saying now about TV and TS?

The mechanics of what you're doing with it have been clear all along. The bit which I'm struggling to get clear to myself is whether, so to speak, this just happens to work, in the limited world of MT4 and its brokers only, or whether there's something more subtle going on that I'm missing. For example, it wouldn't seem to work on /6B and /6E futures (GBPUSD and EURUSD). They've both got tick sizes of 0.0001, but point values of $62,500 vs $125,000. Similarly, the CBOT gold contract (/ZG) has a tick size of 0.1 and a point value of $100.

Reason: