//+------------------------------------------------------------------+
//| MyTral.mq4 |
//| Copyright by Macleod © 2010 |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright by Macleod © 2010"
#property link ""
//---- input parameters
extern string g1 = "Óðîâåíü TralingStop\'à";
extern int TrailingLevel = 400;
extern int TrailingStep = 30;
extern string g2 = "Óðîâåíü \"Áåçóáûòêà\"";
extern int ZeroLevel = 300;
extern string g3 = "MagicNumber (0 - òðàëèì âñå îðäåðà)";
extern int MagicNumber = 0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if (MagicNumber != 0 && OrderMagicNumber() != MagicNumber)
continue;
if (OrderSymbol()==Symbol()) {
RefreshRates();
Zero();
Tral();
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
int Tral()
{
if (OrderType() == OP_BUY) { // 1
if ((OrderStopLoss() < ND(Bid - TrailingLevel * Point - TrailingStep * Point)) || (OrderStopLoss() == 0)) { // 2
OrderModify(OrderTicket(),OrderOpenPrice(),ND(Bid - TrailingLevel * Point),OrderTakeProfit(),0,Green);
} // 2
} // 1 BUY
if (OrderType() == OP_SELL) { // 1
if ((OrderStopLoss() > ND(Ask + TrailingLevel * Point + TrailingStep * Point)) || (OrderStopLoss() == 0)) { // 2
OrderModify(OrderTicket(),OrderOpenPrice(),ND(Ask + TrailingLevel * Point),OrderTakeProfit(),0,Red);
} // 2
} // 1
}
int Zero()
{
if (OrderType() == OP_BUY) { // 1
if (OrderOpenPrice() <= ND(Bid - ZeroLevel * Point) && OrderOpenPrice() > OrderStopLoss()) { // 2
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
} // 2
} // 1 BUY
if (OrderType() == OP_SELL) { // 1
if (OrderOpenPrice() >= ND(Ask + ZeroLevel * Point) && OrderOpenPrice() < OrderStopLoss()) { // 2
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red);
} // 2
} // 1 SELL
}
double ND(double d, int n=-1)
{
if (n<0)
return(NormalizeDouble(d, Digits));
return(NormalizeDouble(d, n));
}
Comments