すべてのロング/ショートポジションを決済する
返信 0 件
こんにちは,
to close long or short only for specified symbol you can do this:
1) ウィザードフォルダにあるCustomFunction.mq4にカスタムコードを追加する
void closeAllOrders(string direction, string symbolStr) {
int total = OrdersTotal();
for(int i=total-1;i>=0;i--) {
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
if (direction == "LONG" && type == OP_BUY && OrderSymbol() == symbolStr) {
result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
}
else if (direction == "SHORT" && type == OP_SELL && OrderSymbol() == symbolStr) {
result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
}
if(result == false) {
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}
return(0);
}
2) 追加 カスタムアクション ウィザードのようにこのように
closeAllOrders("LONG", "EURUSD");
This for example will close all long positions for EURUSD
質問があればお知らせください
0