Bom Dia
Acabei esse código e tem 13 erros que, infelizmente, não consigo resolver!
Se alguém puder me auxiliar ficarei muito grato
//+------------------------------------------------------------------+
//| meta 5 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
extern int MAGICMA = 1;
extern int periodo_menor = 8;
extern int periofo_maior = 20;
extern double LoteEntrada = 0.01;
extern double fator_exp_lote = 1.4;
extern bool OperarSELL = true;
extern bool OperarBuy = true;
extern bool PararTrade = false;
extern int TakeProfit = 1000;
extern int StopLoss = 500;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
CheckForOpen(MAGICNA);
}
//+------------------------------------------------------------------+
bool sinal_media_moveis(int BUY_SELL)
{
bool retorno = false;
double media_menor = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 1);
double media_menor_ant = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 2);
double media_maior = iMA(NULL, 0, periodo_maior, 0, MODE_SMA, PRICE_CLOSE, 1);
double media_maior_ant = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 2);
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);
}
double total_ordem_aberta (int magicma_n, ont BUY_SELL)
{
int totalordens = ordensTotal();
int contador = 0;
for(int i= 0; i < totalordens; i++)
{
if(orderselect(i, SELECT_BY_POS, MODE_TRADES)==false) break;
if ((OrderMagicnumber() == MAGICMA_n) && (OrderTYPE() == BUY_SELL))
contador++;
}
void checkForOpen(int Magicma_n)
{
int res;
double total_de_ordem_venda = total_ordem_aberta (MAGICMA_n, OP_SELL);
double total_de_ordem_compra = total_ordem_aberta (MAGICMA_n, OP_SELL);
double lote_ent = 0;
if (PararTrade == true)
{
if(total_de_ordem_venda == 0) && (total_de_ordem_compra == 0))
return;
}
if(volume[0] > 1) return;
if (IsTradeContextBusy() == true)
return;
RefreshRates();
if(OperarSELL == true)
{
if((sinal_media_moveis(OP_SELL) == true) && (total_de_ordem_de_venda==0) && (total_de_ordem_de_compra==0))
{
lote_ent = get_lotes(double lote_inicial, 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_de_compra==0) && (total_de_ordem_de_venda==0))
{
lote_ent = get_lotes(double lote_inicial, Magicma_n, fator_exp_lote);
res=OrderSend(symbol(), OP_BUY, lote_ent, Ask, 150, Ask - (StopLoss * Point), Bid -(TakeProfit * PointMAGICMA_n, 0, clrblue);
}
}
return;
}
double get lotes(double lote_inicial, int MAGIC, double fator_incremento = 1)
{
double tamanho_lote = 0;
int maior_ticket = 0;
double maior_lote=0;
double Profit = 0;
for(int i=0 ; i < OrderHistoryTotal() ; i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false)
break;
if((OrderMagicNumber() == MAGIC) &&
(OrderSybol() == Sybol()) )
{
if (OrderTicket()> maior_ticket)
{
maior_ticket = OrderTicket();
maior_lote = NormalizeDouble(OrderLots(), 2)
Profit = OrderProfit()
}
}
}
if (OrderSelect(maior_ticket, SELECT_BY_TICKET, MODE_HISTORY) == false)
return (lote_inicial);
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);
}
Primeiramente, quando for colar trechos de um código use Alt+S . Da maneira que você fez dificulta a leitura e vem em desencontro com as funcionalidades do Fórum.
Percebo em seu código alguns problemas com abertura e fechamento de chaves, negligenciadas. Para corrigir isso, observe na parte de descrição do Metaeditor as linhas que possuem erros em seu código. A própria ferramenta te orienta nisso.
Persistindo suas dificuldades poste o código corretamente e um print do relatório do Metaeditor.
[ ]'s
Bom Dia
Acabei esse código e tem 13 erros que, infelizmente, não consigo resolver!
Se alguém puder me auxiliar ficarei muito grato
//+------------------------------------------------------------------+
//| meta 5 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
extern int MAGICMA = 1;
extern int periodo_menor = 8;
extern int periofo_maior = 20;
extern double LoteEntrada = 0.01;
extern double fator_exp_lote = 1.4;
extern bool OperarSELL = true;
extern bool OperarBuy = true;
extern bool PararTrade = false;
extern int TakeProfit = 1000;
extern int StopLoss = 500;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
CheckForOpen(MAGICNA);
}
//+------------------------------------------------------------------+
bool sinal_media_moveis(int BUY_SELL)
{
bool retorno = false;
double media_menor = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 1);
double media_menor_ant = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 2);
double media_maior = iMA(NULL, 0, periodo_maior, 0, MODE_SMA, PRICE_CLOSE, 1);
double media_maior_ant = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 2);
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);
}
double total_ordem_aberta (int magicma_n, ont BUY_SELL)
{
int totalordens = ordensTotal();
int contador = 0;
for(int i= 0; i < totalordens; i++)
{
if(orderselect(i, SELECT_BY_POS, MODE_TRADES)==false) break;
if ((OrderMagicnumber() == MAGICMA_n) && (OrderTYPE() == BUY_SELL))
contador++;
}
void checkForOpen(int Magicma_n)
{
int res;
double total_de_ordem_venda = total_ordem_aberta (MAGICMA_n, OP_SELL);
double total_de_ordem_compra = total_ordem_aberta (MAGICMA_n, OP_SELL);
double lote_ent = 0;
if (PararTrade == true)
{
if(total_de_ordem_venda == 0) && (total_de_ordem_compra == 0))
return;
}
if(volume[0] > 1) return;
if (IsTradeContextBusy() == true)
return;
RefreshRates();
if(OperarSELL == true)
{
if((sinal_media_moveis(OP_SELL) == true) && (total_de_ordem_de_venda==0) && (total_de_ordem_de_compra==0))
{
lote_ent = get_lotes(double lote_inicial, 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_de_compra==0) && (total_de_ordem_de_venda==0))
{
lote_ent = get_lotes(double lote_inicial, Magicma_n, fator_exp_lote);
res=OrderSend(symbol(), OP_BUY, lote_ent, Ask, 150, Ask - (StopLoss * Point), Bid -(TakeProfit * PointMAGICMA_n, 0, clrblue);
}
}
return;
}
double get lotes(double lote_inicial, int MAGIC, double fator_incremento = 1)
{
double tamanho_lote = 0;
int maior_ticket = 0;
double maior_lote=0;
double Profit = 0;
for(int i=0 ; i < OrderHistoryTotal() ; i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false)
break;
if((OrderMagicNumber() == MAGIC) &&
(OrderSybol() == Sybol()) )
{
if (OrderTicket()> maior_ticket)
{
maior_ticket = OrderTicket();
maior_lote = NormalizeDouble(OrderLots(), 2)
Profit = OrderProfit()
}
}
}
if (OrderSelect(maior_ticket, SELECT_BY_TICKET, MODE_HISTORY) == false)
return (lote_inicial);
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);
}
Outra coisa. Você inicia dizendo que "acabou esse código". Programou em qual linguagem??? Em MQL5 não foi!!!
Bom Dia
Acabei esse código e tem 13 erros que, infelizmente, não consigo resolver!
Se alguém puder me auxiliar ficarei muito grato
Corrigidos erros de compilação:
//+------------------------------------------------------------------+ //| MM EA.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern int MAGICMA = 11; extern int periodo_menor = 8; extern int periodo_maior = 20; extern double LoteEntrada = 0.01; extern double fator_exp_lote = 1.4; extern bool OperarSELL = true; extern bool OperarBUY = true; extern bool PararTrade = false; extern int TakeProfit = 1000; extern int StopLoss = 500; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { CheckForOpen(MAGICMA); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool sinal_media_moveis(int BUY_SELL) { bool retorno = false; double media_menor = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 1); double media_menor_ant = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 2); double media_maior = iMA(NULL, 0, periodo_maior, 0, MODE_SMA, PRICE_CLOSE, 1); double media_maior_ant = iMA(NULL, 0, periodo_maior, 0, MODE_SMA, PRICE_CLOSE, 2); 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); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int total_ordem_aberta (int MAGICMA_n, int BUY_SELL) { int totalordens = OrdersTotal(); int contador = 0; for(int i = 0; i < totalordens; i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) {break;} if(OrderMagicNumber() == MAGICMA_n && OrderType() == BUY_SELL) {contador++;} } return(contador); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckForOpen(int MAGICMA_n) { int res; int total_de_ordem_venda = total_ordem_aberta(MAGICMA_n, OP_SELL); int total_de_ordem_compra = total_ordem_aberta(MAGICMA_n, OP_BUY); double lote_ent = 0; if(PararTrade == true && total_de_ordem_venda == 0 && total_de_ordem_compra == 0) {return;} if(Volume[0] > 1) {return;} if(IsTradeContextBusy() == true) {return;} RefreshRates(); if(OperarSELL == true) { 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, clrBlue); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double get_lotes(double lote_inicial, int MAGIC, double fator_incremento) { int maior_ticket = 0; double tamanho_lote = 0, maior_lote = 0, Profit = 0; for(int i = 0; i < OrdersHistoryTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false) {break;} if(OrderMagicNumber() == MAGIC && OrderSymbol() == Symbol()) { if (OrderTicket()> maior_ticket) { maior_ticket = OrderTicket(); maior_lote = NormalizeDouble(OrderLots(), 2); Profit = OrderProfit(); } } } if(OrderSelect(maior_ticket, SELECT_BY_TICKET, MODE_HISTORY) == false) {return(lote_inicial);} if(maior_lote == 0) {tamanho_lote = lote_inicial;} else { if(Profit > 0) {tamanho_lote = lote_inicial;} else {tamanho_lote = maior_lote * fator_incremento;} } return(NormalizeDouble(tamanho_lote, 2)); } //+------------------------------------------------------------------+ //| Expert End | //+------------------------------------------------------------------+
- Aplicativos de negociação gratuitos
- 8 000+ sinais para cópia
- Notícias econômicas para análise dos mercados financeiros
Você concorda com a política do site e com os termos de uso
Bom Dia
Acabei esse código e tem 13 erros que, infelizmente, não consigo resolver!
Se alguém puder me auxiliar ficarei muito grato
//+------------------------------------------------------------------+
//| meta 5 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
extern int MAGICMA = 1;
extern int periodo_menor = 8;
extern int periofo_maior = 20;
extern double LoteEntrada = 0.01;
extern double fator_exp_lote = 1.4;
extern bool OperarSELL = true;
extern bool OperarBuy = true;
extern bool PararTrade = false;
extern int TakeProfit = 1000;
extern int StopLoss = 500;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
CheckForOpen(MAGICNA);
}
//+------------------------------------------------------------------+
bool sinal_media_moveis(int BUY_SELL)
{
bool retorno = false;
double media_menor = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 1);
double media_menor_ant = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 2);
double media_maior = iMA(NULL, 0, periodo_maior, 0, MODE_SMA, PRICE_CLOSE, 1);
double media_maior_ant = iMA(NULL, 0, periodo_menor, 0, MODE_SMA, PRICE_CLOSE, 2);
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);
}
double total_ordem_aberta (int magicma_n, ont BUY_SELL)
{
int totalordens = ordensTotal();
int contador = 0;
for(int i= 0; i < totalordens; i++)
{
if(orderselect(i, SELECT_BY_POS, MODE_TRADES)==false) break;
if ((OrderMagicnumber() == MAGICMA_n) && (OrderTYPE() == BUY_SELL))
contador++;
}
void checkForOpen(int Magicma_n)
{
int res;
double total_de_ordem_venda = total_ordem_aberta (MAGICMA_n, OP_SELL);
double total_de_ordem_compra = total_ordem_aberta (MAGICMA_n, OP_SELL);
double lote_ent = 0;
if (PararTrade == true)
{
if(total_de_ordem_venda == 0) && (total_de_ordem_compra == 0))
return;
}
if(volume[0] > 1) return;
if (IsTradeContextBusy() == true)
return;
RefreshRates();
if(OperarSELL == true)
{
if((sinal_media_moveis(OP_SELL) == true) && (total_de_ordem_de_venda==0) && (total_de_ordem_de_compra==0))
{
lote_ent = get_lotes(double lote_inicial, 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_de_compra==0) && (total_de_ordem_de_venda==0))
{
lote_ent = get_lotes(double lote_inicial, Magicma_n, fator_exp_lote);
res=OrderSend(symbol(), OP_BUY, lote_ent, Ask, 150, Ask - (StopLoss * Point), Bid -(TakeProfit * PointMAGICMA_n, 0, clrblue);
}
}
return;
}
double get lotes(double lote_inicial, int MAGIC, double fator_incremento = 1)
{
double tamanho_lote = 0;
int maior_ticket = 0;
double maior_lote=0;
double Profit = 0;
for(int i=0 ; i < OrderHistoryTotal() ; i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false)
break;
if((OrderMagicNumber() == MAGIC) &&
(OrderSybol() == Sybol()) )
{
if (OrderTicket()> maior_ticket)
{
maior_ticket = OrderTicket();
maior_lote = NormalizeDouble(OrderLots(), 2)
Profit = OrderProfit()
}
}
}
if (OrderSelect(maior_ticket, SELECT_BY_TICKET, MODE_HISTORY) == false)
return (lote_inicial);
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);
}