Pon "Me gusta" y sigue las noticias
Deje un enlace a él, ¡qué los demás también lo valoren!
Evalúe su trabajo en el terminal MetaTrader 5
TypePendingOrderTriggered - Asesor Experto para MetaTrader 5
- Visualizaciones:
- 920
- Ranking:
- Publicado:
- 2017.03.27 10:58
- ¿Necesita un robot o indicador basado en este código? Solicítelo en la bolsa freelance Pasar a la bolsa
El Asesor Experto muestra el ejemplo de la solución del problema: ¿Cómo determinar el momento de la activación de la orden pendiente?
Cómo trabaja el EA: en la función OnTradeTransaction(), esperamos la transacción del tipo "TRADE_TRANSACTION_DEAL_ADD":
TRADE_TRANSACTION_DEAL_ADD | Adición de la transacción al historial. Se realiza como resultado de la ejecución de una orden o realización de una operación con el balance de la cuenta. |
Una vez «capturada» esta transacción, mostramos inmediatamente la bandera "bln_find_order" de la búsqueda de la orden y le asignamos a la variable "ul_find_order" el tiket de la orden:
//+------------------------------------------------------------------+ //| TradeTransaction function | //+------------------------------------------------------------------+ void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result) { //+------------------------------------------------------------------+ //| TRADE_TRANSACTION_DEAL_* | //| The following fields in MqlTradeTransaction structure | //| are filled for trade transactions related to deals handling | //| (TRADE_TRANSACTION_DEAL_ADD, TRADE_TRANSACTION_DEAL_UPDATE | //| and TRADE_TRANSACTION_DEAL_DELETE): | //| •deal - deal ticket; | //| •order - order ticket, based on which a deal has been performed;| //| •symbol - deal symbol name; | //| •type - trade transaction type; | //| •deal_type - deal type; | //| •price - deal price; | //| •price_sl - Stop Loss price (filled, if specified in the order, | //| •based on which a deal has been performed); | //| •price_tp - Take Profit price (filled, if specified | //| in the order, based on which a deal has been performed); | //| •volume - deal volume in lots. | //| •position - the ticket of the position that was opened, | //| modified or closed as a result of deal execution. | //| •position_by - the ticket of the opposite position. | //| It is only filled for the out by deals | //| (closing a position by an opposite one). | //+------------------------------------------------------------------+ //--- get transaction type as enumeration value ENUM_TRADE_TRANSACTION_TYPE type=trans.type; //--- if transaction is result of addition of the transaction in history if(type==TRADE_TRANSACTION_DEAL_ADD) { bln_find_order=true; // true -> you should look for a order ul_find_order=trans.order; } }
En OnTick() comprobamos constantemente el estado de la bandera "bln_find_order", y en cuanto la bandera sea igual a true, empezamos la búsqueda de la orden.
- Primero, intentamos encontrar esta orden por el ticket
- Si el intento es positivo (eso significa que la orden ya ha sido registrada en el historial), determinamos el tipo de esta orden. Para acceder a la propiedad de la orden desde el historial de trading, hay que usar HistoryOrderGetInteger.
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnStart() { //--- if(bln_find_order) // true -> you should look for a order { static long counter=0; Print("Attempt number ",counter); ResetLastError(); if(HistoryOrderSelect(ul_find_order)) { long type_order=HistoryOrderGetInteger(ul_find_order,ORDER_TYPE); if(type_order==ORDER_TYPE_BUY_LIMIT || type_order==ORDER_TYPE_BUY_STOP || type_order==ORDER_TYPE_SELL_LIMIT ||type_order==ORDER_TYPE_SELL_STOP) { Print("The pending order ",ul_find_order," is found! Type of order is ", EnumToString((ENUM_ORDER_TYPE)HistoryOrderGetInteger(ul_find_order,ORDER_TYPE))); bln_find_order=false; // true -> you should look for a order counter=0; return; } else { Print("The order ",ul_find_order," is not pending"); bln_find_order=false; // true -> you should look for a order return; } } else { Print("Order ",ul_find_order," is not find, error#",GetLastError()); } counter++; } }
Traducción del ruso realizada por MetaQuotes Ltd
Artículo original: https://www.mql5.com/ru/code/17610
Dsl (líneas de señal descontinuas) - RSI.
XCCXCandleKeltnerCanal de Keltner construido respecto al valor medio del oscilador XCCX en forma de velas.
Indicador MACD en interpretación de la línea de señal descontinua (DSL).
HistoryPositionInfoDevuelve el beneficio de la posición en puntos a base del historial de trading.