Professional Documents
Culture Documents
Script Robo Cruzamento de Medias Moveis
Script Robo Cruzamento de Medias Moveis
//+------------------------------------------------------------------+
//| INPUTS( ENTRADAS) |
//+------------------------------------------------------------------+
extern int MAGICMA = 1;
extern int periodo_menor = 8;
extern int periodo_maior = 20;
extern double fator_exp_lote = 1.4;
extern double LoteEntrada = 0.01;
extern bool OperarSELL = true;
extern bool OperarBUY = true;
extern bool PararTrade = false;
extern int TakeProfit = 1000;
extern int StopLoss = 500;
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
checkForOpen(MAGICMA);
}
//+------------------------------------------------------------------+
if(BUY_SELL==OP_SELL)
{
if((media_menor_ant > media_maior_ant)&&(media_menor < media_maior))
retorno = true;
else
retorno = false;
}
else if(BUY_SELL==OP_BUY)
{
if((media_menor_ant < media_maior_ant)&&(media_menor > media_maior))
retorno = true;
else
retorno = false;
}
return(retorno);
}
contador++;
}
return (contador);
}
if (PararTrade == true)
{
if((total_de_ordem_venda ==0) &&(total_de_ordem_compra ==0))
return;
}
if(Volume[0] > 3) return;
if (IsTradeContextBusy()==true)
return;
RefreshRates();
if((sinal_media_moveis(OP_SELL)==true)&&(total_de_ordem_venda==0)&&(total_de_ordem_
compra==0))
{
lote_ent = get_lotes(LoteEntrada,Magicma_n, fator_exp_lote);
res=OrderSend(Symbol(),OP_SELL,lote_ent,Bid,150,Bid + (StopLoss * Point), Bid -
(TakeProfit * Point),"", Magicma_n,0, clrRed);
}
}
if(OperarBUY == true)
{
if((sinal_media_moveis(OP_BUY)==true)&&(total_de_ordem_compra==0)&&(total_de_ordem_
venda==0))
{
lote_ent = get_lotes(LoteEntrada,Magicma_n, fator_exp_lote);
res=OrderSend(Symbol(),OP_BUY,lote_ent,Ask,150,Ask - (StopLoss * Point), Ask +
(TakeProfit * Point),"", Magicma_n,0, clrGreen);
}
}
return;
}
if((OrderMagicNumber()==MAGIC) &&
(OrderSymbol()==Symbol() ))
{
if(OrderTicket() > maior_ticket)
{
maior_ticket = OrderTicket();
maior_lote = NormalizeDouble(OrderLots(),2);
Profit = OrderProfit();
}
}
if (maior_lote ==0)
tamanho_lote = lote_inicial;
else
{
if (Profit > 0)
tamanho_lote = lote_inicial;
else
tamanho_lote = maior_lote * fator_incremento;
}
Lote = NormalizeDouble (tamanho_lote, 2);
return (Lote);
}