First Steps - EA does not run as it should

 

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);
   }
}
 
#property script_show_inputs
seems that this is a script, not an EA
 

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?

 
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. 

 
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? 

 
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.
 

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.

 
 
Use GlobalVariable.
 
I can't use ticket1 as a global variable, because mt would open a new order every tick. I've tried this already.
 
Show us.
Reason: