FEMI Trailing stop
FEMI Trailing stop

FEMI Trailing stop最新版

更新日期:
2022-03-13
分类标签:
语言:
中文
平台:
没限制

13 人已下载 手机查看

描述文字

//+——————————————————————+
//| FEMI TRAILING STOP.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+——————————————————————+
input int InpTrailingStopPoints = 30; // Trailing stop points
double StopLoss;
//+——————————————————————+
//| Expert initialization function |
//+——————————————————————+
int OnInit() {
StopLoss = SymbolInfoDouble(Symbol(), SYMBOL_POINT)*InpTrailingStopPoints;
return(INIT_SUCCEEDED);
}
//—
//+——————————————————————+
//| Expert deinitialization function |
//+——————————————————————+
void OnDeinit(const int reason)
{
//—

}
//+——————————————————————+
//| Expert tick function |
//+——————————————————————+
void OnTick()
{
ApplyTrailingStop(Symbol(), StopLoss);
}
void ApplyTrailingStop(string symbol, double stopLoss) {

static int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);

// Trailing from the close prices
double buyStopLoss = NormalizeDouble(SymbolInfoDouble(symbol, SYMBOL_BID)-stopLoss, digits);
double sellStopLoss = NormalizeDouble(SymbolInfoDouble(symbol, SYMBOL_ASK)+stopLoss, digits);;

int count = OrdersTotal();
for (int i=count-1; i>=0; i–) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==symbol) {
if (OrderType()==ORDER_TYPE_BUY && buyStopLoss<OrderOpenPrice() && OrderProfit()>0 && (OrderStopLoss()==0 || buyStopLoss>OrderStopLoss())) {
if (OrderModify(OrderTicket(), OrderOpenPrice(), buyStopLoss, OrderTakeProfit(), OrderExpiration())) {}
} else
if (OrderType()==ORDER_TYPE_SELL && sellStopLoss>OrderOpenPrice() && OrderProfit()>0 && (OrderStopLoss()==0 || sellStopLoss<OrderStopLoss())) {
if (OrderModify(OrderTicket(), OrderOpenPrice(), sellStopLoss, OrderTakeProfit(), OrderExpiration())) {}
}
}
}
}

}
//+——————————————————————+

如果你对文件有了解,请帮助投票!

If you are familiar with the file, please help vote!

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位投票人。

相关资源

暂无评论

none
暂无评论...