Ayuda en EA - El TP Y SL No cuando lo pongo en 50 se va a 500 pips y cuando es menos de 50 no coloca los límites
Por favor necesito ayuda con este EA:
extern int MagicNumber=10001;
extern double Lots =1;
extern int StopLoss=50;
extern int TakeProfit=50;
extern int TrailingStep=10;
extern int breakeven=15;
extern int TrailingStop=50;
extern int Slippage=3;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
int TheStopLoss=0;
int TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
if((iCCI(NULL,0,5,PRICE_OPEN,0)>0)&&(iRSI(NULL,0,3,PRICE_OPEN,0)>50)&&(iMACD(NULL,0,2,5,2,PRICE_OPEN,MODE_MAIN,0)>0)) // Acá Abra una Operación de compra
{
result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator 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((iCCI(NULL,0,3,PRICE_OPEN,0)<0)&&(iRSI(NULL,0,3,PRICE_OPEN,0)<50)&&(iMACD(NULL,0,5,2,2,PRICE_OPEN,MODE_MAIN,0)<0)) // Acá abre una operación de venta
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator 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(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(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);
}
No es fácil que funcione un EA. Probablemente el problema esté en el nivel de stop (stop_level).
Trata de programar estructuradamente, a partir de funciones elementales como las de abajo. Con ellas no hacen falta, por ejemplo, las tres primeras lineas del EA (variable MyPoint)
//---------------------------------- NIVEL de STOP (STOP-LEVEL) -------------------------------------------- int stopLevel(string simb= NULL) { int SLevel= (int)SymbolInfoInteger(simb, SYMBOL_TRADE_STOPS_LEVEL); return (SLevel); //Margen mínimo en puntos del actual precio de cierre para colocación de Stop ordenes } //----------------------------------- VALOR DEL PUNTO en precio (Point())--------------------------------- double valorPunto(string simb= NULL) { //valor de un punto en precio; en EURUSD 0.00001 double resp= SymbolInfoDouble(simb, SYMBOL_POINT); return(resp); } //--------------------------------- DÍGITOS DEL SÍMBOLO --------------------------------------- int digitosSimb(string simb= NULL) { //numero de decimales que usa el broker en el precio int numDig= (int)SymbolInfoInteger(simb, SYMBOL_DIGITS); return(numDig); }
![MQL5 - Lenguaje de estrategias comerciales para el terminal de cliente MetaTrader 5](https://c.mql5.com/i/registerlandings/logo-2.png)
- Aplicaciones de trading gratuitas
- 8 000+ señales para copiar
- Noticias económicas para analizar los mercados financieros
Usted acepta la política del sitio web y las condiciones de uso
Por favor necesito ayuda con este EA:
extern int MagicNumber=10001;
extern double Lots =1;
extern int StopLoss=50;
extern int TakeProfit=50;
extern int TrailingStep=10;
extern int breakeven=15;
extern int TrailingStop=50;
extern int Slippage=3;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
int TheStopLoss=0;
int TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
if((iCCI(NULL,0,5,PRICE_OPEN,0)>0)&&(iRSI(NULL,0,3,PRICE_OPEN,0)>50)&&(iMACD(NULL,0,2,5,2,PRICE_OPEN,MODE_MAIN,0)>0)) // Acá Abra una Operación de compra
{
result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator 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((iCCI(NULL,0,3,PRICE_OPEN,0)<0)&&(iRSI(NULL,0,3,PRICE_OPEN,0)<50)&&(iMACD(NULL,0,5,2,2,PRICE_OPEN,MODE_MAIN,0)<0)) // Acá abre una operación de venta
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator 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(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(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);
}