Simple EA tester

 

Anyone can help me?

here is a very simple EA.It should open a sell order when the difference between two consecutive ticks is bigger than 10 point.the second tick must be minor than the first.

the compiler don't give me any errors but when I run it on the tester it doesn't give me any result.the EA during the test doesn't open any orders.what's wrong on the EA?

 


int c=0;

double bid0=0;

double bid1=0;

int start()

{

double stoploss=(Ask+50*Point);

double takeprofit=(Ask+500*Point);

if (c==0)

bid0=Bid;

if (c==1)

bid1=Bid;

if (c==1 && bid1<bid0-10*Point)

OrderSend (Symbol(),OP_SELL,0.01,Bid,3,stoploss,takeprofit);

c=c+1;

if (bid1>=bid0-10*Point)

c=0;

return (0);


 

1) Please edit you post and use the SRC button for your code!

2) Problem 1: you don't get all the ticks!!

3) Problem 2: start (or OnTick()) is called if you received a new tick and the previous one is gone unless you have saved it which I don't see.

 

                

 Sorry  gooly I'm a beginner user.

1) I don't mind if I don't get all ticks , I want only open a position when two ticks are processed consecutively by start function.

2) I saved the last tick processed by start  with record bid1=Bid as you can see.I also saved the previous tick with record bid0=Bid.Is it incorrect?

 

int c=0;
double bid0=0;
double bid1=0;
int start()
{
double stoploss=(Ask+50*Point);
double takeprofit=(Ask+500*Point);
if (c==0)
bid0=Bid;
if (c==1)
bid1=Bid;
if (c==1 && bid1<bid0-10*Point)
OrderSend (Symbol(),OP_SELL,0.01,Bid,3,stoploss,takeprofit);
c=c+1;
if (bid1>=bid0-10*Point)
c=0;
return (0);
}
 

It is always good practice to give variables recognizable names

Why calculate Stoploss and takeprofit every tick?

Consider using something like this (just quickly written, not compiled or tested, no error checking)

 double This_Tick,Last_Tick=0;
//+------------------------------------------------------------------+
int start()
  {
  This_Tick=Bid;
  if(Last_Tick-This_Tick>10*Point)
     {
     double stoploss=(Ask+50*Point);
     double takeprofit=(Ask-500*Point);
     OrderSend(Symbol(),OP_SELL,0.01,Bid,3,stoploss,takeprofit);
     }
  Last_Tick=This_Tick;
  }

 Also note that in the tester, ticks are "smoothed out", so jumps that happen in real time will not be apparent in the tester

 

Thanks GumRai ,you are right, to give variables recognizable name make the EA more understandable.

So I rewrote my EA.I hope it is more understandable in this way.

int c=0;
double FirstTick=0;
double SecondTick=0;
int stoploss=50;
int takeprofit=500;

int start()
{
if (c==0)
FirstTick=Bid;   //record first tick
if (c==1) 
SecondTick=Bid;       //record second tick
if (c==1 && SecondTick<FirstTick-10*Point) 
OrderSend (Symbol(),OP_SELL,0.01,Bid,3,Ask+stoploss*Point,Ask+takeprofit*Point);
c=c+1;
if (SecondTick>=FirstTick-10*Point)  
c=0;                                  //c=0 will give a new FirstTick
return (0);
}

 But  Why doesn't it open any orders during test?

 
OrderSend (Symbol(),OP_SELL,0.01,Bid,3,Ask+stoploss*Point,Ask+takeprofit*Point);
You also need to check for errors if the order fails
 
  1. Check your return codes (OrderSend) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. Self-document your code. If you can't read the code in English, there is a problem. if(c==0) is meaningless. Use meaningful names.
 

I din't see why you need the variable c at all.

How will c be re-valued  to 0 if

if (SecondTick>=FirstTick-10*Point) 

 returns false?

Reason: