Publi
|
Aquí dejo el scrip de lo que estoy trabajando, no va mal pero necesita depuraciones; a ver donde debo meter los comandos indicados.
extern int MagicNumber=10033;
extern double Lots =0.2;
extern double StopLoss=25;
extern double TakeProfit=50;
extern int TrailingStop=1;
extern int InicioTrailing=5;
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((Ask>iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0))&&
(Bid<iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0))&&
(iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1)>iMA(NULL, 0,120,0,MODE_SMA,PRICE_CLOSE,1))&&
(Close[1]<iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1))||
(iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1)<iMA(NULL, 0,120,0,MODE_SMA,PRICE_CLOSE,1))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,0)>iMA(NULL,0, 120,0,MODE_SMA,PRICE_CLOSE,0))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,1)<iMA(NULL,0, 120,0,MODE_SMA,PRICE_CLOSE,1))&&
(iMACD(NULL,0,3,5,2,PRICE_CLOSE,MODE_MAIN,1)>0)&&
(Ask>iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,0))&&
(Bid<iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,0))||
(iRSI(NULL,0,11,PRICE_OPEN,1)<40)&&
(iRSI(NULL,0,11,PRICE_OPEN,0)>40)&&
(iRSI(NULL,0,11,PRICE_OPEN,1)>(iRSI(NULL,0,11,PRIC E_OPEN,2)))&&
(iRSI(NULL,0,11,PRICE_OPEN,0)>(iRSI(NULL,0,11,PRIC E_OPEN,1)))&&
(Ask>iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,0))&&
(Bid<iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,0))||
(iRSI(NULL,0,11,PRICE_OPEN,1)<30)&&
(iRSI(NULL,0,11,PRICE_OPEN,1)>(iRSI(NULL,0,11,PRIC E_OPEN,2)))&&
(iRSI(NULL,0,11,PRICE_OPEN,0)>(iRSI(NULL,0,11,PRIC E_OPEN,1)))||
(iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,0)>iMA(NULL,0, 50,0,MODE_EMA,PRICE_CLOSE,0))&&
(Ask>iMA(NULL,0,20,0,MODE_SMA,PRICE_HIGH,0))&&
(Bid<iMA(NULL,0,20,0,MODE_SMA,PRICE_HIGH,0))||
(iRSI(NULL,0,11,PRICE_OPEN,0)<50)&&
(iRSI(NULL,0,11,PRICE_OPEN,0)>(iRSI(NULL,0,11,PRIC E_OPEN,1)))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,0)>iMA(NULL,0, 20,0,MODE_EMA,PRICE_HIGH,0))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,0)>iMA(NULL,0, 5,0,MODE_EMA,PRICE_HIGH,1))||
(Close[3]<iMA(NULL,0,20,0,MODE_SMA,PRICE_HIGH,3))&&
(Close[2]<iMA(NULL,0,20,0,MODE_SMA,PRICE_HIGH,2))&&
(Close[1]>iMA(NULL,0,20,0,MODE_SMA,PRICE_HIGH,1))&&
(iRSI(NULL,0,11,PRICE_OPEN,0)>(iRSI(NULL,0,11,PRIC E_OPEN,1))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,0)>iMA(NULL,0, 5,0,MODE_SMA,PRICE_HIGH,1))))
// Here is your open buy rule
{
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(),Normali zeDouble(TheStopLoss,Digits),NormalizeDouble(TheTa keProfit,Digits),0,Green);
}
return(0);
}
if((Ask>iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0))&&
(Bid<iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0))&&
(iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1)<iMA(NULL, 0,120,0,MODE_SMA,PRICE_CLOSE,1))&&
(Close[1]>iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1))||
(iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1)>iMA(NULL, 0,120,0,MODE_SMA,PRICE_CLOSE,1))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_LOW,0)<iMA(NULL,0,1 20,0,MODE_SMA,PRICE_CLOSE,0))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_LOW,1)>iMA(NULL,0,1 20,0,MODE_SMA,PRICE_CLOSE,1))&&
(iMACD(NULL,0,3,5,2,PRICE_CLOSE,MODE_MAIN,1)<0)&&
(Ask>iMA(NULL,0,5,0,MODE_SMA,PRICE_LOW,0))&&
(Bid<iMA(NULL,0,5,0,MODE_SMA,PRICE_LOW,0))||
(iRSI(NULL,0,11,PRICE_OPEN,1)>60)&&
(iRSI(NULL,0,11,PRICE_OPEN,0)<60)&&
(iRSI(NULL,0,11,PRICE_OPEN,1)<(iRSI(NULL,0,11,PRIC E_OPEN,2)))&&
(iRSI(NULL,0,11,PRICE_OPEN,0)<(iRSI(NULL,0,11,PRIC E_OPEN,1)))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_LOW,0)<iMA(NULL,0,2 0,0,MODE_SMA,PRICE_HIGH,0))&&
(Ask>iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,0))&&
(Bid<iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,0))||
(iRSI(NULL,0,11,PRICE_OPEN,1)>70)&&
(iRSI(NULL,0,11,PRICE_OPEN,1)<(iRSI(NULL,0,11,PRIC E_OPEN,2)))&&
(iRSI(NULL,0,11,PRICE_OPEN,0)<(iRSI(NULL,0,11,PRIC E_OPEN,1)))||
(iMA(NULL,0,20,0,MODE_SMA,PRICE_HIGH,0)<iMA(NULL,0 ,50,0,MODE_EMA,PRICE_CLOSE,0))&&
(Ask>iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,0))&&
(Bid<iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,0))||
(iRSI(NULL,0,11,PRICE_OPEN,0)>50)&&
(iRSI(NULL,0,11,PRICE_OPEN,0)<(iRSI(NULL,0,11,PRIC E_OPEN,1)))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,0)<iMA(NULL,0, 20,0,MODE_EMA,PRICE_LOW,0))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,0)<iMA(NULL,0, 5,0,MODE_EMA,PRICE_HIGH,1))||
(Close[3]>iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,3))&&
(Close[2]>iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,2))&&
(Close[1]<iMA(NULL,0,20,0,MODE_SMA,PRICE_LOW,1))&&
(iRSI(NULL,0,11,PRICE_OPEN,0)<(iRSI(NULL,0,11,PRIC E_OPEN,1)))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,0)<iMA(NULL,0, 5,0,MODE_SMA,PRICE_HIGH,1)))
// Here is your open Sell rule
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippag e,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(),Normali zeDouble(TheStopLoss,Digits),NormalizeDouble(TheTa keProfit,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((iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1)<iMA(NU LL,0,50,0,MODE_SMA,PRICE_CLOSE,1))&&
(iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,2)>iMA(NULL, 0,50,0,MODE_SMA,PRICE_CLOSE,2))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_HIGH,1)<iMA(NULL,0, 120,0,MODE_SMA,PRICE_CLOSE,1)))
//here is your close buy rule
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),Slippage,Red);
}
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*InicioTrailing)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if((iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1)>iMA(NU LL,0,50,0,MODE_SMA,PRICE_CLOSE,1))&&
(iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,2)<iMA(NULL, 0,50,0,MODE_SMA,PRICE_CLOSE,2))&&
(iMA(NULL,0,5,0,MODE_SMA,PRICE_LOW,1)>iMA(NULL,0,1 20,0,MODE_SMA,PRICE_CLOSE,1)))// here is your close sell rule
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),Slippage,Red);
}
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*InicioTrailing))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyP oint*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);
}
Iniciado por
tivag
Para ello se debe contabilizar el beneficio obtenido , se guarda en una variable y cuando esa variable sea mayor que tu objetivo ponemos una variable de tipo bool a true , esa variable la introduces en donde se manda las ordenes cuando sea false y asi solo se ejecutara cuando el beneficio sea inferior a lo esperado.
double
profit=0;
int historico= OrdersHistoryTotal();
for (int i=0;i<historico;i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
profit += OrderProfit();
}
if (profit>ganancia)
{
stop=true;
}
else
stop=false;
Foro de Forex Trading United