Download MetaTrader 5

First Steps - EA does not run as it should

To add comments, please log in or register
Do you need OpenCL? MQL5 can provide it!
vla
53
vla 2014.11.18 19:39 

Hi Guys,

I've got a Problem on running EAs. You can see my code below. It's a simple moving average strategy. But it does not work. I have tried this after a different strategie does not work either. I have run this on EURUSD with data I downloaded from the Internet (since 2001) on a intraday timeframes (before i used period converter) and on a daily timeframe with data my broker is providing me.

If I run my EA he is not making any trades. But he is sending me Errors in the journal: "unmatched data error [...]" 

Thanks!

TheOneWhoKnocks 

#property copyright "Copyright 2014, vk"
#property link      "-"
#property version   "1.00"
#property script_show_inputs

//externs:
extern double PeriodFastMA = 20;
extern double PeriodSlowMA = 200;
extern double lots = 0.1;

int start()
{
double fastMA = iMA(Symbol(), PERIOD_CURRENT, PeriodFastMA, 0, MODE_SMA, PRICE_CLOSE, 0);
double slowMA = iMA(Symbol(), PERIOD_CURRENT, PeriodSlowMA, 0, MODE_SMA, PRICE_CLOSE, 0);

//Buy Condition:
if(fastMA > slowMA && OrdersTotal() == 0)
   {
   int ticket1 = OrderSend(Symbol(), OP_BUY, lots, Bid, 0, 0, 0);
   if(ticket1 > 0)
      {
      Alert("Order Sended Successfully. Order No.: ", ticket1);
      }
   else
      {
      Alert("Order Sending Error!");
      }
   }
//Sell Condition:
if(slowMA > fastMA)
   {
   OrderClose(ticket1, lots, Ask, 0);
   }
}
Keith Watford
Moderator
9627
Keith Watford 2014.11.18 20:08  
#property script_show_inputs
seems that this is a script, not an EA
vla
53
vla 2014.11.18 20:20  

Hi GumRai,

first I was quite sceptical. But you are absolutely right! Thanks man!
I've took that out. Now it runs! But now I've got a lot of open order errors and order closing errors. Do you know what I can do against this?

Keith Watford
Moderator
9627
Keith Watford 2014.11.18 21:54  
TheOneWhoKnocks:

Hi GumRai,

first I was quite sceptical. But you are absolutely right! Thanks man!
I've took that out. Now it runs! But now I've got a lot of open order errors and order closing errors. Do you know what I can do against this?

 

Buy orders are opened at Ask and closed at Bid

 

MAs can cross and recross many times in a single bar, often it is best to only check on a new bar.

ticket1 is a local variable, so will not hold the ticket number on the next tick. 

vla
53
vla 2014.11.23 14:12  
GumRai:

Buy orders are opened at Ask and closed at Bid

 

MAs can cross and recross many times in a single bar, often it is best to only check on a new bar.

ticket1 is a local variable, so will not hold the ticket number on the next tick. 

Alright 1. and 3. are done now. But how can 2. be a factor? MA are set to close prices. What I have done wrong? Do you know it? 

whroeder1
14504
whroeder1 2014.11.23 18:23  
TheOneWhoKnocks: But how can 2. be a factor? MA are set to close prices. What I have done wrong?
Close[0] == Bid Market moves up and down, Close[0] moves up and down. MA(..., 0) moves up and down. Multiple crosses during bar zero is possible.
vla
53
vla 2014.11.27 20:39  

alright guys I have found my mistake.

My question now is: How can I bring my ticket variable (at least the ticketnumber which was generated in the first if-condition) into the 2nd if-condition? See at the picture below.

vla
53
vla 2014.11.27 20:40  
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.11.28 00:59  
Use GlobalVariable.
vla
53
vla 2014.11.28 09:32  
I can't use ticket1 as a global variable, because mt would open a new order every tick. I've tried this already.
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.11.28 10:02  
Show us.
123
To add comments, please log in or register