Please help me to modify the VolumeAverage EA

 
//+------------------------------------------------------------------+
 //| VoulumEa.mq4 |
 //| |
 //| http://www.metaquotes.net |
 //+------------------------------------------------------------------+
 #property copyright ""
 #property link "http://www.metaquotes.net"
 
//+------------------------------------------------------------------+
 //| expert initialization function |
 //+------------------------------------------------------------------+
 #define ATR 201207
 extern int AtrPeriod=14;
 extern int AtrPeriod2=28;
 //---- buffers
 double AtrBuffer[];
 double AtrBuffer2[];
 double TempBuffer[];
 
int init()
 {
 //----

 //----
 return(0);
 }
 //+------------------------------------------------------------------+
 //| expert deinitialization function |
 //+------------------------------------------------------------------+
 int deinit()
 {
 //----

 //----
 return(0);
 }
 //+------------------------------------------------------------------+
 //| expert start function |
 //+------------------------------------------------------------------+
 int start()
 {
 //----
 int i,counted_bars=IndicatorCounted();
 //----
 if(Bars<=AtrPeriod) return(0);
 //---- initial zero
 if(counted_bars<1)
 for(i=1;i<=AtrPeriod;i++) AtrBuffer[Bars-i]=0.0;
 //----
 i=Bars-counted_bars-1;
 while(i>=0)
 {
 double high=High[i];
 double low =Low[i];
 if(i==Bars-1) TempBuffer[i]=high-low;
 else
 {
 double prevclose=Close[i+1];
 TempBuffer[i]=Volume[i];
 }
 i--;
 }
 //----
 if(counted_bars>0) counted_bars--;
 int limit=Bars-counted_bars;
 for(i=0; i<limit; i++)
 {
 AtrBuffer[i]=iMAOnArray(TempBuffer,Bars,AtrPeriod,0,MODE_SMA,i );
 AtrBuffer2[i]=iMAOnArray(TempBuffer,Bars,AtrPeriod2,0,MODE_SMA, i);
 }
 //----
 if (OrdersTotal( ) >= 1) return ; 
if (AtrBuffer[1]>AtrBuffer2[2])
 {
 OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"",ATR,0,B lue);
 }
 if (AtrBuffer[1]<AtrBuffer2[2])
 {
 OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"",ATR,0, Red);
 } 
//----
 return(0);
 }
 //+------------------------------------------------------------------+
 

I try to run the EA, but it only create the log and could only run a little time then stop like freezen:

2012.07.21 23:32:10 TestGenerator: unmatched data error (volume limit 117 at 2012.05.11 08:05 exceeded)

I am a newbie, thank you for help me!

 

Try to identify the place where EA freezes by including debugging statements in code e.g. print("Control at line # 123"); etc. Reply how it goes..

 
int IndicatorCounted( )
The function returns the amount of bars not changed after the indicator had been launched last. The most calculated bars do not need any recalculation. In most cases, same count of index values do not need for recalculation. The function is used to optimize calculating.


//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int i,counted_bars=IndicatorCounted();
//----
Is this code indicator or EA ??
or is it something ... I don't know
 
double AtrBuffer[];

,counted_bars=IndicatorCounted();

OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"",ATR,0,B lue);
  1. If this is an indicator, indicators can NOT sleep or wait, they can NOT call orderSend(). It will hang the terminal
  2. If this is supposed to be an EA, you can NOT call indicatorCounted(), and you must resize your arrays yourself.
 

Thank you ! I have modified counted_bars=bars. Should not use the IndicatorCounted. Because I use the Indicator DEMO code, so ...