Para que quede todo más ordenado voy a ir poniendo en este hilo todos los scripts y en el otro para debatir e ir poniendo ideas y sugerencias.
- Cerrar todo.
- Buy.
- Sell.
- Ajustar decimales.
- Enviar correo electrónico.
Versión para imprimir
Para que quede todo más ordenado voy a ir poniendo en este hilo todos los scripts y en el otro para debatir e ir poniendo ideas y sugerencias.
- Cerrar todo.
- Buy.
- Sell.
- Ajustar decimales.
- Enviar correo electrónico.
Código://+------------------------------------------------------------------+
//| Cerrar_todo.mq4 |
//+------------------------------------------------------------------+
#property copyright "Elverge"
#property version "1.00"
extern int num_magic = 0; // SI TENEMOS MAS DE UN ROBOT, HAY QUE CAMBIAR EL NUMERO MÁGICO
extern bool Tancar = false; // CUANDO QUERAMOS CERRAR LAS POSICIONES SE CAMBIA POR VERDADERO
int start()
{
if (Tancar == true)
{
Tancar();
return (0);
}
}
int Tancar()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
if ( OrderMagicNumber() == num_magic)
{
int type = OrderType();
bool result = false;
switch(type)
{
//CIERRA COMPRAS
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 0, CLR_NONE );
break;
//CIERRA VENTAS
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 0, CLR_NONE );
break;
//CIERRA ORDENES PENDIENTES
case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT :
case OP_SELLSTOP : result = OrderDelete( OrderTicket() );
}
if(result == false)
{
Alert("Order " , OrderTicket() , " fallo al cerrar. Error:" , GetLastError() );
Sleep(3000);
}
}
}
return(0);
}
Código://+------------------------------------------------------------------+
//| Buy.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern double Lotes = 0.1;
extern int TP = 50;
extern int SL = 200;
int ticket = 0;
int exi_buy = 0;
int start()
{
double preu_SL;
double preu_TP;
// COMPRA
if (exi_buy == 0)
{
preu_SL = (Bid - SL * Point);
if (SL <= 0) preu_SL = 0;
preu_TP = Ask + TP * Point;
ticket=OrderSend(Symbol(),OP_BUY,Lotes,Ask,0,0,0,"COMPRA",0,0,CLR_NONE);
exi_buy = 1;
//MODIFICAMOS SL Y TP
if(ticket>0)
{
OrderSelect(ticket,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),preu_SL,preu_TP,0,CLR_NONE);
}
}
return(0);
}
Código://+------------------------------------------------------------------+
//| Sell.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
extern double Lotes = 0.1;
extern int TP = 50;
extern int SL = 200;
int ticket = 0;
int exi_sell = 0;
int start()
{
double preu_SL;
double preu_TP;
// VENTA
if (exi_sell == 0)
{
preu_SL = Bid + SL * Point;
if (SL <= 0) preu_SL = 0;
preu_TP = Bid - TP * Point;
ticket = OrderSend(Symbol(), OP_SELL,Lotes,Bid,0,0,0,"VENTA",0, 0, CLR_NONE);
exi_sell = 1;
//MODIFICAMOS SL Y TP
if(ticket>0)
{
OrderSelect(ticket,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),preu_SL,preu_TP,0,CLR_NONE);
}
}
return(0);
}
Código://+------------------------------------------------------------------+
//| AJUSTAR DECIMALES.mq4 |
//| Elverge |
//| |
//+------------------------------------------------------------------+
#property copyright "Elverge"
#property link ""
#property version "1.00"
#property strict
double volumen = 0.0;
string valorlote;
int TP= 0;
int SL= 0;
extern int num_magic = 1;
extern double Lotes = 0.1;
extern int tp = 50;
extern int sl = 200;
int init()
{
volumen = Lotes;
valorlote = DoubleToStr (volumen, 2);
if (Digits == 3)
{
TP = 10.0 * tp;
SL = 10.0 * sl;
}
else
{
if (Digits == 5)
{
TP = 10.0 * tp;
SL = 10.0 * sl;
}
else
{
TP = tp;
SL = sl;
}
}
return (0);
}
Código://+------------------------------------------------------------------+
//| AVISO PÉRDIDAS.mq4 |
//| Elverge |
//| |
//+------------------------------------------------------------------+
#property copyright " "
#property link " "
#property version "1.00"
double orden_abierta= 0.0;
int perdidas = 0;
extern int Perdidas = 50;
int OnInit()
{
orden_abierta = (AccountBalance() - AccountEquity());
if (ordren_abierta >= Perdidas)
{
perdidas = AccountProfit ();
if (NovaBarra())SendMail( " PERDIDAS ALTAS ", " en la cuenta : " +AccountNumber() +Symbol() +" hay unas perdidas de aproximadamente " + perdidas + " euros");
}
return(INIT_SUCCEEDED);
}
bool NovaBarra()
{
static datetime ti = 0;
if (ti != Time[0])
{
ti = Time[0]; Sleep(100);
return(true);
}
return(false);
}