Hi,
du kannst hier folgenden entwickelten TrailingEA verwenden.
PHP-Code:
extern double TrailingStop = 15.0;
extern double TrailingStep = 2.0;
extern bool Trailing = TRUE;
extern int MagicNumber = -1;
double points;
int init() {
points = Point;
if (Digits == 5 || Digits == 3) points = 10.0 * points;
return (0);
}
void start() {
if (TrailingStop > 0.0 && OrdersTotal() > 0) MoveTrailing();
}
void MoveTrailing() {
double open_price;
double stoploss;
double price;
double stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point / points;
double valmax = MathMax(TrailingStop, stoplevel);
for (int pos = OrdersTotal() - 1; pos >= 0; pos--) {
if (OrderSelect(pos, SELECT_BY_POS, MODE_TRADES) == TRUE) {
if (OrderMagicNumber() == MagicNumber || MagicNumber < 0 && OrderSymbol() == Symbol()) {
open_price = OrderOpenPrice();
stoploss = OrderStopLoss();
while (IsTradeContextBusy()) Sleep(500);
RefreshRates();
if (OrderType() == OP_BUY) {
price = ND(Bid - valmax * points);
if (Bid > open_price + valmax * points || !Trailing && price >= stoploss + TrailingStep * points && valmax * points > valmax * points) {
if (!OrderModify(OrderTicket(), OrderOpenPrice(), price, OrderTakeProfit(), 0, Blue))
if (!IsOptimization()) Print("BUY OrderModify Error " + GetLastError());
}
}
if (OrderType() == OP_SELL) {
price = ND(Ask + valmax * points);
if (Ask < open_price - valmax * points || !Trailing && price <= stoploss - TrailingStep * points || stoploss == 0.0 && valmax * points > valmax * points) {
if (!OrderModify(OrderTicket(), OrderOpenPrice(), price, OrderTakeProfit(), 0, Red))
if (!IsOptimization()) Print("Sell OrderModify Error " + GetLastError());
}
}
}
}
}
}
double ND(double val) {
return (NormalizeDouble(val, Digits));
}