Aquí es donde me he complicado un poco: he tomado este código (gracias a Alekseu Fedotov):
//+----------------------------------------------------------------------------+ //+----------------------------------------------------------------------------+ //| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru | //+----------------------------------------------------------------------------+ //| Версия : 19.02.2008 | //| Описание : Возвращает номер бара закрытия последней позиции или -1. | //+----------------------------------------------------------------------------+ //| Параметры: | //| sy - наименование инструмента ("" или NULL - текущий символ) | //| tf - таймфрейм ( 0 - текущий таймфрейм) | //| op - операция ( -1 - любая позиция) | //| mn - MagicNumber ( -1 - любой магик) | //+----------------------------------------------------------------------------+ int NumberOfBarCloseLastPos(string sy="0", int tf=0, int op=-1, int mn=-1) { datetime t; int i, k=OrdersHistoryTotal();
if (sy=="" || sy=="0") sy=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { if (OrderSymbol()==sy) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) { if (t<OrderCloseTime()) t=OrderCloseTime(); } } } } } } return(iBarShift(sy, tf, t, True)); }
Y ahora pongo la cuenta:
if(УСЛОВИЕ && NumberOfBarCloseLastPos()>0)
Y aquí está el problema, porque inicialmente NumberOfBarCloseLastPos se establecerá en "-1". Y en consecuencia, el primer pedido nunca se abrirá.
¿Qué podemos hacer en esta situación? ¿O he entendido algo mal?
En esta situación, podríamos intentarif(CONTROL && NumberOfBarCloseLastPos()>-2), o pensar
Aquí hay un pequeño matiz: tomé este código (gracias a Alekseu Fedotov):
//+----------------------------------------------------------------------------+ //+----------------------------------------------------------------------------+ //| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru | //+----------------------------------------------------------------------------+ //| Версия : 19.02.2008 | //| Описание : Возвращает номер бара закрытия последней позиции или -1. | //+----------------------------------------------------------------------------+ //| Параметры: | //| sy - наименование инструмента ("" или NULL - текущий символ) | //| tf - таймфрейм ( 0 - текущий таймфрейм) | //| op - операция ( -1 - любая позиция) | //| mn - MagicNumber ( -1 - любой магик) | //+----------------------------------------------------------------------------+ int NumberOfBarCloseLastPos(string sy="0", int tf=0, int op=-1, int mn=-1) { ... return(iBarShift(sy, tf, t, True)); }
Aquí es donde me he complicado un poco: he tomado este código (gracias a Alekseu Fedotov):
//+----------------------------------------------------------------------------+ //+----------------------------------------------------------------------------+ //| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru | //+----------------------------------------------------------------------------+ //| Версия : 19.02.2008 | //| Описание : Возвращает номер бара закрытия последней позиции или -1. | //+----------------------------------------------------------------------------+ //| Параметры: | //| sy - наименование инструмента ("" или NULL - текущий символ) | //| tf - таймфрейм ( 0 - текущий таймфрейм) | //| op - операция ( -1 - любая позиция) | //| mn - MagicNumber ( -1 - любой магик) | //+----------------------------------------------------------------------------+ int NumberOfBarCloseLastPos(string sy="0", int tf=0, int op=-1, int mn=-1) { datetime t; int i, k=OrdersHistoryTotal();
if (sy=="" || sy=="0") sy=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { if (OrderSymbol()==sy) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) { if (t<OrderCloseTime()) t=OrderCloseTime(); } } } } } } return(iBarShift(sy, tf, t, True)); }
Y ahora pongo la cuenta:
if(УСЛОВИЕ && NumberOfBarCloseLastPos()>0)
Y aquí está el problema, porque inicialmente NumberOfBarCloseLastPos se establecerá en "-1". Y en consecuencia, el primer pedido nunca se abrirá.
¿Qué se puede hacer en esta situación? ¿O he entendido algo mal?
Bueno, eso es lo que yo haría:
//+------------------------------------------------------------------+ int BarCloseLastPos(string symbol_name, ENUM_TIMEFRAMES timeframe, int type, int magic_number) { datetime time=0; int j=-1; for(int i=OrdersHistoryTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) { if(OrderMagicNumber()!=magic_number) continue; if(OrderSymbol()!=symbol_name) continue; if(OrderType()!=type) continue; if(OrderCloseTime()>time) { time=OrderCloseTime(); j=i; } } } if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)) return(iBarShift(symbol_name,timeframe,time)); return(EMPTY); } //+------------------------------------------------------------------+
... y comprueba:
if(BarCloseLastPos(Symbol(),PERIOD_CURRENT,OP_BUY,Magic)>0) { // Последняя позиция Buy была закрыта не на текущем баре }
Aquí es donde me he complicado un poco: he tomado este código (gracias a Alekseu Fedotov):
//+----------------------------------------------------------------------------+ //+----------------------------------------------------------------------------+ //| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru | //+----------------------------------------------------------------------------+ //| Версия : 19.02.2008 | //| Описание : Возвращает номер бара закрытия последней позиции или -1. | //+----------------------------------------------------------------------------+ //| Параметры: | //| sy - наименование инструмента ("" или NULL - текущий символ) | //| tf - таймфрейм ( 0 - текущий таймфрейм) | //| op - операция ( -1 - любая позиция) | //| mn - MagicNumber ( -1 - любой магик) | //+----------------------------------------------------------------------------+ int NumberOfBarCloseLastPos(string sy="0", int tf=0, int op=-1, int mn=-1) { datetime t; int i, k=OrdersHistoryTotal();
if (sy=="" || sy=="0") sy=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { if (OrderSymbol()==sy) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) { if (t<OrderCloseTime()) t=OrderCloseTime(); } } } } } } return(iBarShift(sy, tf, t, True)); }
Y ahora pongo la cuenta:
if(УСЛОВИЕ && NumberOfBarCloseLastPos()>0)
Y aquí está el problema, porque inicialmente NumberOfBarCloseLastPos se establecerá en "-1". Y en consecuencia, el primer pedido nunca se abrirá.
¿Qué podemos hacer en esta situación? ¿O he entendido algo mal?
¡Buenos días usuarios del foro MT4! Me enfrenté a un problema y creo que o bien no sé cómo calcular y un montón de calculadoras o compilador mt4 tiene su propia manera. Estoy escribiendo el código print((1.1145-1.1123-0.0020)/0.0001) debe obtener 2.He intentado imprimir((OrdArr[i].buy-Ord[1,3]-PipStep)/Punto) pinstep es igual a 0,0020 todas las variables resultado doble imprime una décima menos de lo que debería ser. Quizá alguien sepa cuál es el problema. SPS.
Para iniciar sesión y usar el sitio web MQL5.com es necesario permitir el uso de Сookies.
Por favor, active este ajuste en su navegador, de lo contrario, no podrá iniciar sesión.
Ha iniciado sesión. La autenticación de dos factores se ha desactivado. Vuelva a configurarla y escanee un nuevo código QR, o continúe con la autenticación de dos factores desactivada.
Aquí es donde me he complicado un poco: he tomado este código (gracias a Alekseu Fedotov):
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 19.02.2008 |
//| Описание : Возвращает номер бара закрытия последней позиции или -1. |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| sy - наименование инструмента ("" или NULL - текущий символ) |
//| tf - таймфрейм ( 0 - текущий таймфрейм) |
//| op - операция ( -1 - любая позиция) |
//| mn - MagicNumber ( -1 - любой магик) |
//+----------------------------------------------------------------------------+
int NumberOfBarCloseLastPos(string sy="0", int tf=0, int op=-1, int mn=-1) {
datetime t;
int i, k=OrdersHistoryTotal();
if (sy=="" || sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if (OrderSymbol()==sy) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (t<OrderCloseTime()) t=OrderCloseTime();
}
}
}
}
}
}
return(iBarShift(sy, tf, t, True));
}
Y ahora pongo la cuenta:
Y aquí está el problema, porque inicialmente NumberOfBarCloseLastPos se establecerá en "-1". Y en consecuencia, el primer pedido nunca se abrirá.
¿Qué podemos hacer en esta situación? ¿O he entendido algo mal?
Aquí hay un pequeño matiz: tomé este código (gracias a Alekseu Fedotov):
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 19.02.2008 |
//| Описание : Возвращает номер бара закрытия последней позиции или -1. |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| sy - наименование инструмента ("" или NULL - текущий символ) |
//| tf - таймфрейм ( 0 - текущий таймфрейм) |
//| op - операция ( -1 - любая позиция) |
//| mn - MagicNumber ( -1 - любой магик) |
//+----------------------------------------------------------------------------+
int NumberOfBarCloseLastPos(string sy="0", int tf=0, int op=-1, int mn=-1) {
...
return(iBarShift(sy, tf, t, True));
}
En esta situación, podría intentarif(CONDITION && NumberOfBarCloseLastPos()>-2), o pensar
Aquí es donde me he complicado un poco: he tomado este código (gracias a Alekseu Fedotov):
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 19.02.2008 |
//| Описание : Возвращает номер бара закрытия последней позиции или -1. |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| sy - наименование инструмента ("" или NULL - текущий символ) |
//| tf - таймфрейм ( 0 - текущий таймфрейм) |
//| op - операция ( -1 - любая позиция) |
//| mn - MagicNumber ( -1 - любой магик) |
//+----------------------------------------------------------------------------+
int NumberOfBarCloseLastPos(string sy="0", int tf=0, int op=-1, int mn=-1) {
datetime t;
int i, k=OrdersHistoryTotal();
if (sy=="" || sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if (OrderSymbol()==sy) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (t<OrderCloseTime()) t=OrderCloseTime();
}
}
}
}
}
}
return(iBarShift(sy, tf, t, True));
}
Y ahora pongo la cuenta:
Y aquí está el problema, porque inicialmente NumberOfBarCloseLastPos se establecerá en "-1". Y en consecuencia, el primer pedido nunca se abrirá.
¿Qué se puede hacer en esta situación? ¿O he entendido algo mal?
Bueno, eso es lo que yo haría:
int BarCloseLastPos(string symbol_name, ENUM_TIMEFRAMES timeframe, int type, int magic_number) {
datetime time=0;
int j=-1;
for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {
if(OrderMagicNumber()!=magic_number) continue;
if(OrderSymbol()!=symbol_name) continue;
if(OrderType()!=type) continue;
if(OrderCloseTime()>time) {
time=OrderCloseTime();
j=i;
}
}
}
if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)) return(iBarShift(symbol_name,timeframe,time));
return(EMPTY);
}
//+------------------------------------------------------------------+
... y comprueba:
// Последняя позиция Buy была закрыта не на текущем баре
}
Bueno, eso es lo que yo haría:
int BarCloseLastPos(string symbol_name, ENUM_TIMEFRAMES timeframe, int type, int magic_number) {
datetime time=0;
int j=-1;
for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {
if(OrderMagicNumber()!=magic_number) continue;
if(OrderSymbol()!=symbol_name) continue;
if(OrderType()!=type) continue;
if(OrderCloseTime()>time) {
time=OrderCloseTime();
j=i;
}
}
}
if(OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)) return(iBarShift(symbol_name,timeframe,time));
return(EMPTY);
}
//+------------------------------------------------------------------+
... y comprueba:
// Последняя позиция Buy была закрыта не на текущем баре
}
¿Y si se cerrara sigilosamente en la barra actual?
Esto es exactamente lo que hay que echar de menos. No necesita abrir una posición si la anterior se cerró en esta barra - en cero.
Y si necesitamos comprobar la condición de que la posición se cerró en la barra actual, tenemos que comprobar el cero:
// Последняя позиция Buy была закрыта на текущем баре
}
Aquí es donde me he complicado un poco: he tomado este código (gracias a Alekseu Fedotov):
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 19.02.2008 |
//| Описание : Возвращает номер бара закрытия последней позиции или -1. |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| sy - наименование инструмента ("" или NULL - текущий символ) |
//| tf - таймфрейм ( 0 - текущий таймфрейм) |
//| op - операция ( -1 - любая позиция) |
//| mn - MagicNumber ( -1 - любой магик) |
//+----------------------------------------------------------------------------+
int NumberOfBarCloseLastPos(string sy="0", int tf=0, int op=-1, int mn=-1) {
datetime t;
int i, k=OrdersHistoryTotal();
if (sy=="" || sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if (OrderSymbol()==sy) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (t<OrderCloseTime()) t=OrderCloseTime();
}
}
}
}
}
}
return(iBarShift(sy, tf, t, True));
}
Y ahora pongo la cuenta:
Y aquí está el problema, porque inicialmente NumberOfBarCloseLastPos se establecerá en "-1". Y en consecuencia, el primer pedido nunca se abrirá.
¿Qué podemos hacer en esta situación? ¿O he entendido algo mal?