Cualquier pregunta de novato, para no saturar el foro. Profesionales, no pasen de largo. En ninguna parte sin ti - 6. - página 1095

 
alvlaf:
¿Este código está escrito en MQL5?

for (int i=0; i<SymbolCount; i++)

{

if (CountTrades() == 0) // El número de órdenes debe ser cero

{

if (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY)) ||

(TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))&& MaxOpenOrders > OrdersTotal())

// Si la última operación es perdedora, se abrirá la misma operación, pero con un lote mayor

{

Tipo = TypeLastHistOrder();

if (Type == OP_BUY) Precio = LastAsk;

if (Type == OP_SELL) Precio = LastBid;

Lote = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);

ticket = OrderSend(Symbols[i], Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0 && MaxOpenOrders > OrdersTotal())

// 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 = LastAsk;

if (Type == OP_SELL) Precio = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder(), 2);

ticket = OrderSend(Symbols[i], 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(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

if (SignalSell(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

}

}

}

Código en OnTick después de las palabras y así sucesivamente. Escrito en MQL4, ¿necesita MQL5?

Para cada OrderSend, la condición MaxOpenOrders no debe ser mayor que OrdersTotal().

Código del procedimiento (eliminado OrderSymbol()==Symbol() e introducido iClose()/iOpen() en lugar de Close/Open), no he comprobado la corrección del código:

//+------------------------------------------------------------------+

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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

cnt++;

}

}

return(cnt);

}

//+------------------------------------------------------------------+

bool SeñalCompra(cadena Sym)

{

for (int i=1; i<=Wait; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Especifique aquí el plazo requerido

double O = iOpen(Sym, PERIOD_M5, i);

si(C > O) return(false);

}

if ((iBarShift(Sym, 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

si (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

bool SeñalVenta(cadena Sym)

{

for (int i=1; i<=Wait; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Especifique aquí el plazo requerido

double O = iOpen(Sym, PERIOD_M5, i);

si(C < O) return(false);

}

if ((iBarShift(Sym, 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 (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 (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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

si (OrderCloseTime() > tiempo)

{

hora = OrderCloseTime();

precio = OrderClosePrice();

}

}

}

}

devolución(precio);

}

//+------------------------------------------------------------------+

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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

si (OrderCloseTime() > tiempo)

{

hora = OrderCloseTime();

precio = OrderOpenPrice();

}

}

}

}

devolución(precio);

}

 
alvlaf:

extern int Exp = 1;

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);

¿Te funciona este código? La fecha debe estar aquí, y ser mayor que la fecha actual en 10 minutos (es decir, TimeCurrent() + 600 mínimo).

 
A13ksandr:

for (int i=0; i<SymbolCount; i++)

{

if (CountTrades() == 0) // El número de órdenes debe ser cero

{

if (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY)) ||

(TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))&& MaxOpenOrders > OrdersTotal())

// Si la última operación es perdedora, se abrirá la misma operación, pero con un lote mayor

{

Tipo = TypeLastHistOrder();

if (Type == OP_BUY) Precio = LastAsk;

if (Type == OP_SELL) Precio = LastBid;

Lote = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);

ticket = OrderSend(Symbols[i], Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0 && MaxOpenOrders > OrdersTotal())

// 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 = LastAsk;

if (Type == OP_SELL) Precio = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder(), 2);

ticket = OrderSend(Symbols[i], 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(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

if (SignalSell(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

}

}

}

Código en OnTick después de las palabras y así sucesivamente. Escrito en MQL4, ¿necesita MQL5?

Para cada OrderSend, la condición MaxOpenOrders no debe ser mayor que OrdersTotal().

Código del procedimiento (eliminado OrderSymbol()==Symbol() e introducido iClose()/iOpen() en lugar de Close/Open), no he comprobado la corrección del código:

//+------------------------------------------------------------------+

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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

cnt++;

}

}

return(cnt);

}

//+------------------------------------------------------------------+

bool SeñalCompra(cadena Sym)

{

for (int i=1; i<=Wait; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Especifique aquí el plazo requerido

double O = iOpen(Sym, PERIOD_M5, i);

si(C > O) return(false);

}

if ((iBarShift(Sym, 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

si (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

bool SeñalVenta(cadena Sym)

{

for (int i=1; i<=Wait; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Especifique aquí el plazo requerido

double O = iOpen(Sym, PERIOD_M5, i);

si(C < O) return(false);

}

if ((iBarShift(Sym, 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 (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 (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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

si (OrderCloseTime() > tiempo)

{

hora = OrderCloseTime();

precio = OrderClosePrice();

}

}

}

}

devolución(precio);

}

//+------------------------------------------------------------------+

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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

si (OrderCloseTime() > tiempo)

{

hora = OrderCloseTime();

precio = OrderOpenPrice();

}

}

}

}

devolución(precio);

}

Da un par de errores, no se pudo arreglar. ¿Qué pasa aquí?

//+------------------------------------------------------------------+
//|| BB1.mq4 ||
//| Copyright 2016, MetaQuotes Software Corp.
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp.
#enlace de propiedad "https://www.mql5.com"
#versión de la propiedad "1.00"
#propiedad estricta

extern double Lotes = 1; // Lotes
extern int Exp = 1; // Expiración
extern int Wait = 2; // Número de velas de una dirección
extern int Timeout = 1; // Espacio de tiempo
extern double Multiplier = 3; // Multiplicador
extern int Deslizamiento = 5; // Deslizamiento
extern int Magia = 774274; // Magia
extern int MaxOpenOrders = 1; // Número máximo de pedidos

int ticket, Type, SymbolCount;
Precio doble, lote;

input string TradeSymbols = "EURUSD_OP, GBPUSD_OP, AUDUSD_OP, NZDUSD_OP, USDCAD_OP, USDCHF_OP, GBPCAD_OP, AUDNZD_OP, CHFJPY_OP, GBPCHF_OP"; // símbolos para operar

string Symbols[50]; // 50 es el número máximo posible de símbolos


//--------------------------------------------------

int OnInit()

{

if (IsTesting() || !ExtractSymbols())

{

SymbolCount = 1;

Símbolos[0] = Símbolo();

}

return(INIT_SUCCEED);

}

//--------------------------------------------------

bool ExtraerSímbolos()

{

ushort Comma = StringGetCharacter(",", 0);

SymbolCount = StringSplit(TradeSymbols, Comma, Symbols);

for (int i = 0; i < SymbolCount; i++)

{

StringToUpper(Símbolos[i]);

Symbols[i] = StringTrimRight(Symbols[i]); // protección contra espacios accidentales

Símbolos[i] = StringTrimLeft(Símbolos[i]);

}

si (SymbolCount > 0) return(true);

return(false);

}

//--------------------------------------------------

void OnTick()

{

for (int i=0; i<SymbolCount; i++)

{

if (CountTrades() == 0) // El número de órdenes debe ser cero

{

if (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY)) ||

(TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL)) && MaxOpenOrders > OrdersTotal())

// Si la última operación es perdedora, se abrirá la misma operación, pero con un lote mayor

{

Tipo = TypeLastHistOrder();

if (Type == OP_BUY) Precio = LastAsk;

if (Type == OP_SELL) Precio = LastBid;

Lote = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);

ticket = OrderSend(Symbols[i], Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0 && MaxOpenOrders > OrdersTotal())

// 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 = LastAsk;

if (Type == OP_SELL) Precio = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder(), 2);

ticket = OrderSend(Symbols[i], 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, abrir orden

{

if (SignalBuy(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

if (SignalSell(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], 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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

cnt++;

}

}

return(cnt);

}

//+------------------------------------------------------------------+

bool SeñalCompra(cadena Sym)

{

for (int i=1; i<=Wait; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Especifique aquí el plazo requerido

double O = iOpen(Sym, PERIOD_M5, i);

si (C > O) return(false);

}

if ((iBarShift(Sym, 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

si (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

bool SeñalVenta(cadena Sym)

{

for (int i=1; i<=Wait; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Especifique aquí el plazo requerido

double O = iOpen(Sym, PERIOD_M5, i);

si (C < O) return(false);

}

if ((iBarShift(Sym, 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 (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 (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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

si (OrderCloseTime() > tiempo)

{

hora = OrderCloseTime();

precio = OrderClosePrice();

}

}

}

}

devolución(precio);

}

//+------------------------------------------------------------------+

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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

si (OrderCloseTime() > tiempo)

{

hora = OrderCloseTime();

precio = OrderOpenPrice();

}

}

}

}

devolución(precio);

}

 
Chicos, ayuda. Estoy operando en la plataforma MT4 de Stforex. Cuando abro órdenes, no muestra el nivel de entrada en el gráfico (no hay línea de puntos), y por lo tanto no es conveniente poner un stop-loss. ¿Quizás alguien sepa qué es lo que falla y cómo solucionarlo?
 
gloomy159:
Chicos, ayuda. Estoy operando en la plataforma MT4 de Stforex. Cuando abro una orden, no me muestra el nivel de entrada en el gráfico (no hay línea de puntos), y por lo tanto no es conveniente poner un stop-loss. ¿Quizás quién sabe qué es lo que falla y cómo solucionarlo?

http://prntscr.com/chfa36

Ajustes - Gráficos - Mostrar niveles de negociación

 

Chicos, ¿qué función podría devolver el error 65?

ERR_INVALID_ACCOUNT65 Número de cuenta incorrecto
 
testerMT4:

http://prntscr.com/chfa36

Ajustes - Gráficos - Mostrar niveles de negociación

Esta función se activó inicialmente, pero sigue sin mostrar los niveles en el gráfico
 
gloomy159:
Esta función estaba originalmente activada, pero los niveles siguen sin aparecer en el gráfico
En los ajustes de color, compruebe si el color está asignado a los volúmenes y no coincide con el color de fondo.
 
alvlaf:

Da un par de errores, no se puede arreglar. ¿Qué pasa aquí?


Has olvidado añadir un paréntesis de cierre en las variables OnTick y LastAsk y LastBid. Aquí hay un código que compila sin errores, no he comprobado su funcionalidad:

//+------------------------------------------------------------------+

//|| BB1.mq4 ||

//| Copyright 2016, MetaQuotes Software Corp.

//| https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2016, MetaQuotes Software Corp."

#enlace de propiedad "https://www.mql5.com"

#versión de la propiedad "1.00"

#propiedad estricta


extern double Lotes = 1; // Lotes

extern int Exp = 1; // Expiración

extern int Wait = 2; // Número de velas de una dirección

extern int Timeout = 1; // Espacio de tiempo

extern double Multiplier = 3; // Multiplicador

extern int Deslizamiento = 5; // Deslizamiento

extern int Magia = 774274; // Magia

extern int MaxOpenOrders = 1; // Número máximo de pedidos


int ticket, Type, SymbolCount;

Precio doble, lote;

input string TradeSymbols = "EURUSD_OP, GBPUSD_OP, AUDUSD_OP, NZDUSD_OP, USDCAD_OP, USDCHF_OP, GBPCAD_OP, AUDNZD_OP, CHFJPY_OP, GBPCHF_OP"; // símbolos para operar

string Symbols[50]; // 50 es el número máximo posible de símbolos

//--------------------------------------------------

int OnInit()

{

if (IsTesting() || !ExtractSymbols())

{

SymbolCount = 1;

Símbolos[0] = Símbolo();

}

return(INIT_SUCCEED);

}

//--------------------------------------------------

bool ExtraerSímbolos()

{

ushort Comma = StringGetCharacter(",", 0);

SymbolCount = StringSplit(TradeSymbols, Comma, Symbols);

for (int i = 0; i < SymbolCount; i++)

{

StringToUpper(Símbolos[i]);

Symbols[i] = StringTrimRight(Symbols[i]); // protección contra espacios accidentales

Símbolos[i] = StringTrimLeft(Símbolos[i]);

}

si (SymbolCount > 0) return(true);

return(false);

}

//--------------------------------------------------

void OnTick()

{

for (int i=0; i<SymbolCount; i++)

{

double LastAsk = SymbolInfoDouble(Symbols[i], SYMBOL_ASK);

double LastBid = SymbolInfoDouble(Symbols[i], SYMBOL_BID);

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)) && MaxOpenOrders > OrdersTotal())

// Si la última operación es perdedora, se abrirá la misma operación, pero con un lote mayor

{

Tipo = TypeLastHistOrder();

if (Type == OP_BUY) Precio = LastAsk;

if (Type == OP_SELL) Precio = LastBid;

Lote = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);

ticket = OrderSend(Symbols[i], Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0 && MaxOpenOrders > OrdersTotal())

// 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 = LastAsk;

if (Type == OP_SELL) Precio = LastBid;

Lot = NormalizeDouble(LotsLastHistOrder(), 2);

ticket = OrderSend(Symbols[i], 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(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic)

}

if (SignalSell(Symbols[i]) && MaxOpenOrders > OrdersTotal())

{

ticket = OrderSend(Symbols[i], 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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

cnt++;

}

}

return(cnt);

}

//+------------------------------------------------------------------+

bool SeñalCompra(cadena Sym)

{

for (int i=1; i<=Wait; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Especifique aquí el plazo requerido

double O = iOpen(Sym, PERIOD_M5, i);

si (C > O) return(false);

}

if ((iBarShift(Sym, 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

si (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

bool SeñalVenta(cadena Sym)

{

for (int i=1; i<=Wait; i++)

{

double C = iClose(Sym, PERIOD_M5, i); // Especifique aquí el plazo requerido

double O = iOpen(Sym, PERIOD_M5, i);

si (C < O) return(false);

}

if ((iBarShift(Sym, 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 (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 (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 (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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

si (OrderCloseTime() > tiempo)

{

hora = OrderCloseTime();

precio = OrderClosePrice();

}

}

}

}

devolución(precio);

}

//+------------------------------------------------------------------+

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 (OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

si (OrderCloseTime() > tiempo)

{

hora = OrderCloseTime();

precio = OrderOpenPrice();

}

}

}

}

devolución(precio);

}

 

¡Hola!

¿Cómo se puede determinar si una posición se ha cerrado en TP? No creo que OrderClosePrice()==OrderTakeProfit() sea correcto de usar.