//--------------------------------------------------------------------- // Получить время открытия последнего ордера данного типа. //--------------------------------------------------------------------- #property copyright "© RickD 2006-2007" #property link "www.e2e-fx.net" //--------------------------------------------------------------------- // type - тип ордера OP_BUY/OP_SELL // Смотрим в открытых ордерах и в истории. // Если не найдено ордеров, удовлетворяющих условиям поиска, возвращаем -1. // Польза от функции GetLastOpenTime такая. // Например мы не хотим открывать лонг-ордера чаще чем раз в 2 часа. // Тогда условие на открытие будет выглядеть так: // if (CurTime() - GetLastOpenTime(OP_BUY) >= 2*60*60) { // OrderSend(Symbol(), OP_BUY, ... // } //--------------------------------------------------------------------- datetime GetLastOpenTime(int type) { datetime tm = -1; int cnt = OrdersTotal(); for (int i=0; i < cnt; i++) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; //if (OrderSymbol() != Symbol()) continue; //if (OrderMagicNumber() != Magic) continue; if (OrderType() != type) continue; tm = MathMax(tm, OrderOpenTime()); } cnt = HistoryTotal(); for (i=0; i < cnt; i++) { if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue; //if (OrderSymbol() != Symbol()) continue; //if (OrderMagicNumber() != Magic) continue; if (OrderType() != type) continue; tm = MathMax(tm, OrderOpenTime()); } return (tm); }