CODE NOT WORKING PROPERLY INSTEAD

 

HELLO ALL;

I AM WORKING ON AN EA WHICH TAKES 1 PIPS PROFIT ($10)ON EURUSD 30 MIN CHART IF CANDLE MOVES 4 PIPS HIGHER.

THEN IT PLACES TRADE ON 3RD PIP AND TAKES PROFIT ON 5TH PIP ELSE WHEN CLOSE[0]==OPEN[0].MY CODE BELOW IS NOT WORKING..PLEASE HELP

 RESULTS ON BACKTEST ARE:-

1.1 2012.06.18 09:36 buy 1 0.50 1.2707 0.0000 1.2711 0.00 10000.00

2 2012.06.18 09:36 close 1 0.50 1.2706 0.0000 1.2711 -5.00 9995.00

3 2012.06.18 09:36 buy 2 0.50 1.2707 0.0000 1.2711 0.00 9995.00

4 2012.06.18 09:36 close 2 0.50 1.2706 0.0000 1.2711 -5.00 9990.00

5 2012.06.18 09:36 buy 3 0.50 1.2707 0.0000 1.2711 0.00 9990.00

6 2012.06.18 09:36 close 3 0.50 1.2706 0.0000 1.2711 -5.00 9985.00

7 2012.06.18 09:37 buy 4 0.50 1.2707 0.0000 1.2711 0.00 9985.00

8 2012.06.18 09:37 close 4 0.50 1.2706 0.0000 1.2711 -5.00 9980.00

9 2012.06.18 09:38 buy 5 0.50 1.2707 0.0000 1.2711 0.00 9980.00

10 2012.06.18 09:38 close 5 0.50 1.2706 0.0000 1.2711 -5.00 9975.00

11 2012.06.18 10:09 buy 6 0.50 1.2692 0.0000 1.2696 0.00 9975.00

12 2012.06.18 10:09 close 6 0.50 1.2691 0.0000 1.2696 -5.00 9970.00

13 2012.06.18 10:30 buy 7 0.50 1.2698 0.0000 1.2702 0.00 9970.00

14 2012.06.18 10:30 close 7 0.50 1.2697 0.0000 1.2702 -5.00 9965.00

15 2012.06.18 10:32 buy 8 0.50 1.2700 0.0000 1.2704 0.00 9965.00

16 2012.06.18 10:32 close 8 0.50 1.2699 0.0000 1.2704 -5.00 9960.00

17 2012.06.18 10:32 buy 9 0.50 1.2700 0.0000 1.2704 0.00 9960.00

18 2012.06.18 10:32 close 9 0.50 1.2699 0.0000 1.2704 -5.00 9955.00

19 2012.06.18 10:32 buy 10 0.50 1.2700 0.0000 1.2704 0.00 9955.00

20 2012.06.18 10:32 close 10 0.50 1.2699 0.0000 1.2704 -5.00 9950.00

21 2012.06.18 10:32 buy 11 0.50 1.2700 0.0000 1.2704 0.00 9950.00

22 2012.06.18 10:32 close 11 0.50 1.2699 0.0000 1.2704 -5.00 9945.00

23 2012.06.18 10:32 buy 12 0.50 1.2700 0.0000 1.2704 0.00 9945.00

24 2012.06.18 10:32 close 12 0.50 1.2699 0.0000 1.2704 -5.00 9940.00

25 2012.06.18 10:32 buy 13 0.50 1.2700 0.0000 1.2704 0.00 9940.00

26 2012.06.18 10:32 close 13 0.50 1.2699 0.0000 1.2704 -5.00 9935.00

27 2012.06.18 10:32 buy 14 0.50 1.2700 0.0000 1.2704 0.00 9935.00

28 2012.06.18 10:32 close 14 0.50 1.2699 0.0000 1.2704 -5.00 9930.00



 EVERY TIME IT PLACES ORDERS AND CLOSES IMMIDATELY.

int start()
  {
   if(AccountFreeMargin()>300)
 { 
  double d=0.0004,lots=0.5;
double bulldiff=Close[0]-Open[0];
bool upd=CompareDoubles(bulldiff,d);
//double beardiff=Open[0]-Close[0];
//bool dwd=CompareDoubles(beardiff,d);

if(upd)
{
flag=1;
Print(Close[0],Open[0]);
}//if(dwd)
//flag1=1;


if(OrdersTotal()==0)
{
if(flag)
{
int ticket;
ticket=OrderSend("EURUSD",0,lots,Open[0]+0.0003,0,0,Bid+0.0005,"got a buy",12555,0,Blue);
if(ticket>=0)
Print(Open[0]);
//if(flag1)
//OrderSend("EURUSD",1,lots,iOpen(NULL,30,0)-0.0003,0,0,Ask-0.0005,"got a sell",12000,0,Red);
}
}
if(OrdersTotal()>0)
{
  if(OrderSelect(0, SELECT_BY_POS,MODE_TRADES)==true)
  {
if(OrderType()==0)
{
OrderClose(ticket,0.5,Open[0]+0.0005,5,CLR_NONE);
if(OrdersTotal()>0)
OrderClose(ticket,0.5,Open[0],5,CLR_NONE);
flag=0;
}
}
}
}
   return(0);
  }
 
PLZ HELP.THERE ARE A LOT OF SECRETS IN MQL4.
 
ankit29030:

HELLO ALL;

I AM WORKING ON AN EA WHICH TAKES 1 PIPS PROFIT ($10)ON EURUSD 30 MIN CHART IF CANDLE MOVES 4 PIPS HIGHER.

THEN IT PLACES TRADE ON 3RD PIP AND TAKES PROFIT ON 5TH PIP ELSE WHEN CLOSE[0]==OPEN[0].MY CODE BELOW IS NOT WORKING..PLEASE HELP

 RESULTS ON BACKTEST ARE:-



 EVERY TIME IT PLACES ORDERS AND CLOSES IMMIDATELY.

 

Please edit your post so you are not   SHOUTING ! !   using CAPITAL letters is considered to be SHOUTING . . .  and it makes your post harder to read. 
 
ankit29030:
PLZ HELP.THERE ARE A LOT OF SECRETS IN MQL4.

No there aren't . . .  all the info you need is here: Documentation  and here: Book   and here:  Forum

 

Don't do this . . .

ticket=OrderSend("EURUSD",   0,   lots, Open[0]+0.0

do this instead,  then I don't have to look up what 0 means for that parameter. 

ticket=OrderSend("EURUSD",  OP_BUY lots, Open[0]+0.0
 
ankit29030:

HELLO ALL; 

You should check the Strategy Tester log or look in the Journal . . .  you will see lots and lots of errors . . .

A Buy is opened at Ask,  a Sell is opened at Bid . . .

ticket=OrderSend("EURUSD", 0, lots, Open[0]+0.0003, 0, 0, Bid+0.0005, "got a buy", 12555, 0, Blue);

 A buy is not opened at Open[0] + 0.0003  unless Ask is close to that price.  If you want to open your order when you call OrderSend() then you must use Ask.

This explains it all:   Requirements and Limitations in Making Trades

 
  1. OrderClose(ticket,0.5,Open[0]+0.0005,5,CLR_NONE);
    OrderClose does not say IF the price reaches Open[0]+0.0005 THEN close. Your call says close NOW if Bid is at Open[0]+0.0005 +/- 0.0005. So of course it closes immediately.
  2. What are Function return values ? How do I use them ? - MQL4 forum
Reason: