ayuda con takeprofit y trailing stop en EA

Foro para cuestiones generales sobre la plataforma MetaTrader 4.

ayuda con takeprofit y trailing stop en EA

Notapor diegofe1246 » 16 Feb 2011, 00:05

Alguien me puede ayudar en colocarle takeprofit y trailing stop a este EA de cruce de medias moviles ?

//+------------------------------------------------------------------+
//| SimpleEMA.mq4 |
//| Programando Forex |
//| http://www.programandoforex.com |
//+------------------------------------------------------------------+
#property copyright "Programando Forex"
#property link "http://www.programandoforex.com"

extern int LargaEMA = 20;
extern int CortaEMA = 5;
extern int Size = 1;

int start()
{
static datetime MarcaTiempo = 0;
static int ticket;
int señal;
datetime NuevaTiempo = Time[0];

// A cada nueva barra
if(MarcaTiempo != NuevaTiempo)
{
// Tomamos datos de las dos EMAs (Corta y Larga).
double emaLargaA = iMA(NULL,0,LargaEMA,0,1,4,3);
double emaLargaB = iMA(NULL,0,LargaEMA,0,1,4,1);
double emaCortaA = iMA(NULL,0,CortaEMA,0,1,4,3);
double emaCortaB = iMA(NULL,0,CortaEMA,0,1,4,1);

// Calculamos si se han cruzado
if(emaCortaA < emaLargaA && emaCortaB > emaLargaB)
señal = 0; // ema corta cruza de abajo a arriba.
else if(emaCortaA > emaLargaA && emaCortaB < emaLargaB)
señal = 1; // ema corta cruza de arriba a abajo.
else
señal = -1; // no hay cruce.

// Si no hay órden abierta y hay señal podemos operar.
if(OrdersTotal() == 0 && señal != -1)
{
if(señal == 0) // Señal 0 -> COMPRA
ticket = OrderSend(Symbol(),OP_BUY,Size,Ask,3,0,0,NULL,23,0,Green);
else if(señal == 1) // Señal 1 -> VENTA
ticket = OrderSend(Symbol(),OP_SELL,Size,Bid,3,0,0,NULL,23,0,Green);
}

// Si hay una orden abierta y hay señal en contra cerramos
if(OrdersTotal() != 0 && señal != -1)
{
// Seleccionamos la orden.
OrderSelect(ticket,SELECT_BY_TICKET);
//Comprobamos si la señal es contraria
if(OrderType() == 0 && señal == 1)
OrderClose(ticket,Size,Bid,3,Yellow); // Cerramos la compra.
if(OrderType() == 1 && señal == 0)
OrderClose(ticket,Size,Ask,3,Yellow); // Cerramos la venta.
}

MarcaTiempo = NuevaTiempo;
}


return(0);
}
//+------------------------------------------------------------------+



gracias
diegofe1246
 
Mensajes: 5
Registrado: 17 Ene 2011, 04:12
Karma: 0

Re: ayuda con takeprofit y trailing stop en EA

Notapor Trader2010 » 16 Feb 2011, 21:49

Hola diegofe1246,
bueno el Take profit y el stop losss se configuran en esta linea

ticket = OrderSend(Symbol(),OP_BUY,Size,Ask,3,0,0,NULL,23,0,Green);
else if(señal == 1) // Señal 1 -> VENTA
ticket = OrderSend(Symbol(),OP_SELL,Size,Bid,3,0,0,NULL,23,0,Green);

ticket = OrderSend(Symbol(),OP_BUY,Size,Ask,3,------,------,NULL,23,0,Green);
else if(señal == 1) // Señal 1 -> VENTA
ticket = OrderSend(Symbol(),OP_SELL,Size,Bid,3,------,------,NULL,23,0,Green);

donde puse esas lineas punteadas.primero va el stop loss, luego va el Take profit.
debes saber unas cositas,
debes crear la variable antes, ejemplo:
extern double StopLoss = 50; // Cantidad de pips de perdida o riesgo.
extern double TakeProfit = 50; // Cantidad de Pip de ganancia.

luego meterlas dentro de esta linea.

saludos, espero haberte ayudado.
Trader2010
 
Mensajes: 317
Registrado: 17 Sep 2009, 15:26
Karma: 0


Volver a MetaTrader 4

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados