Money management.

 
If I want to risk buying lots with 1% of account each trade, how do I code that. How can determine how much lots to place the order for if my account is 100,000. so 1% is $1000. and I want to buy $1000 worth of lots. Would the same code work if I used the EA on micro-account? How do I go about doing this.
 

I personally use my SL as a %... so if my Stoploss is 100pips and my 1% risk is $1000 then I take the $1000/100 = $10/pip.


Then You need to know what $10/pip is like on your platform... on mine its 1.0.

So I do it like this :

double bal = AccountBalance();

double risk = bal/100*Risk;

double risklot = risk/stop;


note : my stop is calculated as long or short by using the entry criteria of my EA and StopLoss setting the EA would use.


as example : if my EA opens a SHORT trade on the new candle and the stop is 5 pips higher than the last candles high i do this :

double sl = High[1]+5*point;

double stop = sl-Open[0];

so now the stoploss value in pips is a variable that can be used in the calc above...


someone mite have a better or more elegant way to do it but this works for me perfectly... I risk 2% of my account on every trade not on the open of lots but on the total loss of the trade.

 
23510:

I personally use my SL as a %... so if my Stoploss is 100pips and my 1% risk is $1000 then I take the $1000/100 = $10/pip.


Then You need to know what $10/pip is like on your platform... on mine its 1.0.

Is it ? even for USDJPY, or EURGBP ?
 
I only trade Eu and GU Raptor so yes...it is. :)
 
Take a look at MODE_TICKVALUE used in MarketInfo( string symbol, int type)
 
double  PointValuePerLot(string pair=NULL) {
    /* Value in account currency of a Point of Symbol.
     * In tester I had a sale: open=1.35883 close=1.35736 (0.00147)
     * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip.
     * IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
     * IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
     *                                  $1.00/point or $10.00/pip.
     *
     * https://forum.mql4.com/33975 CB: MODE_TICKSIZE will usually return the
     * same value as MODE_POINT (or Point for the current symbol), however, an
     * example of where to use MODE_TICKSIZE would be as part of a ratio with
     * MODE_TICKVALUE when performing money management calculations which need
     * to take account of the pair and the account currency. The reason I use
     * this ratio is that although TV and TS may constantly be returned as
     * something like 7.00 and 0.00001 respectively, I've seen this
     * (intermittently) change to 14.00 and 0.00002 respectively (just example
     * tick values to illustrate). */
    if (pair == NULL)   pair = Symbol();
    return(  MarketInfo(pair, MODE_TICKVALUE)
           / MarketInfo(pair, MODE_TICKSIZE) ); // Not Point.
}
Reason: