Simple EA tester

Back to topics list To post a new topic, please log in or register
avatar
4
oronz 2015.02.24 17:04
 

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);


avatar
2017
gooly 2015.02.24 20:32 #
 

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.


avatar
4
oronz 2015.02.24 21:26 #
 

                

 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);
}

 

avatar
Moderator
3418
GumRai 2015.02.24 22:03 #
 

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

 

avatar
4
oronz 2015.02.24 22:53 #
 

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?

avatar
Moderator
3418
GumRai 2015.02.25 00:42 #
 
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
avatar
12998
WHRoeder 2015.02.25 03:22 #
 
  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.
avatar
Moderator
3418
GumRai 2015.02.25 04:27 #
 

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?

 

Back to topics list  

To add comments, please log in or register