Cualquier pregunta de novato, para no saturar el foro. Profesionales, no pasen de largo. En ninguna parte sin ti - 6. - página 1093
Está perdiendo oportunidades comerciales:
- Aplicaciones de trading gratuitas
- 8 000+ señales para copiar
- Noticias económicas para analizar los mercados financieros
Registro
Entrada
Usted acepta la política del sitio web y las condiciones de uso
Si no tiene cuenta de usuario, regístrese
A continuación, hay un código de error en el registro del probador y se puede utilizar para una investigación posterior.
No hay error. Sólo se cuelga al entrar en el procedimiento. Y también está StartSell, entra en él normalmente. Esto es un lío.
He actualizado las comillas y funciona. No es correcto por algunos agujeros, pero al menos no cuelga.
Saludos, ¿podrían decirme cuál es la mejor manera de evitar la apertura simultánea de más de un número determinado de series para diferentes instrumentos (el bot está conectado a varios gráficos de diferentes instrumentos al mismo tiempo) en opciones binarias?
extern double Lotes = 1; // Lotes
extern int Exp = 1; // Caducidad
extern int Wait = 0; // Número de velas de una dirección
extern int Timeout = 1; // Espacio de tiempo
extern double Multiplier = 3; // Multiplicador
extern int int Deslizamiento = 5; // Deslizamiento
extern int MaxOpenOrders = 1; // Número máximo de órdenes abiertas simultáneamente
extern int Magia = 774274; // Magia
int ticket, Tipo;
Precio doble, lote;
//+------------------------------------------------------------------+
//| Función de inicialización de expertos |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEED);
}
//+------------------------------------------------------------------+
//| Función de desinicialización experta |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| función de tic experto |
//+------------------------------------------------------------------+
void OnTick()
{
// --------------- Operaciones abiertas ---------------
if (CountTrades() == 0) // El número de órdenes debe ser igual a cero
{
if ((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))
// Si la última operación es perdedora, se abre la misma, pero con un lote mayor
{
Tipo = TypeLastHistOrder();
if (Type == OP_BUY) Precio = Ask;
if (Type == OP_SELL) Precio = Oferta;
Lote = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0)
// si el beneficio de la última operación es igual a cero, se abrirá la misma operación
{
Tipo = TypeLastHistOrder();
if (Type == OP_BUY) Precio = Ask;
if (Type == OP_SELL) Precio = Oferta;
Lot = NormalizeDouble(LotsLastHistOrder(), 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) > PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) < PriceOpenLastHistOrder(OP_SELL))
|| CountHistTrades() == 0)// Si la última operación es rentable, se abre la orden
{
if (SignalBuy() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (SignalSell() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
}
}
}
//+------------------------------------------------------------------+
int CountTrades(int type = -1)
{
int cnt = 0;
for (int i=TotalPedidos()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
cnt++;
}
}
return(cnt);
}
//+------------------------------------------------------------------+
int CountHistTrades(int type = -1)
{
int cnt = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
cnt++;
}
}
return(cnt);
}
//+------------------------------------------------------------------+
bool SeñalCompra()
{
for (int i=1; i<=Wait; i++)
{
if (Close[i] > Open[i]) return(false)
}
if ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))
&& CountHistTrades() > 0) return(true);
si (CountHistTrades() == 0) return(true);
return(false);
}
//+------------------------------------------------------------------+
bool SeñalVenta()
{
for (int i=1; i<=Wait; i++)
{
if (Close[i] < Open[i]) return(false)
}
if ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))
&& CountHistTrades() > 0) return(true);
si (CountHistTrades() == 0) return(true);
return(false);
}
//+------------------------------------------------------------------+
datetime TimeLastHistOrder(int type = -1)
{
datetime lasttime = 0;
datetime opentime = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
si (OrderCloseTime() > lasttime)
{
lasttime = OrderCloseTime();
opentime = OrderOpenTime();
}
}
}
}
return(opentime);
}
//+------------------------------------------------------------------+
int TipoÚltimoHistOrden()
{
datetime tiempo = 0;
int tipo = -1;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
si (OrderCloseTime() > tiempo)
{
hora = OrderCloseTime();
tipo = OrderType();
}
}
}
}
devolver(tipo);
}
//+------------------------------------------------------------------+
double LotsLastHistOrder(int type = -1)
{
datetime tiempo = 0;
lotes dobles = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
si (OrderOpenTime() > tiempo)
{
tiempo = OrderOpenTime();
tiempo = OrderLots();
}
}
}
}
return(lots);
}
//+------------------------------------------------------------------+
double PrecioCierreÚltimaHistoria(int tipo = -1)
{
datetime tiempo = 0;
precio doble = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
si (OrderCloseTime() > tiempo)
{
hora = OrderCloseTime();
precio = OrderClosePrice();
}
}
}
}
}
}
//+------------------------------------------------------------------+
double PriceOpenLastHistOrder(int type = -1)
{
datetime tiempo = 0;
precio doble = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
si (OrderCloseTime() > tiempo)
{
hora = OrderCloseTime();
precio = OrderOpenPrice();
}
}
}
}
}
}
//+------------------------------------------------------------------+
Basta con eliminar la condición OrderSymbol() == Symbol() de la función CountTrades y añadir OrderType() == OP_BUY || OrderType() == OP_SELL, ¿no?
Y cambiar la condición si (SignalBuy() && CountTrades() < MaxOpenOrders) en OnTick antes de OrderSend... Lo mismo para vender.if (OrderMagicNumber() == Magic && (OrderType() == OrderType() == OP_BUY || OrderType() == OP_SELL))
¿Lo he cambiado correctamente?
Saludos, ¿podrían decirme cuál es la mejor manera de evitar la apertura simultánea de más de un número determinado de series para diferentes instrumentos (el bot está conectado a varios gráficos de diferentes instrumentos al mismo tiempo) en opciones binarias?
extern double Lotes = 1; // Lotes
extern int Exp = 1; // Caducidad
extern int Wait = 0; // Número de velas de una dirección
extern int Timeout = 1; // Espacio de tiempo
extern double Multiplier = 3; // Multiplicador
extern int int Deslizamiento = 5; // Deslizamiento
extern int MaxOpenOrders = 1; // Número máximo de órdenes abiertas simultáneamente
extern int Magia = 774274; // Magia
int ticket, Tipo;
Precio doble, lote;
//+------------------------------------------------------------------+
//| Función de inicialización de expertos |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEED);
}
//+------------------------------------------------------------------+
//| Función de desinicialización experta |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| función de tic experto |
//+------------------------------------------------------------------+
void OnTick()
{
// --------------- Operaciones abiertas ---------------
if (CountTrades() == 0) // El número de órdenes debe ser igual a cero
{
if ((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))
// Si la última operación es perdedora, se abre la misma, pero con un lote mayor
{
Tipo = TypeLastHistOrder();
if (Type == OP_BUY) Precio = Ask;
if (Type == OP_SELL) Precio = Oferta;
Lote = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0)
// si el beneficio de la última operación es igual a cero, se abrirá la misma operación
{
Tipo = TypeLastHistOrder();
if (Type == OP_BUY) Precio = Ask;
if (Type == OP_SELL) Precio = Oferta;
Lot = NormalizeDouble(LotsLastHistOrder(), 2);
ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) > PriceOpenLastHistOrder(OP_BUY))
|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) < PriceOpenLastHistOrder(OP_SELL))
|| CountHistTrades() == 0)// Si la última operación es rentable, se abre la orden
{
if (SignalBuy() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
if (SignalSell() && MaxOpenOrders > OrdersTotal())
{
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);
}
}
}
}
//+------------------------------------------------------------------+
int CountTrades(int type = -1)
{
int cnt = 0;
for (int i=TotalPedidos()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
cnt++;
}
}
return(cnt);
}
//+------------------------------------------------------------------+
int CountHistTrades(int type = -1)
{
int cnt = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
cnt++;
}
}
return(cnt);
}
//+------------------------------------------------------------------+
bool SeñalCompra()
{
for (int i=1; i<=Wait; i++)
{
if (Close[i] > Open[i]) return(false)
}
if ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))
&& CountHistTrades() > 0) return(true);
si (CountHistTrades() == 0) return(true);
return(false);
}
//+------------------------------------------------------------------+
bool SeñalVenta()
{
for (int i=1; i<=Wait; i++)
{
if (Close[i] < Open[i]) return(false)
}
if ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))
&& CountHistTrades() > 0) return(true);
si (CountHistTrades() == 0) return(true);
return(false);
}
//+------------------------------------------------------------------+
datetime TimeLastHistOrder(int type = -1)
{
datetime lasttime = 0;
datetime opentime = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
si (OrderCloseTime() > lasttime)
{
lasttime = OrderCloseTime();
opentime = OrderOpenTime();
}
}
}
}
return(opentime);
}
//+------------------------------------------------------------------+
int TipoÚltimoHistOrden()
{
datetime tiempo = 0;
int tipo = -1;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
si (OrderCloseTime() > tiempo)
{
hora = OrderCloseTime();
tipo = OrderType();
}
}
}
}
devolver(tipo);
}
//+------------------------------------------------------------------+
double LotsLastHistOrder(int type = -1)
{
datetime tiempo = 0;
lotes dobles = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
si (OrderOpenTime() > tiempo)
{
tiempo = OrderOpenTime();
tiempo = OrderLots();
}
}
}
}
return(lots);
}
//+------------------------------------------------------------------+
double PrecioCierreÚltimaHistoria(int tipo = -1)
{
datetime tiempo = 0;
precio doble = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
si (OrderCloseTime() > tiempo)
{
hora = OrderCloseTime();
precio = OrderClosePrice();
}
}
}
}
}
}
//+------------------------------------------------------------------+
double PriceOpenLastHistOrder(int type = -1)
{
datetime tiempo = 0;
precio doble = 0;
for (int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))
{
si (OrderCloseTime() > tiempo)
{
hora = OrderCloseTime();
precio = OrderOpenPrice();
}
}
}
}
}
}
//+------------------------------------------------------------------+
La hora puede establecerse directamente en formato datetime, sin necesidad de perder tiempo de máquina en la conversión, funciona así:
extern datetime StartTime = D'07:00';
En este formato de tiempo, cuando iniciamos el EA, obtenemos la fecha de compilación, mientras que queremos que la fecha de compilación sea hoy.
¿Cómo corregirlo?
Este formato de tiempo da la fecha de compilación del EA al iniciarlo, pero me gustaría tener la fecha de hoy.
¿Cómo solucionarlo?
El parámetro se cambia por el deseado al inicio, de la misma manera que los demás parámetros de usuario.
Y por alguna razón me muestra la fecha actual en el momento de ejecutar el script.
Por favor, dígame, ¿cuál es el propósito de usar MagicNumber, lo que da en esta estrategia? En mi opinión, también se pueden eliminar las funciones OnInit OnDeinit aquí