Skip to content

Instantly share code, notes, and snippets.

@notmii
Created November 18, 2015 07:06
Show Gist options
  • Save notmii/5228c23f58fb45050644 to your computer and use it in GitHub Desktop.
Save notmii/5228c23f58fb45050644 to your computer and use it in GitHub Desktop.
input double trailingStop
void tailStop() {
for (int i = 0; i < OrdersTotal(); i++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY) {
if (Bid - OrderOpenPrice() > trailingStop * MarketInfo(NULL, MODE_POINT)) {
if (OrderStopLoss() < Bid - trailingStop * MarketInfo(NULL, MODE_POINT)
|| (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - trailingStop * MarketInfo(NULL, MODE_POINT), OrderTakeProfit(), Red);
}
}
} else if (OrderType() == OP_SELL) {
if (OrderOpenPrice() - Ask > trailingStop * MarketInfo(NULL, MODE_POINT)) {
if ((OrderStopLoss() > Ask + trailingStop * MarketInfo(NULL, MODE_POINT))
|| (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + trailingStop * MarketInfo(NULL, MODE_POINT), OrderTakeProfit(), Red);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment