calculate pip size for currency?

 

Is there a way for MQL4 to adjust lot sizes based on the currency pair.

For example I use AccoutnBalance to calculate the trade size but this should be adjusted for each pair.

If my account is in GBP, then a trade size of 1 on GBPUSD is actually $1.5 and if I want it to be £1 per point then it needs to be adjusted up to a trade size of 1.5.

That's easy for GBPUSD or any pair with GBP in it but what do I do if it's a trade on EURCAD? I need to compare it to GBPCAD.


Is there a way to do this dynamically for every pair?


EURUSD, 1 pip = $1.27. GBPUSD = $1.52

So to trade at £1 per pip on EURUSD, I need to have a trade size of 1.52/1.27 = 1.19 mini lots


Repeat calculation for each pair used?

 

You should read up on MarketInfo(symbol, MODE_TICKVALUE) -> https://www.mql5.com/en/forum/126450/page4#330987.

 
gordon:

You should read up on MarketInfo(symbol, MODE_TICKVALUE) -> https://www.mql5.com/en/forum/126450/page4#330987.


If I do MarketInfo(Symbol(), MODE_TICKVALUE) on GBPUSD it gives me a value of 0.656 meaning £0.656 to $1

But shouldn't my trade size be higher than 0.656 to trade at £1 per pip?


Or I do 0.1 / 0.656 giving a 0.152 lot size?

 

one lot, one point up means 0.656 in your account currency $0.656 usd, 0.656 euros, whatever.

But shouldn't my trade size be higher than 0.656 to trade at £1 per pip?
if your account currency is pounds and you want one pound per Point you trade 1/0.0656 lots. On a 5 digit broker a pip is 10 points.
//+------------------------------------------------------------------+
//| Lot size computation.                                            |
//+------------------------------------------------------------------+
double  LotSize(double SL_points){
    /* This function computes the lot size for a trade.
     * Explicit inputs are SL relative to bid/ask (E.G. SL=30*points,)
     * Implicit inputs are the MM mode, the MM multiplier, count currently
     * filled orders by all EA's vs this EA and Previous closed orders list.
     * Implicit inputs are all used to reduce available balance the maximum
     * dollar risk allowed. StopLoss determines the maximum dollar risk possible
     * per lot. Lots=maxRisk/maxRiskPerLot
     **************************************************************************/

    /*++++ Compute lot size based on account balance and MM mode*/{
    double  ab  = AccountBalance();
    switch(MMMode.F0M1G2){
    case MMMODE_FIXED:
        at.risk = MMMultplier;
        break;
    case MMMODE_MODERATE:
        // See https://www.mql5.com/en/articles/1526 Fallacies, Part 1: Money
        // Management is Secondary and Not Very Important.
        at.risk = MathSqrt(MMMultplier * ab)/ab;     // % used/trade ~const.
        at.risk = MathSqrt(MMMultplier * ab
                            * MathPow( 1 - at.risk, OrdersTotal()-oo.count ));
        break;
    case MMMODE_GEOMETRICAL:
        at.risk = MMMultplier * ab
                            * MathPow(1 - MMMultplier, OrdersTotal()-oo.count);
        break;
    }
    double  maxLossPerLot   = SL_points/Point
                            * MarketInfo( Symbol(), MODE_TICKVALUE ),
            minLot      = MarketInfo(Symbol(), MODE_MINLOT),
    // IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
    // 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/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000
    //                                  $1.00/point or $10.00/pip.
    // at.risk / maxLossPerLot = number of lots wanted. Must be
    // rounded/truncated to nearest lotStep size, still.
    //
    // However, the broker doesn't care about the at.risk/account balance. They
    // care about margin. margin used=lots used*marginPerLot and that must be
    // less than free margin available.
            marginFree   = AccountFreeMargin(),
            marginPerLot = MarketInfo( Symbol(), MODE_MARGINREQUIRED ),
    // So I use, the lesser of either.
            size = MathMin(marginFree / marginPerLot, at.risk / maxLossPerLot);
    /*---- Compute lot size based on account balance and MM mode*/}

    /*++++ Combine TSSF and trade size*/{
    if (size < minLot){ // Multiple orders -> no free margin
            // [risk=9.48USD/40.80, margin=10.62/1334.48, MMM=1x1, ExtraOO=0]
            //       0.23                  0.007
        Print(
            "LotSize(SL=", DoubleToStr(SL_points/pips2dbl, Digits.pips), ")=",
            size, " [risk=", at.risk, AccountCurrency(),    "/", maxLossPerLot,
                    ", margin=",    marginFree,             "/", marginPerLot,
                    ", MMM=",       MMMode.F0M1G2,          "x", MMMultplier,
                    ", ExtraOO=",   OrdersTotal()-oo.count,
                "]" );
        return(0.0);    // Risk limit.
    }
    double  LotStep     = MarketInfo(Symbol(), MODE_LOTSTEP),
            adjFactTSSF = MathMin(1,(TSSF-1)/(TSSF.Max-1)),
            adjFactTEF  = MathMin(1,MathMax(0,TEF));
        if (!TSSF.Enable01)     adjFactTSSF     = 1;
        if (!TEF.Enable01)      adjFactTEF      = 1;
    size =  MathMax( minLot
                   , MathFloor(size*adjFactTEF*adjFactTEF/ LotStep)*LotStep
                   );
    /*---- Combine TSSF and trade size*/}
    at.risk = size * maxLossPerLot; // Export for Comment
    return(size);
}   // LotSize