Código:
--------------
input double Lots=0.01;
input double macd_rapido=12;
input double macd_lento=26;
input int macd_signal=9;
input int slippage=3;
input int magic=12345;
//--------------
int init()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void deinit()
{
//---
return;
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- definimos variables a usar
double MacdCurrent,MacdPrevious;
double SignalCurrent,SignalPrevious;
bool cerrar;
int i,ticket,total;
//----------------
double SL=Ask-30*Point;
double TP=Ask+70*Point;
MacdCurrent=iMACD(Symbol(),0,macd_rapido,macd_lento,macd_signal,PRICE_CLOSE,MODE_MAIN,0);
MacdPrevious=iMACD(Symbol(),0,macd_rapido,macd_lento,macd_signal,PRICE_CLOSE,MODE_MAIN,1);
SignalCurrent=iMACD(Symbol(),0,macd_rapido,macd_lento,macd_signal,PRICE_CLOSE,MODE_SIGNAL,0);
SignalPrevious=iMACD(Symbol(),0,macd_rapido,macd_lento,macd_signal,PRICE_CLOSE,MODE_SIGNAL,1);
total=OrdersTotal();
//-------------------------------
if (total<1)
{
if(MacdCurrent>MacdPrevious)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,slippage,SL,TP,NULL,magic,0,clrGreen);
for (i=0;i<total;i++)
{
if (OrderSelect(ticket,SELECT_BY_TICKET)==False) continue;
if ((OrderType()==OP_BUY)&& (OrderSymbol()==Symbol()))
{
if ((MacdCurrent<MacdPrevious))
cerrar=OrderClose(OrderTicket(),Lots,Bid,slippage,clrNONE);
}
}
return;
}
}
}