Solution for "How to Make EA Auto Fits 4, 5, 6 and Any Digits Form Platforms, Unit in Pips."

 
This is a simple algorithm I'm using in all my EA for a long time and proof working, so they are all setting in pips for this related topic, and automatic changed into the platform specific Points.
The reason for creating this is because I have seen there are many not wise implementation.

Function pips2Points()
//+------------------------------------------------------------------+
//| pips2Points() @http://kolier.li |
//+------------------------------------------------------------------+
double pips2Points(double pips)
{
double points;
if(Close[0]<10) {
points = pips*MathPow(10,Digits-4);
}
else if(Close[0]>10) {
points = pips*MathPow(10,Digits-2);
}
return(points);
}

User Input Parameters
extern double TakeProfit = 10; // In Pips. Take Profit, Change to 0 if you don't want to use.
extern double StopLoss = 10; // In Pips. Stop Loss, Change to 0 if you don't want to use.

Implementation
tp = pips2Points(TakeProfit)*Point;
sl = pips2Points(StopLoss)*Point;

int ticket = OrderSend(Symbol(), OP_BUY, 1, Ask, 3, Ask-sl, Ask+tp);

 

The unit for Slippage is points. In your OrderSend(..., 3, ...) the 3 is in pips and must also be converted.

Why convert pips to points with all the over head of a function call and then multiply by Point to create a double. One multiply is sufficient:

//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
 

Hi, WHRoeder,

Slippage don't need to convert to points, it's INT, https://docs.mql4.com/trading/OrderSend

Its unit is pips, am I wrong?

Sure, still can make my function simper.

But I thought my function is successor of your suggestion currently for MT4 while there are some 6 Digits platform. Your suggested function can not fits 4, 5, 6 or even larger automatically.

But seems that due to many traders feel hard to comfort with those 6 Digits, some of those brokers already changed back to 5 Digits.

 
kolier:

Hi, WHRoeder,

Slippage don't need to convert to points, it's INT, https://docs.mql4.com/trading/OrderSend

Its unit is pips, am I wrong?

Sure, still can make my function simper.

But I thought my function is successor of your suggestion currently for MT4 while there are some 6 Digits platform. Your suggested function can not fits 4, 5, 6 or even larger automatically.

But seems that due to many traders feel hard to comfort with those 6 Digits, some of those brokers already changed back to 5 Digits.

The function OrderSend is not well documented. The slippage is in Points not pips. Most functions seem to use Points and there is no mention of pips.

The fact that the data type is an int is neither here nor there. Slippage is the integer number of points. If a pip is a point (4 digit broker) then that's ok. Otherwise you multiply by 10. Either way it is still an int. You are perhaps confusing the slippage in points with the value of a point (which is a double).

 

Hi, dabbler

I always treat the Slippage as pips, based on the results of my many tests long ago.

Just like the freeze level.

Any Official declarer?

 
kolier:

I always treat the Slippage as pips, based on the results of my many tests long ago.


Same here, in practice I set my slippage equal to MODE_SPREAD for any given currency pair.
 

In the orderSend the slippage value is in points OrderSend(..., 3, ...) means 3 pips (3 points) on a 4 digit broker and 0.3 pips (3 points) on a 5 digit broker.

Therefor it must be adjusted as I previously posted.

 
WHRoeder:

In the orderSend the slippage value is in points OrderSend(..., 3, ...) means 3 pips (3 points) on a 4 digit broker and 0.3 pips (3 points) on a 5 digit broker.

Therefor it must be adjusted as I previously posted.

How about this pips in order making window?

 

Guys,

How can I convert my code from 4 digits to 5.

Please find it attached.

Thanks

Dooby

Files:
 
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
 
How can i change the attached EA so it works with my 3 digit broker on USDJPY? Currently it is set up for 5 digits
Files:
Reason: