![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I'm really new to programing amd I decided to make the first tryout changing the MACD sample EA, but I can't get it to work, I get always the same errors in the tester. Then a installed the MetaTrader again and I don't get the error messages, but it doesn't trade.
Can anyone give an hand? Thank you very much.
André
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4588 at 2009.10.02 22:05 and price 1.4589 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4585 at 2009.10.02 21:45 is not reached from the least timeframe, low price 1.4586 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4607 at 2009.10.02 21:00 is not reached from the least timeframe, high price 1.4606 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4614 at 2009.10.02 20:50 and price 1.4615 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4606 at 2009.10.02 20:30 is not reached from the least timeframe, high price 1.4605 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4597 at 2009.10.02 20:40 and price 1.4596 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4598 at 2009.10.02 20:25 and price 1.4599 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4585 at 2009.10.02 20:05 and price 1.4584 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4594 at 2009.10.02 19:15 is not reached from the least timeframe, low price 1.4595 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4605 at 2009.10.02 19:25 and price 1.4606 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4549 at 2009.10.02 16:10 and price 1.4550 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4519 at 2009.10.02 15:50 and price 1.4520 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4533 at 2009.10.02 15:15 is not reached from the least timeframe, low price 1.4534 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4540 at 2009.10.02 14:00 is not reached from the least timeframe, high price 1.4539 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4534 at 2009.10.02 13:45 is not reached from the least timeframe, low price 1.4535 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4545 at 2009.10.02 13:25 and price 1.4546 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4539 at 2009.10.02 13:00 is not reached from the least timeframe, low price 1.4540 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4520 at 2009.10.02 10:30 is not reached from the least timeframe, low price 1.4521 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4525 at 2009.10.02 10:15 is not reached from the least timeframe, low price 1.4526 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4554 at 2009.10.02 09:10 and price 1.4555 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4540 at 2009.10.02 09:05 and price 1.4539 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4549 at 2009.10.02 08:55 and price 1.4550 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4536 at 2009.10.02 08:40 and price 1.4535 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4542 at 2009.10.02 07:10 and price 1.4541 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4543 at 2009.10.02 06:25 and price 1.4544 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4543 at 2009.10.02 06:20 and price 1.4544 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4539 at 2009.10.02 05:45 is not reached from the least timeframe, high price 1.4538 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4537 at 2009.10.02 04:45 is not reached from the least timeframe, high price 1.4536 mismatches)
2009.12.13 02:57:57 TestGenerator: unmatched data error (high value 1.4523 at 2009.10.02 04:20 and price 1.4524 mismatched)
2009.12.13 02:57:57 TestGenerator: unmatched data error (low value 1.4513 at 2009.10.02 03:45 is not reached from the least timeframe, low price 1.4514 mismatches)
EA
#define NUMMAGICO 20091212
extern int RiscoStopLoss = 1;
extern double LoteBase = 0.1;
extern double PrazoGatilho = 9;
extern double PrazoBase=27;
extern double TrailingStop = 30;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double LoteBase, PrazoGatilho, PrazoBase;
double MediaGatilhoActual,MediaGatilhoAnterior,DecliveGatilho;
double MediaBaseActual,MediaBaseAnterior,DecliveBase;
double MediaUlt3dias,TrailingStop;
int RiscoStopLoss, cnt,ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
// to simplify the coding and speed up access
// data are put into internal variables
MediaGatilhoActual=iMA(NULL,0,PrazoGatilho,0,MODE_EMA,PRICE_MEDIAN,0);
MediaGatilhoAnterior=iMA(NULL,0,PrazoGatilho,0,MODE_EMA,PRICE_MEDIAN,1);
DecliveGatilho=MathArctan(MediaGatilhoAnterior-MediaGatilhoActual);
MediaBaseActual=iMA(NULL,0,PrazoBase,0,MODE_SMA,PRICE_OPEN,0);
MediaBaseAnterior=iMA(NULL,0,PrazoBase,0,MODE_SMA,PRICE_OPEN,1);
DecliveBase=MathArctan(MediaBaseAnterior-MediaBaseActual);
MediaUlt3dias=iMA(NULL,0,3,0,MODE_EMA,PRICE_MEDIAN,0);
total=OrdersTotal();
if(total<1)
{
// no opened orders identified
if(AccountFreeMargin()<(1000*LoteBase))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// check for long position (BUY) possibility
if(MediaGatilhoAnterior<MediaBaseAnterior&&MediaGatilhoActual>MediaBaseActual)
{
ticket=OrderSend(Symbol(),OP_BUY,LoteBase,Ask,3,Ask-(Ask-MediaUlt3dias)*RiscoStopLoss,0,"TESTE",NUMMAGICO,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); Print("Dec Gat -",DecliveGatilho," Dec Base -",DecliveBase);
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
// check for short position (SELL) possibility
if(MediaGatilhoAnterior>MediaBaseAnterior&&MediaGatilhoActual<MediaBaseActual)
{
ticket=OrderSend(Symbol(),OP_SELL,LoteBase,Bid,3,Bid+(MediaUlt3dias-Bid)*RiscoStopLoss,0,"TESTE",NUMMAGICO,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); Print("Dec Gat -",DecliveGatilho," Dec Base -",DecliveBase);
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
// it is important to enter the market correctly,
// but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(iClose(NULL,0,0)<iClose(NULL,0,1))
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// should it be closed?
if(iClose(NULL,0,0)>iClose(NULL,0,1))
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
// the end.