forexeadvisor cierre velas

Foro para cuestiones generales sobre la plataforma MetaTrader 4.

forexeadvisor cierre velas

Notapor piscinausu » 31 Ago 2016, 17:46

buenos días, como mis conocimientos de pogramacion son muy limitados, asi que he tenido que recurrir a forexeadvidor para crear una ea, y lo domino bastante bien, pero en este punto no he podido lograrlo, me explico tengo una operación abierta con un condicionante de cierre , hasta aquí todo bien , pero intento colocarle otro condicinate , que es que si el primer condicionante no se cumple la operación se cierre al finalizar la vela que esta operando en este momento, no se si alguien domina el tema y me puede ayudar
muchas gracias de antemano
piscinausu
 
Mensajes: 14
Registrado: 12 Jul 2013, 19:14
Karma: 0

Re: forexeadvisor cierre velas

Notapor Duracell » 31 Ago 2016, 23:59

Quizás sería mejor en el hilo de metatrader, si pasas el código, o solo esa parte en particular se puede mirar.
Continous learning... always long @ smoke xd

La Gran Carrera xd
Imagen
Avatar de Usuario
Duracell
 
Mensajes: 524
Registrado: 02 Nov 2013, 13:21
Karma: 10

Re: forexeadvisor cierre velas

Notapor FXWizard » 01 Sep 2016, 12:17

Lo muevo aquí, más apropiado.

Piscinausu, ¿puedes subir algo de código para que podamos verlo entre todos? Gracias.

Saludos,
FXWizard
Avatar de Usuario
FXWizard
 
Mensajes: 8493
Registrado: 12 Feb 2008, 15:17
Karma: 35

Re: forexeadvisor cierre velas

Notapor piscinausu » 01 Sep 2016, 12:21

Gracias por el interés .Como he comentado mis conocimientos de pogramar son nulos , os paso este código sencillo generado con forexeadvisor, a ver si es posible que la operación de compra o venta se cierre al finalizar la vela, si no se cumple el condicionante.
muchas gracias


xtern int MagicNumber=10018;
extern double Lots =0.1;
extern double StopLoss=0;
extern double TakeProfit=0;
extern int TrailingStop=0;
extern int Slippage=3;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;

double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
if((Low[0]<iMA(NULL,0,2,0,MODE_EMA,PRICE_LOW,0))&&(High[0]<iMA(NULL,0,2,0,MODE_EMA,PRICE_HIGH,0))) // Here is your open buy rule
{
result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator http://www.ForexEAdvisor.com",MagicNumber,0,Blue);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
if((High[0]>iMA(NULL,0,2,0,MODE_EMA,PRICE_HIGH,0))&&(Low[0]>iMA(NULL,0,2,0,MODE_EMA,PRICE_LOW,0))) // Here is your open Sell rule
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator http://www.ForexEAdvisor.com",MagicNumber,0,Red);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
}

for(int cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber
)
{
if(OrderType()==OP_BUY)
{
if((High[0]>iMA(NULL,0,2,0,MODE_EMA,PRICE_HIGH,0))) //here is your close buy rule
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
}
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if((Low[0]<iMA(NULL,0,2,0,MODE_EMA,PRICE_LOW,0))) // here is your close sell rule
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
}
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}

int TotalOrdersCount()
{
int result=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
if (OrderMagicNumber()==MagicNumber) result++;

}
return (result);
}
piscinausu
 
Mensajes: 14
Registrado: 12 Jul 2013, 19:14
Karma: 0

Re: forexeadvisor cierre velas

Notapor Duracell » 02 Sep 2016, 08:52

Es decir, quieres que si no cierra por el if((High[0]>iMa...., cierre al final de la vela actual?


Enviado desde mi iPhone con Tapatalk
Continous learning... always long @ smoke xd

La Gran Carrera xd
Imagen
Avatar de Usuario
Duracell
 
Mensajes: 524
Registrado: 02 Nov 2013, 13:21
Karma: 10

Re: forexeadvisor cierre velas

Notapor piscinausu » 02 Sep 2016, 11:43

Exacto, asi es muchas gracias
piscinausu
 
Mensajes: 14
Registrado: 12 Jul 2013, 19:14
Karma: 0

Re: forexeadvisor cierre velas

Notapor Xakalin » 02 Sep 2016, 12:43

xtern int MagicNumber=10018;
extern double Lots =0.1;
extern double StopLoss=0;
extern double TakeProfit=0;
extern int TrailingStop=0;
extern int Slippage=3;
double newBar;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;

double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
if((Low[0]<iMA(NULL,0,2,0,MODE_EMA,PRICE_LOW,0))&&(High[0]<iMA(NULL,0,2,0,MODE_EMA,PRICE_HIGH,0))) // Here is your open buy rule
{
result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator http://www.ForexEAdvisor.com",MagicNumber,0,Blue);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
if((High[0]>iMA(NULL,0,2,0,MODE_EMA,PRICE_HIGH,0))&&(Low[0]>iMA(NULL,0,2,0,MODE_EMA,PRICE_LOW,0))) // Here is your open Sell rule
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator http://www.ForexEAdvisor.com",MagicNumber,0,Red);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
}

for(int cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber
)
{
if(OrderType()==OP_BUY)
{
if((High[0]>iMA(NULL,0,2,0,MODE_EMA,PRICE_HIGH,0))) //here is your close buy rule
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
}else(if NewBar()){
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
}

if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if((Low[0]<iMA(NULL,0,2,0,MODE_EMA,PRICE_LOW,0))) // here is your close sell rule
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
}else(if NewBar()){
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
}

if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}

int TotalOrdersCount()
{
int result=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
if (OrderMagicNumber()==MagicNumber) result++;

}
return (result);
}

bool NewBar()
{
if (Time[0] != newBar){
newBar = Time[0];
return true;
}
return false;
}


Te explico lo que he hecho, porque no se si es lo que pides, he creado al final una funcion para ver si es una nueva vela, el comienzo de una, indica el cierre de la anterior, por lo que si es una nueva barra, se ha cerrado la anterior.
lo he puesto en los dos condicionantes del order close, if High y en el if Low, si no quieres alguno de ellos borra lo que está en negrita =)

espero que te valga, y si no comenta un poco más o se lo dejo a otra persona! :)
un saludo!

EDIT: no tengo para compilar y probar, espero que funcione sin errores :/
Imagen
Avatar de Usuario
Xakalin
 
Mensajes: 291
Registrado: 05 Jul 2016, 17:57
Karma: 4

Re: forexeadvisor cierre velas

Notapor Duracell » 02 Sep 2016, 14:16

Eso iba a hacer yo jeje


Enviado desde mi iPhone con Tapatalk
Continous learning... always long @ smoke xd

La Gran Carrera xd
Imagen
Avatar de Usuario
Duracell
 
Mensajes: 524
Registrado: 02 Nov 2013, 13:21
Karma: 10

Siguiente

Volver a MetaTrader 4

¿Quién está conectado?

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