How to Make EA Auto Fits 4, 5, 6 and Any Digits Form Platforms, Unit in Pips.
Wed, 07/21/2010 - 10:35 | kolier 0 comments
Usually the old EA only fits one digits form platform, or use Unit in Points when set to 10 to represent 10 pips in 4 Digits, set to 100 to represent 10 pips in 5 Digits, etc.
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);
}Use Case
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.
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);
